アラートルールの追加

最終更新日: 29 年 2023 月 XNUMX 日

LogicMonitor REST API v3 を使用してアラート ルールを追加できます。 API リクエストを行う前に、自分自身を認証する必要があります。

URI: 投稿 /setting/alert/rules

タイプ説明
datapoint文字列アラート ルールと一致するように構成されたデータポイント。 あらゆる文字と一致するグロブ表現をサポートします。 例 - “datapoint” : “*”
instance文字列インスタンスはアラート ルールと一致するように構成されています。 あらゆる文字と一致するグロブ表現をサポートします。 例 - “instance” : “*”
devices文字列配列アラート ルールと一致するように構成されたデバイス名とサービス名。 例 - “devices” : [ “Cisco Router” ]
escalatingChainId整数(必須の) アラート ルールに関連付けられたエスカレーション チェーン ID。 例 - “escalatingChainId” : 7
resourcePropertiesJSON配列リソース プロパティの名前と値を含むリソース プロパティ フィルター リスト。
sendAnomalySuppressedAlertブーリアン(必須の) 異常抑制アラートを送信するには、値を次のように設定します。 true、それ以外の場合は次のように設定します false.
priority整数(必須の) アラート ルールに関連付けられた優先度。 例 - "priority" : 3
suppressAlertAckSdtブーリアン確認応答および SDT のステータス通知をアラート ルールに送信するかどうかを示します。 例 - “suppressAlertAckSdt” : false
datasource文字列アラート ルールと一致するように構成されたデータソース。 例 - “datasource” : “Port-” 
suppressAlertClearブーリアンアラート クリア通知をアラート ルールに送信するかどうかを示します。 例 - “suppressAlertClear” : true
name文字列(必須の) アラート ルールの名前。 例 - “name” : ”Warning”
levelStr文字列アラート ルールと一致するように構成されたアラート重大度レベル。 許容可能な値は次のとおりです。 AllWarnErrorCritical。 例 - “levelStr”: ”All”
deviceGroups文字列配列アラート ルールと一致するように設定されたデバイス グループとサービス グループ。 例 - “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)
Pythonの3