• 0

Using API v2


Question

12 answers to this question

Recommended Posts

  • 0
  • Administrators
  • 0
Link to post
Share on other sites
  • 0
10 minutes ago, Stuart Weenig said:

FYI, the @Stefan W and Michael helped develop this little nugget that makes interacting with the SDK dead simple (two lines and you've got the results of an API call). 

 

Ye great work. Way easier than using the API (for me at least)

I found this documentation which looks very nice also:

https://www.logicmonitor.com/support-files/rest-api-developers-guide/sdks/docs/#api-LM-getAlertList

Question, in the example:

api_response = api_instance.get_alert_list_by_device_group_id(id, needMessage=needMessage, customColumns=customColumns, fields=fields, size=size, offset=offset, filter=filter)

How do you get the ID of the specific group? 

Thanks

Edited by MrJ
Link to post
Share on other sites
  • 0
  • Administrators
Just now, MrJ said:

How do you get the if of the specific group? 

Assuming you mean ID. There are several ways. Programmatically, you'd do a get_device_group_list() method call. You could get the whole list then filter/search in your script to find the ID, or you could include a filter in the call so that only the group you're interested in is returned.

 

Link to post
Share on other sites
  • 0
2 minutes ago, Stuart Weenig said:

Assuming you mean ID. There are several ways. Programmatically, you'd do a get_device_group_list() method call. You could get the whole list then filter/search in your script to find the ID, or you could include a filter in the call so that only the group you're interested in is returned.

 

Sorry, I yes I had a typo. OK yes I see that, thank you. I looked for something like that in the docs but missed it. Thanks a lot.

Link to post
Share on other sites
  • 0

Sorry, another question. I was trying to iterate through the api response keys (I thought it was just json) but I see it returns the var as a class. Is there some documentation or examples on how to work with the values? 

Thanks

Edited by MrJ
Link to post
Share on other sites
  • 0
  • Administrators

Yeah, it's a bummer that it doesn't just return it as a native python dictionary. Each item in the items object of the response has a .to_dict() method though. So, you'd do it like this:

Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lm import lm
>>> alerts = lm.get_alert_list()
>>> for alert in alerts.items:
...   for key in alert.to_dict().keys():
...     print(key)
... 
sdt
ack_comment
acked
acked_by
acked_epoch
alert_value
chain
chain_id
clear_value
cleared
custom_columns
data_point_id
data_point_name
detail_message
==== etc etc etc ===

 

Link to post
Share on other sites
  • 0
  • Administrators

Looks like the entire response has a .to_dict() method. However, this results in a dictionary where one of the entries is called "items". Unfortunately, dictionaries have a native method called items(), so this conflicts and you can't actually access that key pythonically (thanks Swagger). The above method is what I'd use.

Link to post
Share on other sites
  • 0
On 2/26/2021 at 6:33 PM, Stuart Weenig said:

Looks like the entire response has a .to_dict() method. However, this results in a dictionary where one of the entries is called "items". Unfortunately, dictionaries have a native method called items(), so this conflicts and you can't actually access that key pythonically (thanks Swagger). The above method is what I'd use.

Thank you, I'll give that a try. 

Link to post
Share on other sites
  • 0
On 2/26/2021 at 6:33 PM, Stuart Weenig said:

Looks like the entire response has a .to_dict() method. However, this results in a dictionary where one of the entries is called "items". Unfortunately, dictionaries have a native method called items(), so this conflicts and you can't actually access that key pythonically (thanks Swagger). The above method is what I'd use.

Actually there was some weird behaviour going on when I was trying to access the data and was scratching my head but makes sense now. Thanks

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.