赛尔校园公共服务平台 Logo
平台使用
阿里云
百度云
移动云
智算服务
教育生态
登录 →
赛尔校园公共服务平台 Logo
平台使用 阿里云 百度云 移动云 智算服务 教育生态
登录
  1. 首页
  2. 阿里云
  3. 日志服务
  4. 开发参考
  5. 日志服务SDK
  6. Python SDK
  7. 告警
  8. 列出告警规则

列出告警规则

  • 告警
  • 发布于 2025-04-22
  • 0 次阅读
文档编辑
文档编辑

使用ListAlerts接口列出指定Project下的告警规则。

前提条件

您已完成以下操作:

  • 开通日志服务。

  • 初始化日志服务Python SDK。

参数说明

def list_alert(self, project, offset=0, size=10):

请求参数

名称

类型

是否必填

描述

示例值

project

String

是

Project名称。

demo-test-project

offset

int

否

查询开始行。默认值为0。

0

size

int

否

分页查询时,设置的每页行数。最大值为 200。默认值为10。

10

返回参数

返回参数说明,请参见ListAlerts - 列出告警规则。

示例代码

from aliyun.log import LogClient
import os


def main():
    # 本示例从环境变量中获取AccessKey ID和AccessKey Secret
    accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')

    # 日志服务的服务接入点
    endpoint = "cn-hangzhou.log.aliyuncs.com"

    project = 'demo-test-project'

    client = LogClient(endpoint, accessKeyId, accessKey)

    res = client.list_alert(project)
    res.log_print()


if __name__ == '__main__':
    main()

示例返回结果

ListResponse for alerts:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '2917', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Mon, 04 Nov 2024 09:24:39 GMT', 'x-log-time': '1730712279', 'x-log-requestid': '672892D70EF2CAE571955AD9'}
count: 2
total: 2
alerts [{'name': 'alert-id-223456', 'type': 'Alert', 'apiType': 'Alert', 'status': 'ENABLED', 'description': '', 'displayName': 'Alert for testing', 'state': 'Enabled', 'recyclable': False, 'schedule': {'type': 'FixedRate', 'delay': 0, 'interval': '1m', 'runImmediately': False, 'timeZone': ''}, 'configuration': {'version': '2.0', 'type': 'default', 'dashboard': 'internal-alert-analysis', 'queryList': [{'storeType': 'log', 'region': 'cn-hangzhou', 'project': 'demo-test-project', 'store': 'test-logstore', 'query': '* | select count(*) cnt', 'timeSpanType': 'Truncated', 'start': '-1m', 'end': 'absolute', 'powerSqlMode': 'auto'}], 'groupConfiguration': {'type': 'no_group', 'fields': []}, 'joinConfigurations': [], 'severityConfigurations': [{'severity': 6, 'evalCondition': {'condition': 'cnt > 0', 'countCondition': ''}}], 'labels': [{'key': 'service', 'value': 'nginx'}], 'annotations': [{'key': 'title', 'value': 'Nginx Status Error'}, {'key': 'desc', 'value': 'Nginx Status Error, count: ${cnt}'}], 'autoAnnotation': True, 'sendResolved': False, 'threshold': 1, 'noDataFire': False, 'noDataSeverity': 6, 'policyConfiguration': {'alertPolicyId': 'sls.builtin.dynamic', 'actionPolicyId': 'test-action-policy', 'repeatInterval': '1m', 'useDefault': False}}, 'scheduleId': '668e7eee7c127******52cecb6817343', 'createTime': 1730712225, 'lastModifiedTime': 1730712225}, {'name': 'alert-id-123456', 'type': 'Alert', 'apiType': 'Alert', 'status': 'ENABLED', 'description': '', 'displayName': 'Nginx Status Error', 'state': 'Enabled', 'recyclable': False, 'schedule': {'type': 'FixedRate', 'delay': 0, 'interval': '1m', 'runImmediately': True, 'timeZone': ''}, 'configuration': {'annotations': [{'key': 'title', 'value': 'Nginx Status Error'}, {'key': 'desc', 'value': 'Nginx Status Error, count: ${cnt}'}], 'autoAnnotation': True, 'condition': '', 'conditionConfiguration': {}, 'dashboard': 'internal-alert-analysis', 'groupConfiguration': {'fields': [], 'type': 'no_group'}, 'joinConfigurations': [], 'labels': [{'key': 'service', 'value': 'nginx'}], 'noDataFire': False, 'noDataSeverity': 6, 'notifyThreshold': 1, 'policyConfiguration': {'actionPolicyId': 'test-action-policy', 'alertPolicyId': 'sls.builtin.dynamic', 'repeatInterval': '1m', 'useDefault': False}, 'queryList': [{'chartTitle': '', 'dashboardId': '', 'end': 'absolute', 'powerSqlMode': 'auto', 'project': 'demo-test-project', 'query': '* | select count(*) cnt', 'region': 'cn-hangzhou', 'start': '-1m', 'store': 'test-logstore', 'storeType': 'log', 'timeSpanType': 'Truncated', 'ui': '{}'}], 'sendRecoveryMessage': False, 'sendResolved': False, 'severityConfigurations': [{'evalCondition': {'condition': 'cnt > 0', 'countCondition': ''}, 'severity': 6}], 'sinkAlerthub': {'enabled': True}, 'sinkCms': {'enabled': False}, 'sinkEventStore': {'enabled': False, 'endpoint': '', 'eventStore': '', 'project': '', 'roleArn': ''}, 'tags': [], 'templateConfiguration': {'annotations': {}, 'tokens': {}}, 'threshold': 1, 'throttling': '1m', 'type': 'default', 'version': '2.0'}, 'scheduleId': '70d9a3a28ede4******461eff13ff8d5', 'createTime': 1730711770, 'lastModifiedTime': 1730711843}]

Process finished with exit code 0

相关文档

  • 管理告警规则的API请参见:

    • CreateAlert - 创建告警规则

    • DeleteAlert - 删除告警规则

    • UpdateAlert - 更新告警规则

    • EnableAlert - 开启告警规则

    • DisableAlert - 关闭告警规则

    • GetAlert - 获取告警规则

    • ListAlerts - 列出告警规则

  • 更多示例代码,请参见Aliyun Log Python SDK on GitHub。

相关文章

创建告警规则 2025-04-22 10:33

调用CreateAlert接口创建告警规则。 前提条件 您已完成以下操作:

删除告警规则 2025-04-22 10:33

使用DeleteAlert接口删除指定的告警规则。 前提条件 您已完成以下操作:

更新告警规则 2025-04-22 10:33

使用UpdateAlert接口更新告警规则。 前提条件 您已完成以下操作:

开启告警规则 2025-04-22 10:33

使用EnableAlert接口开启指定的告警规则。 前提条件 您已完成以下操作:

关闭告警规则 2025-04-22 10:33

使用DisableAlert接口关闭指定的告警规则。 前提条件 您已完成以下操作:

获取告警规则 2025-04-22 10:33

使用GetAlert接口获取指定的告警规则。 前提条件 您已完成以下操作:

目录
Copyright © 2025 your company All Rights Reserved. Powered by 赛尔网络.
京ICP备14022346号-15
gongan beian 京公网安备11010802041014号