# coding=utf-8
# *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import warnings
import pulumi
import pulumi.runtime
from typing import Union
from .. import utilities, tables


class MetricAlert(pulumi.CustomResource):
    actions: pulumi.Output[list]
    """
    One or more `action` blocks as defined below.

      * `action_group_id` (`str`) - The ID of the Action Group can be sourced from the `monitoring.ActionGroup` resource
      * `webhookProperties` (`dict`) - The map of custom string properties to include with the post operation. These data are appended to the webhook payload.
    """
    auto_mitigate: pulumi.Output[bool]
    """
    Should the alerts in this Metric Alert be auto resolved? Defaults to `true`.
    """
    criterias: pulumi.Output[list]
    """
    One or more `criteria` blocks as defined below.

      * `aggregation` (`str`) - The statistic that runs over the metric values. Possible values are `Average`, `Count`, `Minimum`, `Maximum` and `Total`.
      * `dimensions` (`list`) - One or more `dimension` blocks as defined below.
        * `name` (`str`) - One of the dimension names.
        * `operator` (`str`) - The dimension operator. Possible values are `Include` and `Exclude`.
        * `values` (`list`) - The list of dimension values.

      * `metricName` (`str`) - One of the metric names to be monitored.
      * `metricNamespace` (`str`) - One of the metric namespaces to be monitored.
      * `operator` (`str`) - The criteria operator. Possible values are `Equals`, `NotEquals`, `GreaterThan`, `GreaterThanOrEqual`, `LessThan` and `LessThanOrEqual`.
      * `threshold` (`float`) - The criteria threshold value that activates the alert.
    """
    description: pulumi.Output[str]
    """
    The description of this Metric Alert.
    """
    enabled: pulumi.Output[bool]
    """
    Should this Metric Alert be enabled? Defaults to `true`.
    """
    frequency: pulumi.Output[str]
    """
    The evaluation frequency of this Metric Alert, represented in ISO 8601 duration format. Possible values are `PT1M`, `PT5M`, `PT15M`, `PT30M` and `PT1H`. Defaults to `PT1M`.
    """
    name: pulumi.Output[str]
    """
    The name of the Metric Alert. Changing this forces a new resource to be created.
    """
    resource_group_name: pulumi.Output[str]
    """
    The name of the resource group in which to create the Metric Alert instance.
    """
    scopes: pulumi.Output[str]
    """
    A set of strings of resource IDs at which the metric criteria should be applied.
    """
    severity: pulumi.Output[float]
    """
    The severity of this Metric Alert. Possible values are `0`, `1`, `2`, `3` and `4`. Defaults to `3`.
    """
    tags: pulumi.Output[dict]
    """
    A mapping of tags to assign to the resource.
    """
    window_size: pulumi.Output[str]
    """
    The period of time that is used to monitor alert activity, represented in ISO 8601 duration format. This value must be greater than `frequency`. Possible values are `PT1M`, `PT5M`, `PT15M`, `PT30M`, `PT1H`, `PT6H`, `PT12H` and `P1D`. Defaults to `PT5M`.
    """
    def __init__(__self__, resource_name, opts=None, actions=None, auto_mitigate=None, criterias=None, description=None, enabled=None, frequency=None, name=None, resource_group_name=None, scopes=None, severity=None, tags=None, window_size=None, __props__=None, __name__=None, __opts__=None):
        """
        Manages a Metric Alert within Azure Monitor.

        ## Example Usage

        ```python
        import pulumi
        import pulumi_azure as azure

        main_resource_group = azure.core.ResourceGroup("mainResourceGroup", location="West US")
        to_monitor = azure.storage.Account("toMonitor",
            resource_group_name=main_resource_group.name,
            location=main_resource_group.location,
            account_tier="Standard",
            account_replication_type="LRS")
        main_action_group = azure.monitoring.ActionGroup("mainActionGroup",
            resource_group_name=main_resource_group.name,
            short_name="exampleact",
            webhook_receivers=[{
                "name": "callmyapi",
                "service_uri": "http://example.com/alert",
            }])
        example = azure.monitoring.MetricAlert("example",
            resource_group_name=main_resource_group.name,
            scopes=[to_monitor.id],
            description="Action will be triggered when Transactions count is greater than 50.",
            criterias=[{
                "metricNamespace": "Microsoft.Storage/storageAccounts",
                "metricName": "Transactions",
                "aggregation": "Total",
                "operator": "GreaterThan",
                "threshold": 50,
                "dimensions": [{
                    "name": "ApiName",
                    "operator": "Include",
                    "values": ["*"],
                }],
            }],
            actions=[{
                "action_group_id": main_action_group.id,
            }])
        ```

        :param str resource_name: The name of the resource.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[list] actions: One or more `action` blocks as defined below.
        :param pulumi.Input[bool] auto_mitigate: Should the alerts in this Metric Alert be auto resolved? Defaults to `true`.
        :param pulumi.Input[list] criterias: One or more `criteria` blocks as defined below.
        :param pulumi.Input[str] description: The description of this Metric Alert.
        :param pulumi.Input[bool] enabled: Should this Metric Alert be enabled? Defaults to `true`.
        :param pulumi.Input[str] frequency: The evaluation frequency of this Metric Alert, represented in ISO 8601 duration format. Possible values are `PT1M`, `PT5M`, `PT15M`, `PT30M` and `PT1H`. Defaults to `PT1M`.
        :param pulumi.Input[str] name: The name of the Metric Alert. Changing this forces a new resource to be created.
        :param pulumi.Input[str] resource_group_name: The name of the resource group in which to create the Metric Alert instance.
        :param pulumi.Input[str] scopes: A set of strings of resource IDs at which the metric criteria should be applied.
        :param pulumi.Input[float] severity: The severity of this Metric Alert. Possible values are `0`, `1`, `2`, `3` and `4`. Defaults to `3`.
        :param pulumi.Input[dict] tags: A mapping of tags to assign to the resource.
        :param pulumi.Input[str] window_size: The period of time that is used to monitor alert activity, represented in ISO 8601 duration format. This value must be greater than `frequency`. Possible values are `PT1M`, `PT5M`, `PT15M`, `PT30M`, `PT1H`, `PT6H`, `PT12H` and `P1D`. Defaults to `PT5M`.

        The **actions** object supports the following:

          * `action_group_id` (`pulumi.Input[str]`) - The ID of the Action Group can be sourced from the `monitoring.ActionGroup` resource
          * `webhookProperties` (`pulumi.Input[dict]`) - The map of custom string properties to include with the post operation. These data are appended to the webhook payload.

        The **criterias** object supports the following:

          * `aggregation` (`pulumi.Input[str]`) - The statistic that runs over the metric values. Possible values are `Average`, `Count`, `Minimum`, `Maximum` and `Total`.
          * `dimensions` (`pulumi.Input[list]`) - One or more `dimension` blocks as defined below.
            * `name` (`pulumi.Input[str]`) - One of the dimension names.
            * `operator` (`pulumi.Input[str]`) - The dimension operator. Possible values are `Include` and `Exclude`.
            * `values` (`pulumi.Input[list]`) - The list of dimension values.

          * `metricName` (`pulumi.Input[str]`) - One of the metric names to be monitored.
          * `metricNamespace` (`pulumi.Input[str]`) - One of the metric namespaces to be monitored.
          * `operator` (`pulumi.Input[str]`) - The criteria operator. Possible values are `Equals`, `NotEquals`, `GreaterThan`, `GreaterThanOrEqual`, `LessThan` and `LessThanOrEqual`.
          * `threshold` (`pulumi.Input[float]`) - The criteria threshold value that activates the alert.
        """
        if __name__ is not None:
            warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
            resource_name = __name__
        if __opts__ is not None:
            warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
            opts = __opts__
        if opts is None:
            opts = pulumi.ResourceOptions()
        if not isinstance(opts, pulumi.ResourceOptions):
            raise TypeError('Expected resource options to be a ResourceOptions instance')
        if opts.version is None:
            opts.version = utilities.get_version()
        if opts.id is None:
            if __props__ is not None:
                raise TypeError('__props__ is only valid when passed in combination with a valid opts.id to get an existing resource')
            __props__ = dict()

            __props__['actions'] = actions
            __props__['auto_mitigate'] = auto_mitigate
            if criterias is None:
                raise TypeError("Missing required property 'criterias'")
            __props__['criterias'] = criterias
            __props__['description'] = description
            __props__['enabled'] = enabled
            __props__['frequency'] = frequency
            __props__['name'] = name
            if resource_group_name is None:
                raise TypeError("Missing required property 'resource_group_name'")
            __props__['resource_group_name'] = resource_group_name
            if scopes is None:
                raise TypeError("Missing required property 'scopes'")
            __props__['scopes'] = scopes
            __props__['severity'] = severity
            __props__['tags'] = tags
            __props__['window_size'] = window_size
        super(MetricAlert, __self__).__init__(
            'azure:monitoring/metricAlert:MetricAlert',
            resource_name,
            __props__,
            opts)

    @staticmethod
    def get(resource_name, id, opts=None, actions=None, auto_mitigate=None, criterias=None, description=None, enabled=None, frequency=None, name=None, resource_group_name=None, scopes=None, severity=None, tags=None, window_size=None):
        """
        Get an existing MetricAlert resource's state with the given name, id, and optional extra
        properties used to qualify the lookup.

        :param str resource_name: The unique name of the resulting resource.
        :param str id: The unique provider ID of the resource to lookup.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[list] actions: One or more `action` blocks as defined below.
        :param pulumi.Input[bool] auto_mitigate: Should the alerts in this Metric Alert be auto resolved? Defaults to `true`.
        :param pulumi.Input[list] criterias: One or more `criteria` blocks as defined below.
        :param pulumi.Input[str] description: The description of this Metric Alert.
        :param pulumi.Input[bool] enabled: Should this Metric Alert be enabled? Defaults to `true`.
        :param pulumi.Input[str] frequency: The evaluation frequency of this Metric Alert, represented in ISO 8601 duration format. Possible values are `PT1M`, `PT5M`, `PT15M`, `PT30M` and `PT1H`. Defaults to `PT1M`.
        :param pulumi.Input[str] name: The name of the Metric Alert. Changing this forces a new resource to be created.
        :param pulumi.Input[str] resource_group_name: The name of the resource group in which to create the Metric Alert instance.
        :param pulumi.Input[str] scopes: A set of strings of resource IDs at which the metric criteria should be applied.
        :param pulumi.Input[float] severity: The severity of this Metric Alert. Possible values are `0`, `1`, `2`, `3` and `4`. Defaults to `3`.
        :param pulumi.Input[dict] tags: A mapping of tags to assign to the resource.
        :param pulumi.Input[str] window_size: The period of time that is used to monitor alert activity, represented in ISO 8601 duration format. This value must be greater than `frequency`. Possible values are `PT1M`, `PT5M`, `PT15M`, `PT30M`, `PT1H`, `PT6H`, `PT12H` and `P1D`. Defaults to `PT5M`.

        The **actions** object supports the following:

          * `action_group_id` (`pulumi.Input[str]`) - The ID of the Action Group can be sourced from the `monitoring.ActionGroup` resource
          * `webhookProperties` (`pulumi.Input[dict]`) - The map of custom string properties to include with the post operation. These data are appended to the webhook payload.

        The **criterias** object supports the following:

          * `aggregation` (`pulumi.Input[str]`) - The statistic that runs over the metric values. Possible values are `Average`, `Count`, `Minimum`, `Maximum` and `Total`.
          * `dimensions` (`pulumi.Input[list]`) - One or more `dimension` blocks as defined below.
            * `name` (`pulumi.Input[str]`) - One of the dimension names.
            * `operator` (`pulumi.Input[str]`) - The dimension operator. Possible values are `Include` and `Exclude`.
            * `values` (`pulumi.Input[list]`) - The list of dimension values.

          * `metricName` (`pulumi.Input[str]`) - One of the metric names to be monitored.
          * `metricNamespace` (`pulumi.Input[str]`) - One of the metric namespaces to be monitored.
          * `operator` (`pulumi.Input[str]`) - The criteria operator. Possible values are `Equals`, `NotEquals`, `GreaterThan`, `GreaterThanOrEqual`, `LessThan` and `LessThanOrEqual`.
          * `threshold` (`pulumi.Input[float]`) - The criteria threshold value that activates the alert.
        """
        opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))

        __props__ = dict()

        __props__["actions"] = actions
        __props__["auto_mitigate"] = auto_mitigate
        __props__["criterias"] = criterias
        __props__["description"] = description
        __props__["enabled"] = enabled
        __props__["frequency"] = frequency
        __props__["name"] = name
        __props__["resource_group_name"] = resource_group_name
        __props__["scopes"] = scopes
        __props__["severity"] = severity
        __props__["tags"] = tags
        __props__["window_size"] = window_size
        return MetricAlert(resource_name, opts=opts, __props__=__props__)

    def translate_output_property(self, prop):
        return tables._CAMEL_TO_SNAKE_CASE_TABLE.get(prop) or prop

    def translate_input_property(self, prop):
        return tables._SNAKE_TO_CAMEL_CASE_TABLE.get(prop) or prop
