Come join our live training webinar every other Wednesday at 11am PST and hear LogicMonitor experts explain best practices and answer common questions. We understand these are uncertain times, and we are here to help!
LM Service Insight enables you to create and monitor at the service level by creating logical “services” in LogicMonitor. The release of LM Service Insight coincided with the new umbrella term “resources”. Resources include devices, services, cloud resources, kubernetes resources (e.g. pods, nodes, services, deployments), and new types will be added as we move forwards. To ensure backwards compatibility, we did not rename our API resources. As such, API management of services is actually done via the devices resource, where a service is a type of device (and where the devices API endpoint really can be thought of as the resources API endpoint). This means that you can programmatically manage (add, create, update, delete) services with the devices API resource. This document provides examples and additional information for doing so.
Creating a service in the UI comprises of two parts:
With the API, these two steps would be:
While the ability to add DataSources isn’t published quite yet (coming soon…), you can easily add the service itself via API (and have DataSources that were created via UI or imported via API and that automatically apply to the service to aggregate data).
Aside from specifying a device type of 6 to create a service, there are a number of other requirements. Most importantly, the service members are specified via property. Below is a table that shows all required fields for creating a service with the /device/devices endpoint:
In addition to the required fields above, there are a number of optional fields you can include when creating your service (such as membership re-evaluation rate):
The following example script adds a Service named ‘Reporting Service’ that groups all devices with the property ‘kubernetes.label.app=argus’. The member re-evaluation interval is set to 30 minutes:
#!/usr/bin/env python import requests import json import hashlib import base64 import time import hmac #Account Info AccessId ='xxxxx' AccessKey ='yyyy' Company = 'ACCOUNT' #Request Info httpVerb ='POST' resourcePath = '/device/devices' queryParams ='?v=2' data = '{"name":"testAPIService","displayName":"Reporting Service","deviceType":6,"preferredCollectorId":-4,"customProperties":[{"name":"predef.bizService.evalMembersInterval","value":"30"},{"name":"predef.bizservice.members","value":"{\\"device\\":[{\\"deviceGroupFullPath\\":\\"*\\",\\"deviceDisplayName\\":\\"*\\",\\"deviceProperties\\":[{\\"name\\":\\"kubernetes.label.app\\",\\"value\\":\\"argus\\"}]}],\\"instance\\":[]}"}]}' #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 hmac = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest() signature = base64.b64encode(hmac.encode()) #Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(url, data=data, headers=headers) #Print status and body of response print ('Response Status:',response.status_code) parsed = json.loads(response.content) print(json.dumps(parsed, indent=4))