Updating Datasource Instance Details
Last updated - 10 January, 2024
In this article
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}
Parameter | Type | Description |
deviceId | Integer | (Mandatory) The device ID. |
hdsId | Integer | (Mandatory) The device datasource ID. |
id | Integer | (Mandatory) The instance ID that you want to update. |
opType | String | Specify the operation type. Accepted values are refresh (default), replace , and add . |
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. |
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)