This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Updating multiple custom properties from a list

I am using NPM 11.5.3 and trying to update multiple custom properties on a node through the use of SWIS Update and Python 2.7

custompropertylist = ['prop1', 'prop2', 'prop3']

for property in custompropertylist:

     value = raw_input("%s:" % prop)

     swis.update(uri + '/CustomProperties', property=value)

I have this successfully working if I don't use a list and manually define each property and execute, but I am trying to make my code more modular. I have tried tinkering with this for a bit without success and the only return value of SWIS Update I get is 'None'

  • nigel_sw While this is technically in the correct place, you might get a better response if you move it to the SDK forum. The SDK forum is specifically dedicated to exactly what your post is talking about.

    Orion SDK

  • You're right. Just got it moved, thanks.

  • I think you need something more like this:

    custompropertylist = ['prop1', 'prop2', 'prop3']

    for property in custompropertylist:

         value = raw_input("%s" % property)

         swis.update(uri + '/CustomProperties', {property: value})

    swis.update is expecting a dictionary of the properties to update. With the property=value syntax, you are going to be trying to set "property" to value. With the {property:value} syntax, you will set the "prop1" (and then later "prop2" and "prop3") to value.

  • swis.update(uri + '/CustomProperties', **{property: value})

    sorted me out. I had tried using the dictionary format beforehand and wasn't able to get it to work, but it's working now. I knew it was probably something trivial. Thanks.

  • HI,

    I am trying to do a similar thing:

    def update_props(hostid, prop, value):
    npm_server = REDACTED
    username = REDACTED
    password = REDACTED
    
    swis = SwisClient(npm_server, username, password)
    print("Custom Property Update Test:")
    results = swis.query(
    "SELECT Uri FROM Orion.Nodes WHERE NodeID=@id",
    id=1073) # set valid NodeID!
    uri = results['results'][0]['Uri']
    
    swis.update(uri + '/CustomProperties', {prop:value} )

    But I get the following error:

    Traceback (most recent call last):
    File "./custom_property_update.py", line 67, in <module>
    update_props(hostid, prop, value)
    File "./custom_property_update.py", line 43, in update_props
    swis.update(uri + '/CustomProperties', {prop:value} )
    TypeError: update() takes exactly 2 arguments (3 given)
    
    

    Can you point me in the right direction. I am passing it the dict as it expects am I not?

  • Error: update() takes 2 positional arguments but 3 were given

    data = swis.query('SELECT NodeID,Uri FROM Orion.Nodes WHERE IPAddress = ', ip=ip)['results']
    # print(data)
    if(data == []):
    print("Check the device, Unable to find")
    else:
    print("Device found")
    print(data[0]['Uri'])

    # for property in custompropertylist:
    swis.update(data[0]['Uri'] + '/CustomProperties', {'cpuutil':cpuutil})

    getting error please suggest


  •  wrote:

    Error: update() takes 2 positional arguments but 3 were given

    data = swis.query('SELECT NodeID,Uri FROM Orion.Nodes WHERE IPAddress = ', ip=ip)['results']
    # print(data)
    if(data == []):
    print("Check the device, Unable to find")
    else:
    print("Device found")
    print(data[0]['Uri'])

    # for property in custompropertylist:
    swis.update(data[0]['Uri'] + '/CustomProperties', {'cpuutil':cpuutil})

    getting error please suggest


    For a single property update like that, I believe you should be able to use the syntax from this sample without the curly braces around the property.  You can also take a look at this earlier comment and take a look at how Python treats that ** operator.