async def sample_list_incidents_for_detection_configuration_async():
    # [START list_incidents_for_detection_configuration_async]
    import datetime
    from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
    from azure.ai.metricsadvisor.aio import MetricsAdvisorClient

    service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
    subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
    api_key = os.getenv("METRICS_ADVISOR_API_KEY")
    detection_configuration_id = os.getenv(
        "METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")

    client = MetricsAdvisorClient(
        service_endpoint, MetricsAdvisorKeyCredential(subscription_key,
                                                      api_key))
    async with client:
        results = client.list_incidents(
            detection_configuration_id=detection_configuration_id,
            start_time=datetime.datetime(2020, 1, 1),
            end_time=datetime.datetime(2020, 9, 9),
        )
        async for result in results:
            print("Metric id: {}".format(result.metric_id))
            print("Incident ID: {}".format(result.id))
            print("Severity: {}".format(result.severity))
            print("Status: {}".format(result.status))
async def sample_list_incidents_for_alert_async():
    # [START list_incidents_for_alert_async]
    from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
    from azure.ai.metricsadvisor.aio import MetricsAdvisorClient

    service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
    subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
    api_key = os.getenv("METRICS_ADVISOR_API_KEY")
    alert_configuration_id = os.getenv(
        "METRICS_ADVISOR_ALERT_CONFIGURATION_ID")
    alert_id = os.getenv("METRICS_ADVISOR_ALERT_ID")

    client = MetricsAdvisorClient(
        service_endpoint, MetricsAdvisorKeyCredential(subscription_key,
                                                      api_key))
    async with client:
        results = client.list_incidents(
            alert_configuration_id=alert_configuration_id,
            alert_id=alert_id,
        )
        async for result in results:
            print("Metric id: {}".format(result.metric_id))
            print("Incident ID: {}".format(result.id))
            print("Severity: {}".format(result.severity))
            print("Status: {}".format(result.status))
class ListIncidentsTest(PerfStressTest):
    def __init__(self, arguments):
        super().__init__(arguments)
        service_endpoint = os.getenv("AZURE_METRICS_ADVISOR_ENDPOINT")
        subscription_key = os.getenv("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY")
        api_key = os.getenv("AZURE_METRICS_ADVISOR_API_KEY")
        self.anomaly_detection_configuration_id = os.getenv(
            "AZURE_METRICS_ADVISOR_ANOMALY_DETECTION_CONFIGURATION_ID")
        self.service_client = SyncClient(
            service_endpoint,
            MetricsAdvisorKeyCredential(subscription_key, api_key))
        self.async_service_client = AsyncClient(
            service_endpoint,
            MetricsAdvisorKeyCredential(subscription_key, api_key))

    async def close(self):
        await self.async_service_client.close()
        await super().close()

    def run_sync(self):
        results = self.service_client.list_incidents(
            detection_configuration_id=self.anomaly_detection_configuration_id,
            start_time=datetime.datetime(2020,
                                         1,
                                         1,
                                         tzinfo=datetime.timezone.utc),
            end_time=datetime.datetime(2020,
                                       10,
                                       21,
                                       tzinfo=datetime.timezone.utc),
        )
        for _ in results:
            pass

    async def run_async(self):
        results = self.async_service_client.list_incidents(
            detection_configuration_id=self.anomaly_detection_configuration_id,
            start_time=datetime.datetime(2020,
                                         1,
                                         1,
                                         tzinfo=datetime.timezone.utc),
            end_time=datetime.datetime(2020,
                                       10,
                                       21,
                                       tzinfo=datetime.timezone.utc),
        )
        async for _ in results:
            pass