すべてのプロダクト
Search
ドキュメントセンター

Simple Log Service:アラートルールの有効化

最終更新日:Jan 06, 2025

EnableAlert APIを呼び出して、アラートルールを有効にします。

前提条件

パラメータ説明

def enable_alert(self, project_name, job_name):

パラメーター

必須 / 任意

説明

project_name

String

対象

プロジェクトの名前。

demo-test-project

job_name

String

対象

アラートルールの ID。

alert-0123456789-123456

詳細については、「EnableAlert」をご参照ください。

サンプルコード

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'
    alertId = 'alert-0123456789-123456'

    client = LogClient(endpoint, accessKeyId, accessKey, "")

    res = client.enable_alert(project, alertId)
    res.log_print()


if __name__ == '__main__':
    main()

関連ドキュメント