Problem with fetching instances from device
Hi
I'm quite new with LogicMonitor so sorry for maybe obvious question - I'm trying to get list of instances for specific datasource from specific device via python script
It should be fairly easy as it pretty well described in documentation
First I get list of DS's from device with this: https://www.logicmonitor.com/support/rest-api-developers-guide/v1/datasources/get-datasources-associated-with-a-device
And then I want to use the data provided in this script: https://www.logicmonitor.com/support/rest-api-developers-guide/v1/datasource-instances/get-datasource-instances
I get the list of DS's where instance number > 0 but when I try to get instances I always get "DeviceDataSource(xxx) is not found for device(id=yyy)"
Below is my super simple script but I cannot find where is the issue - it is build based on scripts from LM doc
As an output I get datasource ID and name of it - e.g. when I gather information from Cisco switch I get
xx - BGP-
DeviceDataSource(xx) is not found for device(id=yy)
zz - Network Interfaces
DeviceDataSource(zz) is not found for device(id=yy)
And I'm sure that there are instances for BGP or Network Interfaces so don't know why I always get "not found"
import requests
import json
import hashlib
import base64
import time
import hmac
from pprint import pprint
AccessId ='_accessid_'
AccessKey ='_accesskey_'
Company = '_companyname_'
httpVerb = 'GET'
deviceID = '_deviceid_'
proxies = {
"http" : "_httpProxy_",
"https" : "_httpsProxy_",
}
def getData(rP, qP):
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + rP + qP
#Get current time in milliseconds
epoch = str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + rP
#Construct signature
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
#Make request
response = requests.get(url, headers=headers, proxies=proxies)
return response.json()
resourcePath = '/device/devices/' + deviceID + '/devicedatasources'
queryParameters = '?filter=instanceNumber>0'
devDSs = getData(resourcePath, queryParameters)
for x in devDSs['data']['items']:
print(str(x['dataSourceId']) + " - " + x['dataSourceDisplayName'])
resourcePath = '/device/devices/' + deviceID + '/devicedatasources/' + str(x['dataSourceId']) + '/instances'
queryParameters = ''
resp = getData(resourcePath, queryParameters)
print(resp['errmsg'])