tencent cloud

Feedback

CreateAlarmPolicy

Last updated: 2023-05-19 16:22:48

    1. API Description

    Domain name for API request: monitor.tencentcloudapi.com.

    This API is used to create an alarm policy.

    A maximum of 20 requests can be initiated per second for this API.

    We recommend you to use API Explorer
    Try it
    API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

    2. Input Parameters

    The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

    Parameter Name Required Type Description
    Action Yes String Common Params. The value used for this API: CreateAlarmPolicy.
    Version Yes String Common Params. The value used for this API: 2018-07-24.
    Region No String Common Params. This parameter is not required.
    Module Yes String Value fixed at "monitor"
    PolicyName Yes String Policy name, which can contain up to 20 characters
    MonitorType Yes String Monitor type. Valid values: MT_QCE (Tencent Cloud service monitoring)
    Namespace Yes String Type of alarm policy, which can be obtained via DescribeAllNamespaces. For the monitoring of Tencent Cloud services, the value of this parameter is QceNamespacesNew.N.Id of the output parameter of DescribeAllNamespaces, for example, cvm_device.
    Remark No String Remarks with up to 100 letters, digits, underscores, and hyphens
    Enable No Integer Whether to enable. Valid values: 0 (no), 1 (yes). Default value: 1. This parameter can be left empty
    ProjectId No Integer Project ID. For products with different projects, a value other than -1 must be passed in. -1: no project; 0: default project. If no value is passed in, -1 will be used. The supported project IDs can be viewed on the Account Center > Project Management page of the console.
    ConditionTemplateId No Integer Trigger condition template ID. Pass in this parameter if the policy is associated with the trigger condition template; otherwise, pass in the Condition parameter. The trigger condition template ID can be obtained via DescribeConditionsTemplateList.
    Condition No AlarmPolicyCondition Metric trigger condition. The supported metrics can be queried via DescribeAlarmMetrics.
    EventCondition No AlarmPolicyEventCondition Event trigger condition. The supported events can be queried via DescribeAlarmEvents.
    NoticeIds.N No Array of String List of notification rule IDs, which can be obtained via DescribeAlarmNotices
    TriggerTasks.N No Array of AlarmPolicyTriggerTask Triggered task list
    Filter No AlarmPolicyFilter Global filter.
    GroupBy.N No Array of String Aggregation dimension list, which is used to specify which dimension keys data is grouped by.
    Tags.N No Array of Tag Tags bound to a template
    LogAlarmReqInfo No LogAlarmReq Log alarm information
    HierarchicalNotices.N No Array of AlarmHierarchicalNotice Notification rules for different alarm levels
    MigrateFlag No Integer A dedicated field for migration policies. 0: Implement authentication logic; 1: Skip authentication logic.
    EbSubject No String The alert configured for an event

    3. Output Parameters

    Parameter Name Type Description
    PolicyId String Alarm policy ID
    OriginId String Alarm policy ID, which can be used when you call APIs (BindingPolicyObject, UnBindingAllPolicyObject, UnBindingPolicyObject) to bind/unbind instances or instance groups to/from an alarm policy
    RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

    4. Example

    Example1 Creating an alarm policy

    This example shows you how to associate two notification rules and one auto scaling policy where the policy type is "CVM - basic monitoring", triggering metric is "CPU utilization >= 99.9%", and triggering event is "unpingable".

    Input Example

    POST / HTTP/1.1
    Host: monitor.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreateAlarmPolicy
    <Common request parameters>
    
    {
        "Module": "monitor",
        "PolicyName": "CVM alarm policy",
        "Remark": "This is the remark",
        "MonitorType": "MT_QCE",
        "Enable": 1,
        "ProjectId": 0,
        "Namespace": "cvm_device",
        "Condition": {
            "IsUnionRule": 1,
            "Rules": [
                {
                    "MetricName": "cpu_usage",
                    "Period": 60,
                    "Operator": "ge",
                    "Value": "99.9",
                    "ContinuePeriod": 1,
                    "NoticeFrequency": 3600,
                    "IsPowerNotice": 0
                }
            ]
        },
        "EventCondition": {
            "Rules": [
                {
                    "MetricName": "ping_unreach"
                }
            ]
        },
        "NoticeIds": [
            "notice-bv9b4ghqbg",
            "notice-gj2n9wnt29"
        ],
        "TriggerTasks": [
            {
                "Type": "AS",
                "TaskConfig": "{\"Region\":\"ap-guangzhou\",\"Group\":\"asg-0zhspjx\",\"Policy\":\"asp-ganig28\"}"
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RequestId": "29ghj2hh-45-h53h234h-23",
            "PolicyId": "policy-hi498gw3h2",
            "OriginId": "1234556"
        }
    }
    

    5. Developer Resources

    SDK

    TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

    Command Line Interface

    6. Error Code

    The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

    Error Code Description
    FailedOperation Operation failed.
    FailedOperation.DoHTTPTransferFailed Backend service timed out.
    InternalError Internal error.
    InvalidParameter Invalid parameter.
    InvalidParameterValue The parameter value is incorrect.
    LimitExceeded Quota limit is reached.
    ResourceNotFound The resource is not found.
    UnsupportedOperation Unsupported operation.