Forum Discussion

MrJ's avatar
3 years ago

Python SDK

I'm looking at using the Python SDK to add some devices. 

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

When I go to define the body of the call (as per the example) it's complaining about Swagger not defined. 

Quote

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'swagger_client' is not defined

 

I can't install 'swagger_client' from pip. Is there some way I should be installing this to use for the SDK?

Any help appreciated.

Thanks

4 Replies

  • I think I figured this out, more by luck. I stumbled across this site "https://editor.swagger.io/" and I found the json file on the LM Swagger site, I popped it in there and generated a python client config. It seems to import the body now.

     

  • 1 hour ago, MrJ said:

    I think I figured this out, more by luck. I stumbled across this site "https://editor.swagger.io/" and I found the json file on the LM Swagger site, I popped it in there and generated a python client config. It seems to import the body now.

     

    This is prob a better doc to follow obv you need to change the auth path but any method in swagger doc should be on here with example code using the official SDK https://github.com/logicmonitor/lm-sdk-python/blob/master/LMApi.md 

  • 10 hours ago, Michael Baker said:

    This is prob a better doc to follow obv you need to change the auth path but any method in swagger doc should be on here with example code using the official SDK https://github.com/logicmonitor/lm-sdk-python/blob/master/LMApi.md 

     

    Thanks for the link. I will have a look, at first glance it seems very similar/same to the original link I used. The issue I was having was python didn't know what Swagger client was. I figured out you need to take  and generate a swagger python client installation. After that it worked. I don't see that documented anywhere in the documentation.

  • Anonymous's avatar
    Anonymous

    That example is overly descriptive. I was able to do it with this (uses my custom sdk wrapper )

    from lm import lm
    response = lm.add_device_datasource_instance(152,9042,{"displayName":"TESTSDK","wildValue":80})

    The body is just a python dictionary, no need for the swagger library to be installed manually.

     

    To get the device id, i did

    lm.get_device_list(size=1000)

    This is where the 152 came from in my call above.

     

    Once I had the device id, i did:

    for ds in lm.get_device_datasource_list(deviceID).items:
      print(ds.id, ds.data_source_name)

    To get the list of datasources and their IDs.  This is where the 9042 came from in my call above.