OpsNotesの追加

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

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

URI: 投稿 /setting/opsnotes

計測パラメータタイプ説明
note文字列(必須の) メモのメッセージ。
例– “note”:”software updated from 1.0.0 to 1.2.4″
scopesJSONオブジェクトメモに関連付けられたスコープ。 スコープのないメモは、アカウント内のすべてのものに対して表示されます。 Ops Notes スコープは次のもので構成されます。 type これは必須パラメータです。 例えば、 device。 各スコープ オブジェクトには、 type – device, service, deviceGroup, serviceGroup.
  • グループ スコープの場合 – を指定します。 groupId.
  • デバイス/サービスのスコープの場合 – を指定します。 deviceId/serviceId。 オプションで、 groupId.
例– “scopes”:[{“type”:”device”,”deviceId”:56},{“type”:”service”,”serviceId”:87,”groupId”:74}]
happenOnInSec整数メモに関連付けられた日付と時刻 (エポック秒形式)。 デフォルトは現在時刻です。 例 - “happenOnInSec”:1488826440
tagsJSONオブジェクトタグはメモに関連付けられている必要があります。 各タグには一意の ID と名前があります。 新規または既存のタグの名前、または既存のタグの ID を含めることができます。 例 - “tags”:[{“name”:”release”},{“name”:”upgrade”}]
Ops Notes タグ ベースは次のもので構成されます。 name これは必須パラメータです。

次の Python スクリプトは、アカウント api.logicmonitor.com に操作メモを追加します。このメモには、「バージョン 3.4.5 のデプロイ」と ID 530 のデバイスへのタグ「レポート」が含まれます。

#!/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/opsnotes'
queryParams =''
data = '{"note":"deploy version 3.4.5","tags":[{"name":"reporting"}],"scopes":[{"type":"device","deviceId":530}]}'
 
#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