ContributionsMost RecentMost LikesSolutionsRe: API call - Postman - select specific systemProperties - ?fields= Not to beat this dead horse, I’m assuming this also applies to the “fields” parameter as well? Like I’m trying to just pull back an easy list of devices in a device group folder and I only want a handful of fields to return, but I can’t seem to get that to work either. Python SDK hangs with no output I have a simple query script that looks for GroupID values. It’s really as simple as: api = logicmonitor_sdk.LMApi(logicmonitor_sdk.ApiClient(configuration)) search=sys.argv[1] try: api_response = api.get_device_group_list(filter=f"name~\"{search}\"||customProperties~\"{search}\"") for d in api_response.items: print(f"{d.id}:{d.full_path}") except ApiException as e: print("Exception when calling LMApi->getAlertList: %s\n" % e) I call the script from the CLI with something like: ./query_group.py “Some Detail” What I’ve noticed at times is that the script will just sit there (I’ve left it going for over 10 minutes) and it doesn’t seem to respond back any error or output. So I have to kill it with CTRL + C. I was wondering if there is a way in the SDK configuration to set a maximum wait time before an error/exception would be produced, thus ending the script? Re: API Filtering Info *** DISREGARD *** Being a fool, I was using CustomProperties instead of customProperties 🤣 ----- Original Message ---- Sorry to dig up an old thread. I’m looking at trying to find a Device Group ID based on trying to match (~) a value in a few areas and this thread was one of the only ones that seems to discuss API filtering. I’m trying to work out the filter syntax to try and match: device group “name” -or- custom property “location” -or- custom property “company.alias” Unfortunately i’m not getting the results I’m looking for. If I use the _all~{search} I do return what I”m looking for, but that may be too broad for me to use (_all). I tried something like this: api.get_device_group_list(filter=f"name~\"{search}\"||CustomProperties.value~\"{search}\"") But it does not return anything, but when I do the same {search} using _all it does return the device group ID i’m looking for. In this case, the Device Group will have a custom property for “company.alias” that I’m trying to match on. If I put the actual “name” into the search, I get the response I’m expecting. Any ideas where I might be going wrong? Re: Python SDK and creating multiple customProperties in one go This should be helpful for me. Once I set up my customProps as a list of dictionaries it worked like a charm (this is where my python lacks, coming more from a PHP background). I was close, just slightly off ;) Thanks for the tips and snippets. Re: Python SDK and creating multiple customProperties in one go Thanks Stuart. One of the libraries I was using is “argparse” from the CLI. My test script right now looks something like: ./script.py --primary ”Folder Name” --location ”123 somewhere ln, here, there 11111” --custom “building:Some Building” --custom “department:Some Department” --custom “role:Some Role” When I push via the SDK to the api.add_device_group() function, I would basically take the --location and all the --custom ones set via the CLI and “build” the customProperties that I want to POST in the body of the api call (along with some more common , one off variables I scrape). I’ll mess with the listofDicts as you illustrated and go from there. Thanks for your help. Python SDK and creating multiple customProperties in one go I’m trying to be able to supply a script to add some CustomProperties and I was wondering so that I don’t have to reinvent the wheel, if anyone has a quick method to building what is required to set in the BODY of the post. Let’s say I have some different custom properties I want to add: corp.building = “Some Building Name” corp.department = “Some Department Name” corp.role = “Some Role” Can I wrap all these up into a single array/dictionary to pass into the “customProperties” attribute in the “body” of the post? The idea could be I feed a CSV file into the script and the amount of customProperties can be 1 or 10 for any given line being processed. Thanks and let me know if I need to shed more light on what I’m expecting to happen. Re: Using Python SDK to create a DeviceGroup and subGroups Thanks, I was working off of this document: https://www.logicmonitor.com/support-files/rest-api-developers-guide/sdks/docs/#api-LM-addDeviceGroup I’ll just write the loop to add the sub-groups, I was just looking for a shortcut ;) Using Python SDK to create a DeviceGroup and subGroups I’m working on trying to build a script that will take some input (csv or stdin) to create a device group, and then also create multiple device groups under this one device group being specified. I have the python script working to create the first device group I need, but the “subGroups” feature does not seem to work or be populated and I was curious if anyone else had any luck with it? A snippet of my code looks like: infra_root = 'Network Infrastructure' infra_address = 'Test Location' infra_sub_groups = [ {"name":"Aggregation","fullPath":infra_root+"/"+infra_address+"/Aggregation"}, {"name":"Access","fullPath":infra_root+"/"+infra_address+"/Access"}, {"name":"Environmental","fullPath":infra_root+"/"+infra_address+"/Environmental"}, {"name":"PDU","fullPath":infra_root+"/"+infra_address+"/PDU"}, {"name":"UPS","fullPath":infra_root+"/"+infra_address+"/UPS"} ] body = { #"fullPath":infra_root+"/"+infra_address, "groupType":"Normal", "disableAlerting":False, "subGroups":infra_sub_groups, "enableNetflow":False, "parentId":18, "name":infra_address } The script fires off without error and creates he “infra_address” group no problem (under the parent I have). But the output of the script shows me sub_groups is blank: {'applies_to': '', 'aws_regions_info': '', 'aws_test_result': None, 'aws_test_result_code': 200, 'azure_regions_info': '', 'azure_test_result': None, 'azure_test_result_code': 200, 'created_on': 1676065949, 'custom_properties': [], 'default_collector_description': None, 'default_collector_id': 0, 'description': '', 'disable_alerting': False, 'effective_alert_enabled': True, 'enable_netflow': False, 'extra': {}, 'full_path': 'Network Infrastructure/Test Location', 'gcp_regions_info': '', 'gcp_test_result': None, 'gcp_test_result_code': 200, 'group_status': 'normal', 'group_type': 'Normal', 'has_netflow_enabled_devices': False, 'id': 164, 'name': 'Test Location', 'num_of_aws_devices': 0, 'num_of_azure_devices': 0, 'num_of_direct_devices': 0, 'num_of_direct_sub_groups': 0, 'num_of_gcp_devices': 0, 'num_of_hosts': 0, 'parent_id': 18, 'sub_groups': [], 'user_permission': 'write'} Doing it this way will make my life easier instead of running a script over and over again to populate the sub device groups. Thanks!
Top ContributionsPython SDK hangs with no outputPython SDK and creating multiple customProperties in one goRe: Using Python SDK to create a DeviceGroup and subGroupsUsing Python SDK to create a DeviceGroup and subGroupsRe: API Filtering InfoRe: Python SDK and creating multiple customProperties in one goRe: Python SDK and creating multiple customProperties in one goRe: API call - Postman - select specific systemProperties - ?fields=