OpsNotesを追加する

最終更新日: 14 年 2022 月 XNUMX 日

概要

LogicMonitorのRESTAPIを使用して、プログラムでopsノートをアカウントに追加できます。 すべてのAPI呼び出しと同様に、 認証が必要です.

詳細依頼フォーム

HTTPメソッド: POST

URI: / settings / opsnotes

リクエストパラメータ: すべての新しいopsノートに対して次のプロパティをPOSTできます。

プロパティ 説明 必須?
注意メモメッセージ有り文字列「注」:「1.0.0から1.2.4へのソフトウェアアップデート」
起こったOnInSecノートに関連付けられた日付と時刻(エポック秒形式)いいえ。デフォルトは現在の時刻です。整数「happenOnInSec」:1488826440
スコープメモに関連付けられているスコープ。 スコープのないメモは、アカウント内のすべてに表示されます。 各スコープオブジェクトには、タイプ(device、service、deviceGroup、serviceGroup)が必要です。 グループスコープの場合、groupIdを指定する必要があります。 デバイス/サービススコープの場合、deviceId / serviceIdを指定する必要があり、オプションでgroupIdを含めることができます。いいえ。デフォルトはスコープなしです。JSONオブジェクト“ scopes”:[{“ type”:” device”、” deviceId”:56}、{“ type”:” service”、” serviceId”:87、” groupId”:74}]
タグメモに関連付ける必要のあるタグ。 各タグには一意のIDと名前があります。新しいタグまたは既存のタグの名前、または既存のタグのIDを含めることができます。いいえ。デフォルトはタグなしです。JSONオブジェクト“ tags”:[{“ name”:” release”}、{“ name”:” upgrade”}]

次のPythonスクリプトは、アカウントapi.logicmonitor.comにOps Noteを追加し、メモ「deploy version 3.4.5」とタグ「reporting」を、ID530のデバイスに追加します。

注: 以下に提供されているスクリプトは、説明のみを目的としています。 実装では、AccessIdやAccessKeyなどの機密情報を安全に保存および取得する必要があります。





#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac
import gatepass

#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
print(auth)
 
# 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)
パイソン3
記事上で