How to add filters to API call for SDT devices
Hello -
I am able to fetch SDT devices by calling REST API https://abc.logicmonitor.com/santaba/rest/sdt/sdts?filter=type:DeviceSDT
How do I add additional filters based on system property ( Operating system) and Custom property (Region). Not able to filter results using below.
- Anonymous3 years ago
Swagger documentation shows that those attributes aren't contained in the response:
{ "total": 0, "searchId": "string", "items": [ { "endDateTimeOnLocal": "string", "timezone": "America/Los_Angeles", "sdtType": "oneTime", "monthDay": 7, "weekOfMonth": "1", "admin": "string", "endDateTime": 1534554000000, "type": "DeviceGroupSDT", "isEffective": true, "minute": 6, "duration": 138, "endHour": 5, "startDateTime": 1534460400000, "hour": 3, "startDateTimeOnLocal": "string", "weekDay": "Sunday", "comment": "Emergency prod deployment", "id": "string", "endMinute": 18 } ] }
So, you'll have to make a call to /device/devices either for each item in the response, or fetch all the devices and marry the two lists together within your script.
FYI, using the SDK, this is pretty simple:
from lm import lm # how to use this line: https://communities.logicmonitor.com/topic/7713-lm-wrapper-for-the-python-sdk/ # do pagination if you have more than 1000 SDTs in your portal sdts = lm.get_sdt_list(size=1000,filter="type:\"DeviceSDT\"").items # do pagination if you have more than 1000 devices in your portal devices = lm.get_device_list(size=1000).items for sdt in sdts: print(f"{sdt.id}::{devices[sdt.device_id].display_name}\n{'='*80}\n{sdt}\n{'='*80}\n{devices[sdt.device_id]}")
This prints out each device SDT with the corresponding device record. You could use dictionary comprehension to build a quick dictionary with this stuff all zipped together.