メモの追加とアラートの確認

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

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

既存のアラートにメモを追加する

注: アラートにメモを追加しても、アラートが承認されるわけではありません。

URI: 投稿 /alert/alerts/{id}/note

タイプ説明
id文字列(必須の) メモを追加するアラートの ID または内部 ID。
ackComment文字列(必須の) アラートを認識するメモ。 例 - "ackComment": "Looking into this alert."

アラートの確認

URI: 投稿 /alert/alerts/{id}/ack

タイプ説明
id文字列(必須の) 確認するアラートの ID または内部 ID。
ackComment文字列(必須の) アラートを承認するコメント。 例 - "ackComment": "maintenance"

次の Python スクリプトは、「maintenance」というコメントが付いたアラート DS304962 を確認します。

#!/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 = '/alert/alerts/DS304962/ack'
queryParams =''
data = '{"ackComment":"maintenance"}'
 
#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
記事上で