アラート ルールの詳細の更新

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

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

URI: パッチ /setting/alert/rules/{id}

URI: 置く /setting/alert/rules/{id}

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

次の Python スクリプトは、アカウント api.logicmonitor.com のアラート ルール ID 74 を更新します。

#!/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 ='PUT'
resourcePath = '/setting/alert/rules/74'
queryParams =''
data = '{"name":"DBAlerts","priority":500,"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.put(url, data=data, headers=headers)
  
# Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Pythonの3

次の Python スクリプトは、アラート ルール ID 74 を取得し、その優先順位を変更して、api.logicmonitor.com で更新する PUT リクエストを作成します。

#!/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 ='GET'
resourcePath = '/setting/alert/rules/74'
queryParams =''
data = ''
 
#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.get(url, data=data, headers=headers)
 
#Parse response
jsonResponse = json.loads(response.content)
 
#Change Collector Id and add configuration object
rule = jsonResponse['data']
rule['priority'] = 50
 
#Request Info
httpVerb ='PUT'
resourcePath = '/setting/alert/rules/74'
queryParams =''
data = str(json.dumps(rule))
 
#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.put(url, data=data, headers=headers)
  
# Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Pythonの3