Add a Device

Last updated on 24 February, 2021

You can use LogicMonitor’s REST API to programmatically add device to your account.

As with all of our API calls, authentication is required.

HTTP Method: POST

URI: /device/devices

Request Parameters: You can POST the following properties for all new devices

Property

Description

Required?

Type

Example

name The host name or IP address of the device Yes String “name”:”10.36.11.240″
displayName The display name of the device Yes String “displayName”:”ProdServer24″
preferredCollectorId The Id of the preferred collector assigned to monitor the device Yes Integer “preferredCollectorId”:85
hostGroupIds The Id(s) of the groups the device is in, where multiple group ids should be comma separated No. Defaults to “1” (root group). String “hostGroupIds”:”2,34″
description The device description No String “description”:”A server in the LA Datacenter”
disableAlerting Indicates whether alerting is disabled (true) or enabled (false) for this device No. Defaults to false. Boolean “disableAlerting”:false
link The URL link associated with the device No String “link”:”https://status.aws.amazon.com”
enableNetflow Indicates whether Netflow is enabled (true) or disabled (false) for the device No. Default to false. Boolean “enableNetflow”:false
netflowCollectorId The Id of the netflow collector associated with the device Only if enableNetflow=true Integer “netflowCollectorId”:125
customProperties Define custom properties for this device. Each property needs to have a name and a value. No JSON object “customProperties”:[{“name”:”snmp.version”,”value”:”v2c”},{“name”:”location”,”value”:”Santa Barbara, CA”}]

Example Request

The following Python script adds a device with IP address is 172.16.19.171 to the device group with id 2 in account apiAccount.logicmonitor.com:

#!/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

Example Response

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
  }
}
In This Article