有奖捉虫:办公协同&微信生态&物联网文档专题 HOT

1. 接口描述

接口请求域名: cls.tencentcloudapi.com 。

本接口用于获取告警策略执行详情

默认接口请求频率限制:30次/秒。

推荐使用 API Explorer
点击调试
API Explorer 提供了在线调用、签名验证、SDK 代码生成和快速检索接口等能力。您可查看每次调用的请求内容和返回结果以及自动生成 SDK 调用示例。

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数

参数名称 必选 类型 描述
Action String 公共参数,本接口取值:GetAlarmLog。
Version String 公共参数,本接口取值:2020-10-16。
Region String 公共参数,详见产品支持的 地域列表
From Integer 要查询的执行详情的起始时间,Unix时间戳,单位ms。
示例值:1702569600000
To Integer 要查询的执行详情的结束时间,Unix时间戳,单位ms。
示例值:1702655999999
Query String 查询过滤条件,例如:
- 按告警策略ID查询:alert_id:"alarm-0745ec00-e605-xxxx-b50b-54afe61fc971"
- 按监控对象ID查询:monitored_object:"823d8bfa-76a7-xxxx-8399-8cda74d4009b"
- 按告警策略ID及监控对象ID查询:alert_id:"alarm-0745ec00-e605-xxxx-b50b-54afe61fc971" AND monitored_object:"823d8bfa-76a7-xxxx-8399-8cda74d4009b"
- 按告警策略ID及监控对象ID查询支持SQL语句:(alert_id:"alarm-5ce45495-09e8-4d58-xxxx-768134bf330c") AND (monitored_object:"3c514e84-6f1f-46ec-xxxx-05de6163f7fe") AND NOT condition_evaluate_result: "Skip" AND condition_evaluate_result:[* TO *] | SELECT count(*) as top50StatisticsTotalCount, count_if(condition_evaluate_result='ProcessError') as top50StatisticsFailureCount, count_if(notification_send_result!='NotSend') as top50NoticeTotalCount, count_if(notification_send_result='SendPartFail' or notification_send_result='SendFail') as top50NoticeFailureCount, alert_id, alert_name, monitored_object, topic_type, happen_threshold, alert_threshold, notify_template group by alert_id, alert_name, monitored_object,topic_type, happen_threshold, alert_threshold, notify_template order by top50StatisticsTotalCount desc limit 1
示例值:alert_id:notice-c0960eb3-6454-4eef-xxxx-8feb766a9fbd
Limit Integer 单次查询返回的执行详情条数,最大值为1000
示例值:100
Context String 透传上次接口返回的Context值,可获取后续更多日志,总计最多可获取1万条原始日志,过期时间1小时。
注意:
* 透传该参数时,请勿修改除该参数外的其它参数
* 仅当检索分析语句(Query)不包含SQL时有效,SQL获取后续结果参考SQL LIMIT语法
示例值:context
Sort String 原始日志是否按时间排序返回;可选值:asc(升序)、desc(降序),默认为 desc
注意:
* 仅当检索分析语句(Query)不包含SQL时有效
* SQL结果排序方式参考SQL ORDER BY语法
示例值:asc
UseNewAnalysis Boolean true:代表使用新的检索结果返回方式,输出参数AnalysisRecords和Columns有效;
false:代表使用老的检索结果返回方式,输出AnalysisResults和ColNames有效;
两种返回方式在编码格式上有少量区别,建议使用true。
示例值:false

3. 输出参数

参数名称 类型 描述
Context String 加载后续详情的Context
ListOver Boolean 指定时间范围内的告警执行详情是否完整返回
示例值:false
Analysis Boolean 返回的结果是否为SQL分析结果
示例值:1
ColNames Array of String 分析结果的列名,如果Query语句有SQL查询,则返回查询字段的列名;
否则为空。
注意:此字段可能返回 null,表示取不到有效值。
示例值:["time","pv","uv"]
Results Array of LogInfo 执行详情查询结果。
当Query字段无SQL语句时,返回查询结果。
当Query字段有SQL语句时,可能返回null。
注意:此字段可能返回 null,表示取不到有效值。
AnalysisResults Array of LogItems 执行详情统计分析结果。当Query字段有SQL语句时,返回SQL统计结果,否则可能返回null。

注意:此字段可能返回 null,表示取不到有效值。
AnalysisRecords Array of String 执行详情统计分析结果;UseNewAnalysis为true有效。
注意:此字段可能返回 null,表示取不到有效值。
示例值:["xxx","yy"]
Columns Array of Column 分析结果的列名, UseNewAnalysis为true有效
注意:此字段可能返回 null,表示取不到有效值。
RequestId String 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。

4. 示例

示例1 查询日志

查询指定告警策略的告警历史记录

输入示例

POST / HTTP/1.1
Host: cls.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: GetAlarmLog
<公共请求参数>

{
    "From": 1702569600000,
    "To": 1702655999999,
    "Query": "(alert_id:\"alarm-5ce45495-09e8-4d58-8f36-768134bf330c\") AND (monitored_object:\"3c514e84-6f1f-46ec-afbf-05de6163f7fe\") AND NOT condition_evaluate_result: \"Skip\" AND condition_evaluate_result:[* TO *] | SELECT count(*) as top50StatisticsTotalCount, count_if(condition_evaluate_result='ProcessError') as top50StatisticsFailureCount, count_if(notification_send_result!='NotSend') as top50NoticeTotalCount, count_if(notification_send_result='SendPartFail' or notification_send_result='SendFail') as top50NoticeFailureCount, alert_id, alert_name, monitored_object, topic_type, happen_threshold, alert_threshold, notify_template group by alert_id, alert_name, monitored_object,topic_type, happen_threshold, alert_threshold, notify_template order by top50StatisticsTotalCount desc limit 1",
    "Limit": 1
}

输出示例

{
    "Response": {
        "Analysis": true,
        "AnalysisRecords": [],
        "AnalysisResults": [
            {
                "Data": [
                    {
                        "Key": "topic_type",
                        "Value": "log"
                    },
                    {
                        "Key": "alert_threshold",
                        "Value": "15"
                    },
                    {
                        "Key": "top50NoticeFailureCount",
                        "Value": "0"
                    },
                    {
                        "Key": "happen_threshold",
                        "Value": "1"
                    },
                    {
                        "Key": "top50StatisticsFailureCount",
                        "Value": "0"
                    },
                    {
                        "Key": "alert_id",
                        "Value": "alarm-5ce45495-09e8-4d58-8f36-768134bf330c"
                    },
                    {
                        "Key": "top50StatisticsTotalCount",
                        "Value": "705"
                    },
                    {
                        "Key": "alert_name",
                        "Value": "EdgeOne 缓存命中率告警策略_100001127589"
                    },
                    {
                        "Key": "monitored_object",
                        "Value": "3c514e84-6f1f-46ec-afbf-05de6163f7fe"
                    },
                    {
                        "Key": "top50NoticeTotalCount",
                        "Value": "0"
                    },
                    {
                        "Key": "notify_template",
                        "Value": "notice-8e0660a4-197d-46b0-b1ef-e63571b7a438"
                    }
                ]
            }
        ],
        "ColNames": [
            "top50StatisticsTotalCount",
            "top50StatisticsFailureCount",
            "top50NoticeTotalCount",
            "top50NoticeFailureCount",
            "alert_id",
            "alert_name",
            "monitored_object",
            "topic_type",
            "happen_threshold",
            "alert_threshold",
            "notify_template"
        ],
        "Columns": [],
        "Context": "",
        "ListOver": true,
        "RequestId": "716f9f96-ed8c-4a20-9e75-dfa27ba9a273",
        "Results": []
    }
}

示例2 查询指定告警策略和告警对象的告警历史记录

查询指定告警策略和告警对象的告警历史记录

输入示例

POST / HTTP/1.1
Host: cls.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: GetAlarmLog
<公共请求参数>

{
    "From": 1702569600000,
    "To": 1702655999999,
    "Query": "alert_id:\"alarm-5ce45495-09e8-4d58-8f36-768134bf330c\" AND monitored_object:\"3c514e84-6f1f-46ec-afbf-05de6163f7fe\"",
    "Limit": 1,
    "Context": ""
}

输出示例

{
    "Response": {
        "Analysis": false,
        "AnalysisRecords": null,
        "AnalysisResults": [],
        "ColNames": [],
        "Columns": null,
        "Context": "Y29udGV4dC0yNmJkYjY1ZS1lODdjLTQ5Y2ItODdiYy0xNmUwNWFlYTYwM2MxNzAyNjEyMzA4MTU1",
        "ListOver": false,
        "RequestId": "aefbd480-35c5-43b7-b1df-d625727abebf",
        "Results": [
            {
                "FileName": "",
                "HostName": "",
                "IndexStatus": "",
                "LogJson": "{\"reach_trigger\":\"false\",\"label_string\":\"\",\"fire_time\":1702612278007,\"reach_notify\":\"false\",\"record_group_id\":\"\",\"topic_type\":\"log\",\"alert_threshold\":15,\"trigger_result\":\"success\",\"monitored_object\":\"3c514e84-6f1f-46ec-afbf-05de6163f7fe\",\"duration\":0,\"condition_evaluate_result\":\"QueryResultUnmatch\",\"notify_type\":2,\"summary_en\":\"The trigger condition is not met\",\"notification_send_result\":\"NotSend\",\"trigger_time\":1702612278,\"notify_template\":\"notice-8e0660a4-197d-46b0-b1ef-e63571b7a438\",\"summary_cn\":\"执行语句结果不满足触发条件\",\"alert_id\":\"alarm-5ce45495-09e8-4d58-8f36-768134bf330c\",\"notify_result\":\"success\",\"topic_name\":\"dyltest2\",\"process_result\":\"fail\",\"notify_failed_reason\":\"\",\"object_param\":\"[{\\\"EndTime\\\":1702612230000,\\\"StartTime\\\":1702608630000,\\\"TopicId\\\":\\\"3c514e84-6f1f-46ec-afbf-05de6163f7fe\\\",\\\"TopicName\\\":\\\"dyltest2\\\",\\\"TopicType\\\":\\\"log\\\",\\\"grammarVersion\\\":\\\"cql\\\"}]\",\"uin\":100001127589,\"topic_id\":\"3c514e84-6f1f-46ec-afbf-05de6163f7fe\",\"record_info\":\"\",\"notify_time\":1702612278,\"level\":\"Warn\",\"process_error_msg\":\"The conditions are not matched, no results\",\"trigger\":\"$1.hit_rate<50\",\"trigger_failed_reason\":\"The conditions are not matched, no results\",\"happen_threshold\":1,\"record_id\":\"9e35be9f-b617-4827-96c5-97a0383aad0f\",\"nick_name\":\"\",\"logset_id\":\"19b6cec0-b80f-4ffe-98de-239670e5b19d\",\"detail\":\"\",\"alert_name\":\"EdgeOne 缓存命中率告警策略_100001127589\",\"process_error_type\":\"QueryResultUnmatch\",\"status\":\"QueryResultUnmatch\"}",
                "PkgId": "",
                "PkgLogId": "",
                "RawLog": "",
                "Source": "",
                "Time": 1702612278007,
                "TopicId": "louder",
                "TopicName": "louder"
            }
        ]
    }
}

5. 开发者资源

腾讯云 API 平台

腾讯云 API 平台 是综合 API 文档、错误码、API Explorer 及 SDK 等资源的统一查询平台,方便您从同一入口查询及使用腾讯云提供的所有 API 服务。

API Inspector

用户可通过 API Inspector 查看控制台每一步操作关联的 API 调用情况,并自动生成各语言版本的 API 代码,也可前往 API Explorer 进行在线调试。

SDK

云 API 3.0 提供了配套的开发工具集(SDK),支持多种编程语言,能更方便的调用 API。

命令行工具

6. 错误码

以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码

错误码 描述
FailedOperation 操作失败。
FailedOperation.GetlogReachLimit 检索日志触发最大条数限制。
FailedOperation.InvalidContext 检索游标已失效或不存在。
FailedOperation.QueryError 查询语句运行失败。
FailedOperation.SearchTimeout 查询超时。
FailedOperation.SyntaxError 查询语句解析错误。
FailedOperation.Timeout 操作超时
FailedOperation.TopicIsolated 日志主题已隔离。
InternalError 内部错误。
InternalError.SearchError 检索错误
InternalError.SearchFailed 检索失败
InvalidParameter 参数错误。
LimitExceeded.LogSearch 并发查询超过限制,单topic并发最大值15。
MissingParameter 缺少参数错误。
OperationDenied 操作被拒绝。
OperationDenied.AccountDestroy 账户已销毁。
OperationDenied.AccountIsolate 账户欠费。
OperationDenied.AccountNotExists 账户不存在。
ResourceNotFound.TopicNotExist 日志主题不存在。
UnsupportedOperation 操作不支持。