アラート ルールの詳細の更新
最終更新日: 29 年 2023 月 XNUMX 日LogicMonitor REST API v3 を使用してアラート ルールを更新できます。 API リクエストを行う前に、自分自身を認証する必要があります。
URI: パッチ /setting/alert/rules/{id}
URI: 置く /setting/alert/rules/{id}
説明 | ||
id | 整数 | (必須の) The alert rule ID that you want to update. |
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 expressions that match with any characters. Example – “instance” : “*” |
devices | 文字列配列 | アラート ルールと一致するように構成されたデバイス名とサービス名。 例 - “devices” : [ “Cisco Router” ] |
escalatingChainId | 整数 | (必須の) アラート ルールに関連付けられたエスカレーション チェーン ID。 例 - “escalatingChainId” : 5 |
resourceProperties | JSON配列 | リソース プロパティの名前と値を含むリソース プロパティ フィルター リスト。 |
sendAnomalySuppressedAlert | ブーリアン | (必須の) 異常抑制アラートを送信するには、値を次のように設定します。 true 、それ以外の場合は次のように設定します false . |
priority | 整数 | (必須の) アラート ルールに関連付けられた優先度。 例 - "priority": 4 |
suppressAlertAckSdt | ブーリアン | 確認応答および SDT のステータス通知をアラート ルールに送信するかどうかを示します。 例 - “suppressAlertAckSdt” : false |
datasource | 文字列 | アラート ルールと一致するように構成されたデータソース。 例 - “datasource” : “Port-” |
suppressAlertClear | ブーリアン | アラート クリア通知をアラート ルールに送信するかどうかを示します。 例 - “suppressAlertClear” : true |
name | 文字列 | (必須の) アラート ルールの名前。 例 - “name”: ”Warning” |
levelStr | 文字列 | アラート ルールと一致するように構成されたアラート重大度レベル。 許容可能な値は次のとおりです。 All , Warn , Error 、 Critical 。 例 - “levelStr”: ”All” |
deviceGroups | 文字列配列 | アラート ルールと一致するように設定されたデバイス グループとサービス グループ。 例 - “deviceGroups” : [ “Devices by Type” ] |
escalationInterval | 整数 | アラート ルールに関連付けられたエスカレーション間隔 (分単位)。 例 - “escalationInterval” : 20 |
The following Python script updates the alert rule ID 74 in account api.logicmonitor.com.
#!/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)
The following Python script gets the alert rule ID 74, changes its priority, and then makes a PUT request to update it in api.logicmonitor.com.
#!/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)