8 years ago
SDT Report
I want to have a report that will give me all devices that are currently under an SDT, that will show the device name, SDT Start Date, SDT End Date, and the comments of the SDT>
This script gets pretty close, I think:
from lm import lm devices = lm.get_device_list(size=1000).items sdts = lm.get_sdt_list(size=1000).items r = {} for device in devices: r[device.id] = {"display_name": device.display_name, "name": device.name} r[device.id]["device_sdt"] = [s.to_dict() for s in [sdt for sdt in sdts if sdt.type=="DeviceSDT"] if device.id == s.device_id] r[device.id]["group_sdt"] = [s.to_dict() for s in [sdt for sdt in sdts if sdt.type=="DeviceGroupSDT"] if s.device_group_id in [int(i) for i in device.host_group_ids.split(',')]] print("device_id,display_name,name,sdt_type,sdt_start_time,sdt_end_time,sdt_timezone") for k,v in r.items(): for ds in v['device_sdt'] + v['group_sdt']: print(f"{k},{v['display_name']},{v['name']},{ds['type']},{ds['start_date_time_on_local']},{ds['end_date_time_on_local']},{ds['timezone']}")
Uses my own personal library to build the Python SDK object called lm. Doesn't do pagination on the device, list, but that wouldn't be too hard to build. This also may output multiple lines for a single device, if multiple SDTs apply to the same device. Wouldn't be too complicated to flatten the list.
This is what the output looks like on mine:
device_id,display_name,name,sdt_type,sdt_start_time,sdt_end_time,sdt_timezone 58,LogicMonitor,lmstuartweenig.logicmonitor.com,DeviceGroupSDT,2022-05-02 10:25:00 CDT,2022-05-02 11:25:00 CDT,America/Chicago 62,Zoom,logicmonitor.zoom.us,DeviceGroupSDT,2022-05-02 10:25:00 CDT,2022-05-02 11:25:00 CDT,America/Chicago 78,Skilljar,status.skilljar.com,DeviceGroupSDT,2022-05-02 10:25:00 CDT,2022-05-02 11:25:00 CDT,America/Chicago 103,ConnectWise,staging.connectwisedev.com,DeviceSDT,2022-04-12 12:57:00 CDT,3022-04-12 14:57:00 CDT,America/Chicago 140,api.exchangeratesapi.io,api.exchangeratesapi.io,DeviceSDT,2022-05-06 20:00:00 CDT,2022-05-07 19:45:00 CDT,America/Chicago 140,api.exchangeratesapi.io,api.exchangeratesapi.io,DeviceSDT,2022-05-07 19:45:00 CDT,2022-05-08 19:30:00 CDT,America/Chicago 197,buttonmusic.local,buttonmusic.local,DeviceSDT,2022-03-23 10:23:00 CDT,3022-03-23 12:23:00 CDT,America/Chicago 239,boxxy.local,boxxy.local,DeviceSDT,2022-04-04 14:47:00 CDT,3022-04-04 16:47:00 CDT,America/Chicago
Hopefully I'll have some time today to repost my lmwrapper module (i had to pull it off github).