アラートルールの追加
最終更新日: 29 年 2023 月 XNUMX 日LogicMonitor REST API v3 を使用してアラート ルールを追加できます。 API リクエストを行う前に、自分自身を認証する必要があります。
URI: 投稿 /setting/alert/rules
説明 | ||
datapoint | 文字列 | The datapoint configured to match with the alert rule. It supports glob expression that match with any characters. Example – “datapoint” : “*” |
instance | 文字列 | The instance configured to match with the alert rule. It supports glob expression that match with any characters. Example – “instance” : “*” |
devices | 文字列配列 | The device name and service name configured to match with the alert rule. Example – “devices” : [ “Cisco Router” ] |
escalatingChainId | 整数 | (必須の) The escalation chain ID associated with the alert rule. Example – “escalatingChainId” : 7 |
resourceProperties | JSON配列 | リソース プロパティの名前と値を含むリソース プロパティ フィルター リスト。 |
sendAnomalySuppressedAlert | ブーリアン | (必須の) 異常抑制アラートを送信するには、値を次のように設定します。 true , else set it as false . |
priority | 整数 | (必須の) アラート ルールに関連付けられた優先度。 例 - "priority" : 3 |
suppressAlertAckSdt | ブーリアン | 確認応答および SDT のステータス通知をアラート ルールに送信するかどうかを示します。 例 - “suppressAlertAckSdt” : false |
datasource | 文字列 | The datasource configured to match with the alert rule. Example – “datasource” : “Port-” |
suppressAlertClear | ブーリアン | アラート クリア通知をアラート ルールに送信するかどうかを示します。 例 - “suppressAlertClear” : true |
name | 文字列 | (必須の) アラート ルールの名前。 例 - “name” : ”Warning” |
levelStr | 文字列 | The alert severity level configured to match with the alert rule. The acceptable values are: All , Warn , Error 、 Critical 。 例 - “levelStr”: ”All” |
deviceGroups | 文字列配列 | The device groups and service groups configured to match with the alert rule. Example – “deviceGroups” : [ “Devices by Type” ] |
escalationInterval | 整数 | アラート ルールに関連付けられたエスカレーション間隔 (分単位)。 例 - “escalationInterval” : 15 |
次の Python スクリプトは、すべてのグループとデバイスにわたる MYSQL データソース (名前に MYSQL が含まれるデータソース) のすべてのアラートに適用される優先度 1000 のルール「DBAlerts」を追加します。
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
##Request Info
httpVerb ='POST'
resourcePath = '/setting/alert/rules'
queryParams =''
data = '{"name":"DBAlerts","priority":1000,"datasource":"*MYSQL*","instance":"*","datapoint":"*","escalationInterval":15,"escalatingChainId":1}'
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath +queryParams
#Get current time in milliseconds
epoch = str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
#Construct signature
digest = hmac.new(
AccessKey.encode('utf-8'),
msg=requestVars.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
# Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':3}
# Make request
response = requests.post(url, data=data, headers=headers)
# Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)