Updating Datasource Instance Details

Last updated on 10 January, 2024

You can use LogicMonitor REST API v3 to update datasource instance details. You must authenticate yourself before making the API request.

Note:

  • As per the REST standards, any property which is not specified in the PUT request will revert to its default value.
  • You can update datasources instances that do not have Active Discovery enabled.

URI: PATCH /device/devices/{deviceId}/devicedatasources/{hdsId}/instances/{id}

URI: PUT /device/devices/{deviceId}/devicedatasources/{hdsId}/instances/{id}

ParameterTypeDescription
deviceIdInteger(Mandatory) The device ID.
hdsIdInteger(Mandatory) The device datasource ID.
idInteger(Mandatory) The instance ID that you want to update.
opTypeStringSpecify the operation type. Accepted values are refresh (default), replace, and add.
isUNCInstanceBooleanIndicates if UNC monitoring is enabled for the device.
stopMonitoringBooleanIndicates if monitoring is disabled for the instance.
displayNameString(Mandatory) It is the instance alias. It is the descriptive name of the instance, and should be unique to the device/datasource combination.
wildValue2StringOnly 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.
groupIdIntegerThe instance group ID associated with the datasource instance.
descriptionStringThe description of the datasource instance.
disableAlertingBooleanIndicates if alerting is disabled for the instance.
systemPropertiesJSON ArraySpecify the name and value of instance level system properties assigned to the instance.
autoPropertiesJSON ArraySpecify the name and value of instance level auto properties assigned to the instance.
customPropertiesJSON ArraySpecify the name and value of instance level custom properties assigned to the instance.
lockDescriptionBooleanIndicates if active discovery is enabled and if the instance description is editable.
wildValueString(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.

Run the following Python script to update instance ID 144279093 and disable alerting.

#!/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 ='PUT'
resourcePath = '/device/devices/56/devicedatasources/3294/instances/144279093'
queryParams =''
data = '{"groupId":10354,"wildValue":"www.google.com","displayName":"apiInstancess","disableAlerting":true}'
 
#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
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':3}
 
#Make request
response = requests.put(url, data=data, headers=headers)
 
#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3