Adding Datasource Instances
Last updated on 07 October, 2024You can add datasource instances that do not have Active Discovery enabled. You must authenticate yourself before making the API request.
URI: POST /device/devices/{deviceId}/devicedatasources/{hdsId}/instances
Parameter | Type | Description |
deviceId | Integer | (Mandatory) The device ID. |
hdsId | Integer | (Mandatory) The device datasource ID. |
isUNCInstance | Boolean | Indicates if UNC monitoring is enabled for the device. |
stopMonitoring | Boolean | Indicates if monitoring is disabled for the instance. |
displayName | String | (Mandatory) It is the instance alias. It is the descriptive name of the instance and should be unique to the device/datasource combination. |
wildValue2 | String | Only used for two dimensional active discovery. When used, during active discovery runs, the token ##WILDVALUE## is replaced with the value of ALIAS and the token ##WILDVALUE2## is replaced with the value of the second part alias. This value must be unique to the device/datasource/WILDVALUE combination. |
groupId | Integer | The instance group ID associated with the datasource instance. |
description | String | The description of the datasource instance. |
disableAlerting | Boolean | Indicates if alerting is disabled for the instance. |
systemProperties | JSON Array | Specify the name and value of instance level system properties assigned to the instance. |
autoProperties | JSON Array | Specify the name and value of instance level auto properties assigned to the instance. |
customProperties | JSON Array | Specify the name and value of instance level custom properties assigned to the instance. |
lockDescription | Boolean | Indicates if Active Discovery is enabled, and if the instance description is editable. |
wildValue | String | (Mandatory) The variable part of the instance, used to query data from a device. For example, variable part of the SNMP OID tree. This value must be unique for the device/datasource combination, unless two-dimensional active discovery is used. |
The following Python script adds an instance ‘google’ to the HTTP_Page datasource for device ID 38 in api.logicmonitor.com account.
#!/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 = '/device/devices/38/devicedatasources/2214/instances'
data = '{"wildValue":"www.google.com","displayName":"google"}'
#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
print requestVars
#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)
Adding Configuration Collection to Device
You can use LogicMonitor REST API v3 to add configuration collection to devices.
URI: POST /device/devices/{deviceId}/devicedatasources/{hdsId}/instances/{instanceId}/config/configCollection
Parameter | Type | Description |
deviceId | Integer | (Mandatory) The device ID. |
hdsId | Integer | (Mandatory) The device datasource ID. |
instanceId | Integer | (Mandatory) The instance ID to add configuration collection. |