Occasional Bad Request with API to PATCH users
I have a user suspension script that I prefer to run instead of using the "Suspend user after X days of inactivity on LM portal" option in the UI, because of some custom logic. I set up a script ages ago and havent touched the code, but recently on a subset of users, I get a Bad Request (400) error. But whats weird is that all I'm doing is using /setting/admins/ with ?changePassword=false&validationOnly=false and building a minimalistic patching map of the required fields from the model, plus status is set to "suspended". It used to work 100% of the time, but weirdly when I coded it, there were only 3 required fields in the model: roles, password, email. And of course I'd set status in my map, convert to json, do all the stuff, no problem. But I noticed it was failing recently (I never set up alerts on fails) and assumed it was failing 100% of the time at first, reviewed the model and noticed they added "username" as required also, so I added that, expecting it to work, it didnt, so I took that out. THEN I discovered that on some users the old code works, but unlike before, there is a subset that I get a Bad Request on, using the exact same code. No idea why. I also later discovered, when a user came up for suspension that ended up working, that "roles" is not actually required because I removed that for a bit doing some testing, had a real suspend happen to come up, and the code worked without the "required"(??!!) field of "roles" not being in my patch object. This is SUPER FRUSTRATING that the API can change, and that the required fields may or may not be required. :) I made a full "every field" export api to csv script to output every user, looking for something like a property or a setting or something in the raw data that might distinguish a user that the script runs on versus one it wont. Heck I even have logs of the same user that the script had suspended last year (user asked to be reinstated) and it doesnt work on them now. I almost suspect it has something to do with the password, since I havent seen any SSO users the script fails on, and I cant see those. But when I look at every single property that comes back with a GET on the users, I'll have 2 local accounts with the same external group that have nothing different on fields like enabling 2FA or EULA or even the roles they are in or view permissions, there are 35 or so fields ...and nothing stands out. Everything seems like it should work for one user that works for another in these cases. And yet .... Bad Request. Sometimes. Driving me wild over here. At this point I've literally got the original code in place (never committed any changes during testing) and sometimes it works, sometimes it doesnt, but used to be 100% success last year. Stumped. Oh here is an example of the error: I guess I'm not really expecting any silver bullets for this issue, but just on the off chance this is a known issue, I figured I would double check. I wish there were some change log to the Swagger docs. Maybe there is, I'm UI-challenged. If there were API update history changelogs then it might be worth it to pin down when this issue started. Thanks!61Views0likes3CommentsHelp Needed: API to Move Discovered Instances of Device Data Source to Default Group
Hi, I have a Python script to move discovered instances of a Device Data Source to a default group. I tried using the PATCH /device/devices/{deviceId}/devicedatasources/{hdsId}/instances/{id} endpoint but wasn't successful. Which REST API should I be using for this? Code snippet: import logicmonitor_sdk from logicmonitor_sdk.rest import ApiException # Configure API client configuration = logicmonitor_sdk.Configuration() configuration.company = 'your_company' configuration.access_id = 'your_access_id' configuration.access_key = 'your_access_key' api_instance = logicmonitor_sdk.LMApi(logicmonitor_sdk.ApiClient(configuration)) # Set up parameters device_id = 3242 device_datasource_id = 353463564 instance_id = 13543752 device_datasource_default_group_id = 16343007 # Fetch the current instance details try: instance = api_instance.get_device_datasource_instance_by_id(device_id, device_datasource_id, instance_id) print(f"Before Instance Update:\n {instance}") # Update group information updated_instance_body = logicmonitor_sdk.models.DeviceDataSourceInstance( wild_value=instance.wild_value, display_name=instance.display_name, group_id=device_datasource_default_group_id, group_name='@default' ) # Update the instance with new group information api_response = api_instance.patch_device_datasource_instance_by_id(device_id, device_datasource_id, instance_id, updated_instance_body) print(f"After Instance Update:\n {api_response}") except ApiException as e: print(f"Exception when calling LogicMonitor API: {e}")141Views0likes6CommentsLM API
Interesting in hearing some use cases you guys have for the LM API? I have a few scripts setup for mass device manipulation in the case of a change, mass auto discovery, automatically add a Windows server based off AD group, and automated internal ping scans based off a few parameters. Curious to see use cases you guys are using.131Views3likes9CommentsLogicMonitor Python API | Gather Stats
Hi All, I am looking into gathering stats from various devices (CPU usage, Memory usage, interface specific stats etc) programatically with Python. I am specifically using the LogicMonitor SDK for Python and have been wondering if anyone has had any luck gathering those types of stats from the API? Documentation I am following: LM API SDK What I have been doing: get_device_list. From this I am able to get the necessary deviceIDs get_device_datasource_list. Here I can see the data sources and their IDs. However, when I try to get_device_datasource_data_by_id with the IDs gathered in step 2, I get this error HTTP response body: {"errorMessage":"DeviceDataSource<13084642> is not found","errorCode":1404,"errorDetail":null} Is there an easier way to get these stats that I am not seeing?139Views0likes1Comment