デバイスを追加する

最終更新日: 24 年 2021 月 XNUMX 日

LogicMonitorのRESTAPIを使用して、プログラムでデバイスをアカウントに追加できます。

すべてのAPI呼び出しと同様に、 認証が必要です.

HTTPメソッド:POST

URI:/ device / devices

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

プロパティ

説明

必須?

デバイスのホスト名またはIPアドレス 有り 文字列 「名前」:「10.36.11.240」
displayName デバイスの表示名 有り 文字列 “ displayName”:” ProdServer24”
PreferredCollectorId デバイスを監視するために割り当てられた優先コレクターのID 有り 整数 「preferredCollectorId」:85
hostGroupId デバイスが属するグループのID。複数のグループIDはコンマで区切る必要があります。 いいえ。デフォルトは「1」(ルートグループ)です。 文字列 「hostGroupIds」:「2,34」
説明 デバイスの説明 いいえ 文字列 「説明」:「LAデータセンターのサーバー」
無効にするアラート このデバイスでアラートが無効(true)か有効(false)かを示します いいえ。デフォルトはfalseです。 ブーリアン 「disableAlerting」:false
デバイスに関連付けられているURLリンク いいえ 文字列 「リンク」:「https://status.aws.amazon.com」
イネーブルネットフロー Netflowがデバイスに対して有効(true)か無効(false)かを示します いいえ。デフォルトはfalseです。 ブーリアン 「enableNetflow」:false
ネットフローコレクターID デバイスに関連付けられているNetFlowコレクターのID enableNetflow = trueの場合のみ 整数 「netflowCollectorId」:125
カスタムプロパティ このデバイスのカスタムプロパティを定義します。 各プロパティには名前と値が必要です。 いいえ JSONオブジェクト “ customProperties”:[{“ name”:” snmp.version”、” value”:” v2c”}、{“ name”:” location”、” value”:” Santa Barbara、CA”}]

リクエストの例

次のPythonスクリプトは、IPアドレスが172.16.19.171のデバイスをアカウントapiAccount.logicmonitor.comのID2のデバイスグループに追加します。

#!/bin/env python

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

#Account Info
AccessId ='J62te62B8u7WnCR846h6'
AccessKey ='{[H^LX=^Zg^32yp-x(-2Bq22vZ~^u-k3)8!9[7U^'
Company = 'apiAccount'

#Request Info
httpVerb ='POST'
resourcePath = '/device/devices'
data = '{"name":"172.16.19.171","displayName":"ProdServer25","preferredCollectorId":171,"hostGroupIds":2,"customProperties":[{"name":"snmp.version","value":"v3"},{"name":"location","value":"Santa Barbara,CA"}]}'

#Construct URL 
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':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)
Pythonの3

応答例

Response Status: 200
Response Body: {
  "status" : 200,
  "errmsg" : "OK",
  "data" : {
    "id" : 409,
    "name" : "172.16.19.171",
    "displayName" : "ProdServer25",
    "deviceType" : 0,
    "relatedDeviceId" : -1,
    "currentCollectorId" : 171,
    "preferredCollectorId" : 171,
    "preferredCollectorGroupId" : 1,
    "preferredCollectorGroupName" : "@default",
    "description" : "",
    "createdOn" : 1466462717,
    "updatedOn" : 1466462717,
    "disableAlerting" : false,
    "autoPropsAssignedOn" : 0,
    "autoPropsUpdatedOn" : 0,
    "scanConfigId" : 0,
    "link" : "",
    "enableNetflow" : false,
    "netflowCollectorId" : 0,
    "netflowCollectorGroupId" : 0,
    "netflowCollectorGroupName" : null,
    "lastDataTime" : 0,
    "lastRawdataTime" : 0,
    "hostGroupIds" : "2",
    "sdtStatus" : "none-none-none",
    "userPermission" : "write",
    "hostStatus" : "normal",
    "alertStatus" : "none",
    "alertStatusPriority" : 100000,
    "awsState" : 1,
    "alertDisableStatus" : "none-none-none",
    "alertingDisabledOn" : null,
    "collectorDescription" : "SARAHSWINDOWSVM",
    "netflowCollectorDescription" : null,
    "customProperties" : [ {
      "name" : "location",
      "value" : "Santa Barbara,CA"
    }, {
      "name" : "snmp.version",
      "value" : "v3"
    }, {
      "name" : "system.categories",
      "value" : ""
    } ],
    "upTimeInSeconds" : 0,
    "deletedTimeInMs" : 0,
    "toDeleteTimeInMs" : 0,
    "hasDisabledSubResource" : false,
    "manualDiscoveryFlags" : null
  }
}
記事上で