Get Devices

Last updated on 14 November, 2021

You can use LogicMonitor’s REST API to programmatically get information about your LogicMonitor devices. With the devices resource, you can:

  1. Get information about all devices in your LogicMonitor account
  2. Get information about a specific device in your LogicMonitor account

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

Get a list of Devices

Returns a list of devices

HTTP Method: GET

URI: /device/devices

Request Parameters: By default, a list of 50 devices will be returned. You can include sort, filter, fields, size and offset parameters in your request to control what data is included in the response and how it is formatted. Note that query parameters are not considered part of the resource path, and should not be included the calculation of the LMv1 authentication signature.

Property

Syntax

Description

Example URI

sort sort={+ or -}property Sorts the response by the property specified in either increasing (+) or decreasing (-) order /device/devices?sort=-id
filter filter=property{operator}value Filters the response according to the operator and value specified. Note that you can use * to match on more than one character. You can use the ‘.’ character to filter values within an object (e.g. custom properties), and multiple filters can be separated by a comma. See Example 5.

Operators include:

  • Greater than or equals: >:
  • Less than or equals: <:
  • Greater than: >
  • Less than: <
  • Does not equal: !:
  • Equals: :
  • Includes: ~
  • Does not include: !~
/device/devices?filter=name~QA*
fields fields={list of properties separated by commas} Filters the response to only include the following fields for each object /device/devices?fields=name,id
size size=integer The number of results to display. Max is 1000. /device/devices?size=5
offset offset=integer The number of results to offset the displayed results by /device/devices?offset=2

Get information about a particular device

Returns details for a particular device

HTTP Method:GET

URI: device/devices/{id}

Request Parameters: You can include a filter parameter that controls which fields are displayed in the response:

Property

Syntax

Description

Example URI

fields fields={list of properties separated by commas} Filters the response to only include the following fields for each object /device/devices/{id}?fields=displayName,id

Examples

Example Request 1: GET all Devices

The following Python 3 script will return a list of all devices in the api.logicmonitor.com account.

#!/bin/env python

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

#Account Info
AccessId ='your-access-id'
AccessKey ='your-access-key'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/device/devices'
data = ''

#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.get(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)

Example Request 2: GET Devices

The following Python 3 script will return a list of devices in api.logicmonitor.com whose display name contains ‘ip-172-31’:

#!/bin/env python

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

#Account Info
AccessId ='your-access-id' 
AccessKey ='your-access-key'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/device/devices'
queryParameters = '?filter=displayName~ip-172-31'
data = ''

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

#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.get(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)

Example Request 3: GET information for one device

The following Python 3 script will return the details for the device whose id is 39.

#!/bin/env python

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

#Account Info
AccessId ='your-access-id' 
AccessKey ='your-access-key'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/device/devices/39'
data = ''

#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.get(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)

Example Request 4: GET information for one device

The following Python 3 script will return the id, displayName, and custom properties for the device with id 39.

#!/bin/env python

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

#Account Info
AccessId ='your-access-id' 
AccessKey ='your-access-key'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/device/devices/39'
queryParameters = '?fields=id,displayName,customProperties'
data = ''

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

#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.get(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)

Example Request 5: GET devices that have a specific property value

The following Python 3 script will return the id, displayName and custom properties for devices that have a property named snmp.version and a property with value v2c:

#!/bin/env python

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

#Account Info
AccessId ='your-access-id' 
AccessKey ='your-access-key'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/device/devices'
data = ''
queryParams = '?fields=customProperties,name,id&filter=customProperties.name:snmp.version,customProperties.value:v2c'

#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
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.get(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)

Example Request 6: GET all devices

The following Python 3 script will iterate through all devices, 1000 at a time, to return all devices in the account api.logicmonitor.com:

#!/bin/env python

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

#Account Info
AccessId ='your-access-id' 
AccessKey ='your-access-key'
Company = 'api'

#Create list to keep devices
allDevices = []

#Loop through getting all devices
count = 0
done = 0
while done==0:   
    #Request Info
    httpVerb ='GET'
    resourcePath = '/device/devices'
    data=''
    queryParams ='?offset='+str(count)+'&size=10'

    #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
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.get(url, data=data, headers=headers)

    #Parse response & total devices returned
    parsed = json.loads(response.content)
    total = parsed['data']['total']
    devices = parsed['data']['items']
    allDevices.append(devices)
    numDevices = len(devices)
    count += numDevices
    if count == total:
        print "done"
        done = 1
    else:
        print "iterating again"

#print all devices
print json.dumps(allDevices, indent=5, sort_keys=True)

Example Response

The following illustrates an example response for one of the above example requests to the device/devices resource:

{
  "status" : 200,
  "errmsg" : "OK",
  "data" : {
    "total" : 64,
    "items" : [ {
      "id" : 38,
      "name" : "ip-172-31-36-135.us-west-2.compute.internal",
      "displayName" : "ip-172-31-36-135.us-west-2.compute.internal",
      "deviceType" : 0,
      "relatedDeviceId" : -1,
      "currentCollectorId" : 85,
      "preferredCollectorId" : 85,
      "preferredCollectorGroupId" : 1,
      "preferredCollectorGroupName" : "@default",
      "description" : "",
      "createdOn" : 1431975290,
      "updatedOn" : 1466459568,
      "disableAlerting" : false,
      "autoPropsAssignedOn" : 1466400549,
      "autoPropsUpdatedOn" : 1466400669,
      "scanConfigId" : 0,
      "link" : "",
      "enableNetflow" : false,
      "netflowCollectorId" : 0,
      "netflowCollectorGroupId" : 0,
      "netflowCollectorGroupName" : null,
      "lastDataTime" : 0,
      "lastRawdataTime" : 0,
      "hostGroupIds" : "58,7,29,4,2",
      "sdtStatus" : "none-none-none",
      "userPermission" : "write",
      "hostStatus" : "normal",
      "alertStatus" : "unconfirmed-warn-none",
      "alertStatusPriority" : 100,
      "awsState" : 1,
      "alertDisableStatus" : "none-none-none",
      "alertingDisabledOn" : null,
      "collectorDescription" : "ip-172-31-37-162.us-west-2.compute.internal",
      "netflowCollectorDescription" : null,
      "customProperties" : [ {
        "name" : "snmp.authToken",
        "value" : "********"
      }, {
        "name" : "snmp.version",
        "value" : "v3"
      }, {
        "name" : "snmp.security",
        "value" : "admin"
      }, {
        "name" : "jdbc.mysql.pass",
        "value" : "********"
      }, {
        "name" : "dbname",
        "value" : "productDB"
      }, {
        "name" : "jdbc.mysql.user",
        "value" : "sarah"
      }, {
        "name" : "location",
        "value" : "12 E. Carrillo, Santa Barbara, CA 93101"
      }, {
        "name" : "snmp.privToken",
        "value" : "********"
      }, {
        "name" : "system.categories",
        "value" : "snmpTCPUDP, Netsnmp, snmpHR, snmp, collector"
      } ],
      "upTimeInSeconds" : 10641993,
      "deletedTimeInMs" : 0,
      "toDeleteTimeInMs" : 0,
      "hasDisabledSubResource" : true,
      "manualDiscoveryFlags" : null
    }, {
      "id" : 39,
      "name" : "ip-172-31-37-162.us-west-2.compute.interal",
      "displayName" : "ip-172-31-37-162.us-west-2.compute.interal",
      "deviceType" : 0,
      "relatedDeviceId" : -1,
      "currentCollectorId" : 85,
      "preferredCollectorId" : 85,
      "preferredCollectorGroupId" : 1,
      "preferredCollectorGroupName" : "@default",
      "description" : "myDeviceDescription",
      "createdOn" : 1431975317,
      "updatedOn" : 1462395313,
      "disableAlerting" : false,
      "autoPropsAssignedOn" : 0,
      "autoPropsUpdatedOn" : 1466467148,
      "scanConfigId" : 0,
      "link" : "",
      "enableNetflow" : false,
      "netflowCollectorId" : 0,
      "netflowCollectorGroupId" : 0,
      "netflowCollectorGroupName" : null,
      "lastDataTime" : 0,
      "lastRawdataTime" : 0,
      "hostGroupIds" : "7,29",
      "sdtStatus" : "none-none-none",
      "userPermission" : "write",
      "hostStatus" : "dead",
      "alertStatus" : "unconfirmed-critical-none",
      "alertStatusPriority" : 1,
      "awsState" : 1,
      "alertDisableStatus" : "none-none-none",
      "alertingDisabledOn" : null,
      "collectorDescription" : "ip-172-31-37-162.us-west-2.compute.internal",
      "netflowCollectorDescription" : null,
      "customProperties" : [ {
        "name" : "resourceId",
        "value" : "i-b3611945"
      }, {
        "name" : "lm.pass",
        "value" : "********"
      }, {
        "name" : "lm.username",
        "value" : "sarah"
      }, {
        "name" : "snmp.version",
        "value" : "v2c"
      }, {
        "name" : "aws.accesskey",
        "value" : "********"
      }, {
        "name" : "lm.account",
        "value" : "sarah"
      }, {
        "name" : "snmp.community",
        "value" : "********"
      }, {
        "name" : "autotask.accountid",
        "value" : "TopDog"
      }, {
        "name" : "system.categories",
        "value" : "snmpTCPUDP, Netsnmp, snmpHR, snmp, collector"
      } ],
      "upTimeInSeconds" : 0,
      "deletedTimeInMs" : 0,
      "toDeleteTimeInMs" : 0,
      "hasDisabledSubResource" : false,
      "manualDiscoveryFlags" : null
    }, {
      "id" : 56,
      "name" : "ip-172-31-33-214.us-west-2.compute.internal",
      "displayName" : "ip-172-31-33-214.us-west-2.compute.internal",
      "deviceType" : 0,
      "relatedDeviceId" : -1,
      "currentCollectorId" : 90,
      "preferredCollectorId" : 90,
      "preferredCollectorGroupId" : 1,
      "preferredCollectorGroupName" : "@default",
      "description" : "",
      "createdOn" : 1433959544,
      "updatedOn" : 1466459565,
      "disableAlerting" : false,
      "autoPropsAssignedOn" : 1466395148,
      "autoPropsUpdatedOn" : 1466395148,
      "scanConfigId" : 0,
      "link" : "",
      "enableNetflow" : false,
      "netflowCollectorId" : 0,
      "netflowCollectorGroupId" : 0,
      "netflowCollectorGroupName" : null,
      "lastDataTime" : 0,
      "lastRawdataTime" : 0,
      "hostGroupIds" : "19,7,29,4",
      "sdtStatus" : "none-none-none",
      "userPermission" : "write",
      "hostStatus" : "normal",
      "alertStatus" : "unconfirmed-warn-none",
      "alertStatusPriority" : 100,
      "awsState" : 1,
      "alertDisableStatus" : "none-none-none",
      "alertingDisabledOn" : null,
      "collectorDescription" : "ip-172-31-37-162.us-west-2.compute.internal",
      "netflowCollectorDescription" : null,
      "customProperties" : [ {
        "name" : "resourceId",
        "value" : "i-ca784b3c"
      }, {
        "name" : "hipchat_api.pass",
        "value" : "********"
      }, {
        "name" : "snmp.version",
        "value" : "v2c"
      }, {
        "name" : "aws.accesskey",
        "value" : "********"
      }, {
        "name" : "snmp.community",
        "value" : "********"
      }, {
        "name" : "aws.region",
        "value" : "us-west-2"
      }, {
        "name" : "system.categories",
        "value" : "snmpTCPUDP, Netsnmp, snmpHR, snmp"
      } ],
      "upTimeInSeconds" : 9073928,
      "deletedTimeInMs" : 0,
      "toDeleteTimeInMs" : 0,
      "hasDisabledSubResource" : true,
      "manualDiscoveryFlags" : null
    } ],
    "searchId" : null
  }
}
In This Article