Forum Discussion

cvl's avatar
cvl
Icon for Neophyte rankNeophyte
3 months ago

Add Device using the python SDK

Hello,

I have a challenge when I add a device using the logicmonitor Python SDK, I see the property values have been successfully added when I manage the device on LM, but the scripts that need the  properties to run do not seem to work. I created a test script to just 'println' the properties and it gave me the correct values. The only way I could get around the problem was to manually re-enter the values that were populated by the script.

 

I have attached the script used below. Is there a consideration that has to be taken when setting the property of API keys? I am using text.

###############

    async def addDevice(group_id):

        body = logicmonitor_sdk.models.Device(

            display_name=customer + '_Genesys_Host',

            name=customer+'_Genesys_Host.lm.ipiplatform.com',

            preferred_collector_id=38,

            disable_alerting=False,

            host_group_ids=group_id,

            custom_properties=[

                {'name': 'genesys.api.key', 'value': apiUser},

                {'name': 'genesys.api.password', 'value': apiPass},

                {'name': 'billing.api.key', 'value': billUser},

                {'name': 'billing.api.password', 'value': billPass},

                {'name': 'genesys.api.url', 'value': apiURL},

                {'name': 'genesys.login.url', 'value': loginURL},

                {'name': 'org.id', 'value': orgId},

                {'name': 'system.categories', 'value': 'billing'}],

            description='Genesys',

            user_permission='write',

            preferred_collector_group_name='C-IPI Customers (Auto Balanced Group - Linux)'

        )

        try:

            api_response = api_instance.add_device(body, add_from_wizard=True)

            pprint(api_response)

        except ApiException as e:

            logging.error(f"Exception when calling DevicesApi->addDevice: {e}")

####################################################################

 

 

  • when I add a device using the logicmonitor Python SDK, I see the property values have been successfully added when I manage the device on LM

    I created a test script to just 'println' the properties and it gave me the correct values.

    I personally have not used the Python SDK (I'm more a PowerShell person). But based on that you see the properties in the portal for the new device and your test script is working, I would assume your script above is fine at this stage.

    Do you have more details on what you mean by "the scripts that need the  properties to run do not seem to work"? Are these more Python SDK scripts or perhaps custom DataSource scripts that attempt to look for those properties? What does that code look like?

    • cvl's avatar
      cvl
      Icon for Neophyte rankNeophyte

      Hi Mike,

      I have used the Python Script to add the device. I then have groovy scripts which use the properties of the created device to connect and query API's. The problem I am having is that the groovy scripts do not run with the properties of the device. It seems to be a problem with extra blank spaces in the properties.

       

      • Mike_Moniz's avatar
        Mike_Moniz
        Icon for Professor rankProfessor

        Groovy script in a DataSource or other LogicModule? Something you wrote or got somewhere else? If you wrote it, can you post example minimal code that replicates the issue? If you got it somewhere else, can you point out where?