Obtain an alert rule
Updated at:
Retrieve a specified alert rule by calling the GetAlert API operation.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameter description
def get_alert(self, project, alertName):
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
project |
String |
Yes |
The project name. |
demo-test-project |
|
alertName |
String |
Yes |
The alert rule ID. |
alert-0123456789-123456 |
Response parameters
For more information about the response parameters, see GetAlert.
Sample code
from aliyun.log import LogClient
import os
def main():
# In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# Specify a Simple Log Service endpoint.
endpoint = "cn-hangzhou.log.aliyuncs.com"
project = 'demo-test-project'
alertName = 'alert-0123456789-123456'
client = LogClient(endpoint, accessKeyId, accessKey)
res = client.get_alert(project, alertName)
res.log_print()
if __name__ == '__main__':
main()
Sample response
header: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '1257', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Mon, 04 Nov 2024 09:28:28 GMT', 'x-log-time': '1730712508', 'x-log-requestid': '672893BCC4FEB1ED41AD0C84'}
body: {'name': 'alert-0123456789-123456', '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': '668e7eee7c1******6052cecb6817343', 'createTime': 1730712225, 'lastModifiedTime': 1730712225}
Process finished with exit code 0
References
-
For more information about alert rule APIs, see the following topics:
-
For more sample code, see Alibaba Cloud Simple Log Service SDK for Python on GitHub.
Is this page helpful?