How to update settingvalue in nodesettings table

I need to update SettingValue in NodeSettings Table for one of the node, I see an option to create a new one but not to update the existing one.

prop = {
        "NodeID": nodeid,
        "SettingName": "ROSNMPCredentialID",
        "SettingValue": value
      }
      result = swis.create("Orion.NodeSettings", **prop)

I am using the above code to create, kindly help me in updating the existing node.

Thanks

Goutham

Parents
  • Here is an example I use to update Nodesettings to change assigned credentials.

     

    Update Nodesettings to change assigned credential.
    
    
    # Connect to SWIS
    Import-Module SwisPowerShell
    Add-PSSnapin SwisSnapin
    $hostname = "127.0.01"
    $swis = Connect-Swis -Hostname $hostname
    
    #----------------------------------------------------------#
    
    #1. Define values for nodesettings to be updated.
    $NodeSettings = @{  
        SettingName= 'WMICredential';
       SettingValue= 7;
    }
    
    
    #get the URI for the setting.
    $Query = 'select uri from Orion.NodeSettings where nodeid=3';
    $Uri = get-swisData $swis $Query
    
    #3. Update the entity
    Set-SwisObject $swis $Uri -Properties $NodeSettings
    

  • How would someone do similar via Python?  I'm trying to change SNMPv3 credentials etc but can't for the life of me work out how to select those details to then change

  • I see 2 options here

    1. Update an existing SNMPv3 credential set. This will apply to all nodes which have that credential assigned.

    2. Create a new SNMPv3 credential set and assign it to a list of specific nodes based upon I.P Address.

    it sounds like you may need both options?

  • Mainly option 2 would be what I need. For now at least :)

  • Here is what I have come up with as starting point. It needs more commenting, code cleanup, better error handling, and some polish but should be enough to get started. The script provides 3 options

    1. Create a new SNMPv3 Credential.
    2. Update an existing SNMPv3 Credential.
    3. Assign an existing SNMPv3 Credential to a list of nodes based on the I.Ps.

    import requests
    from orionsdk import SwisClient
    requests.packages.urllib3.disable_warnings()
    print("SolarWinds Orion SNMPv3 management script")
    global npm_server 
    npm_server= ''
    global username 
    username = ''
    global password
    password = ''
    def default():
        print("Invalid Selection")
        main
    def main():
        option = int(input("\n SolarWinds Orion SNMPv3 Credential Script. \n \n Choose an Option:\n 1. Create a new SNMPv3 Credential.  \n 2. Update an existing SNMPv3 Credential. \n 3. Assign an existing SNMPv3 Credential to a list of Node I.Ps. \n \n Select Option: "))
        Options = {
            1 : CreateNew,
            2 : UpdateExisting,
            3 : AssignToNodes,  
            }
        Options.get(option,default)()
    
    def CreateNew():
        # Get the values -https://github.com/solarwinds/OrionSDK/wiki/Credential-Management 
        print("Creating a new SNMPv3 Credential Set.")
        CredentialName = input("Credential Name: ")
        UserName = input("User Name:")
        SNMPv3Context = input("SNMPv3 Context:")          
        AuthMethod = input("\nType an Authentication Method. Valid value are: \n None.  \n MD5. \n SHA1. \nAuthentication Method: ") #ToDo: Validate choices from list
        AuthPassword = input("Authentication Password:")
        AuthPassIsKey = input("Authentication Password is key? True/False:") #ToDo: Validate choices from list
        PrivEncrMethod = input("\nType an Privacy / Encryption Method. Valid value are: \n None.  \n MD5. \n AES128. \n AES192 \n AES256 \nAuthentication Method: ") #ToDo: Validate choices from list 
        PrivEncrMethodPass = input("Privacy / Encryption Method Password:")
        PrivEncrMethodPassIsKey = input("Privacy / Encryption Method Password is key? True/False:") #ToDo: Validate choices from list
        swis = SwisClient(npm_server, username, password)    
        snmpv3_credential_id = swis.invoke('Orion.Credential', 'CreateSNMPv3Credentials',CredentialName,UserName,SNMPv3Context,AuthMethod,AuthPassword,bool(AuthPassIsKey),PrivEncrMethod,PrivEncrMethodPass,bool(PrivEncrMethodPassIsKey))     
        print("Created new SNMPv3 Credential with ID:", snmpv3_credential_id)
    
    def UpdateExisting():
        #Only Updates SNMPv3 Credentials
        print("List of existing credentials.")
        swis = SwisClient(npm_server, username, password)
        credentials = swis.query("SELECT ID, Name FROM Orion.Credential where CredentialOwner='Orion'")
        for row in credentials['results']:
            print("{ID} - {Name}".format(**row))
        IDToUpdate = input("Choose a credential ID to update:")
        print("Updating Credential ID:",IDToUpdate )
        CredentialName = input("Credential Name: ")
        UserName = input("User Name:")
        SNMPv3Context = input("SNMPv3 Context:")          
        AuthMethod = input("\nType an Authentication Method. Valid value are: \n None.  \n MD5. \n SHA1. \nAuthentication Method: ") #ToDo: Validate choices from list
        AuthPassword = input("Authentication Password:")
        AuthPassIsKey = input("Authentication Password is key? True/False:") #ToDo: Validate choices from list
        PrivEncrMethod = input("\nType an Privacy / Encryption Method. Valid value are: \n None.  \n MD5. \n AES128. \n AES192 \n AES256 \nAuthentication Method: ") #ToDo: Validate choices from list 
        PrivEncrMethodPass = input("Privacy / Encryption Method Password:")
        PrivEncrMethodPassIsKey = input("Privacy / Encryption Method Password is key? True/False:") #ToDo: Validate choices from list
        swis = SwisClient(npm_server, username, password)    
        swis.invoke('Orion.Credential', 'UpdateSNMPv3Credentials',IDToUpdate,CredentialName,UserName,SNMPv3Context,AuthMethod,AuthPassword,bool(AuthPassIsKey),PrivEncrMethod,PrivEncrMethodPass,bool(PrivEncrMethodPassIsKey))     
        print("Updated SNMPv3 Credntial ID:",IDToUpdate)
    
    def AssignToNodes():
        print("Assign an existing credential to nodes")
        swis = SwisClient(npm_server, username, password) 
        credentials = swis.query("SELECT ID, Name FROM Orion.Credential where CredentialOwner='Orion'")
        for credentail in credentials['results']:
            print("{ID} - {Name}".format(**credentail))
        IDToAssign = input("Which credential do you want to assign?:")
        nodeips = input("Enter a comma seperated list of I.Ps which will be updated:")
        listofips = nodeips.split (",")
        swis = SwisClient(npm_server, username, password)  
        for ip in listofips:
            NodeIDs = swis.query("select NodeID from Orion.Nodes where ipaddress='{}'".format(ip))
            for NodeID in NodeIDs['results']:
                print("Found Node ID {NodeID}".format(**NodeID))
                query = "select Uri from Orion.nodesettings where settingname='RWSNMPCredentialID'and NodeID={}".format(NodeID["NodeID"])
                uris = swis.query(query)
                # extract just the Uris from the results
                urisstr = [row['Uri'] for row in uris['results']]
                result = swis.bulkupdate(urisstr, SettingName='RWSNMPCredentialID', SettingValue=IDToAssign)
                 
    
    if __name__ == '__main__':
        main()

  • thank you so much for this.  I had a few days off so i'll take a look today :).  Is there any decent websites with info about the Solarwinds query language and mixing tables?  i've seen lots about "relationships" and things like N.Orion.nodes etc but none that explain it enough for me to grasp it.  Outside of the scope of my quesiton but you seem to know a lot!

  • Sorry, what do you mean by "and uri will string by then" ?

  • In bulk update uri will be list of string whereas in single update it is not list of string instead just a string. This is what I am intended to say.

  • swis.bulkupdate can be passed a list of Uris and it will update them all, whereas in this case we are only updating a single Uri and so swis.update is more suitable as it accepts a Uri as a string type

  • thanks guys.  So because i'm trying this inside Ansible i've removed the input parts so i can later just enter the IP list into the script or bring it in from a file.  So far I get a nice list of ID and names of credentials and "Found Node ID ...."

    I figure I can manually input the credential i want instead of using IDToAssign?  If so, would the settingvalue= be the ID - Name of credential or just the ID?

    and how would those last 2 lines change for testing just a single node? Would it be:

    urisstr = [row['Uri'] for row in uris['results']]
    result = swis.update(urisstr, SettingName='RWSNMPCredentialID', SettingValue=**chosen credential as question above**)

    My modified version of your awesomely helpful script is this so far:

    print("Query Test:")
    credentials = swis.query("SELECT ID, Name FROM Orion.Credential WHERE CredentialOwner='Orion'")

    for credentail in credentials['results']:
    print("{ID} - {Name}".format(**credentail))

    nodeips = '**IP Address**,'
    listofips = nodeips.split (",")

    swis = SwisClient(npm_server, username, password)
    for ip in listofips:
    NodeIDs = swis.query("select NodeID from Orion.Nodes where ipaddress='{}'".format(ip))
    for NodeID in NodeIDs['results']:
    print("Found Node ID {NodeID}".format(**NodeID))
    query = "select Uri from Orion.nodesettings where settingname='RWSNMPCredentialID'and NodeID={}".format(NodeID["NodeID"])
    uris = swis.query(query)
    # extract just the Uris from the results
    # urisstr = [row['Uri'] for row in uris['results']]
    #result = swis.bulkupdate(urisstr, SettingName='RWSNMPCredentialID', SettingValue=IDToAssign)

  • I would highly recommend the following blog post which covers these topics thwack.solarwinds.com/.../intro-to-api-sdk-swql

  • Your very welcome, this has spurred me into working a little bit more with python and honestly I think I may be hooked :-)  Check out this post when you have some time. https://thwack.solarwinds.com/product-forums/the-orion-platform/f/orion-sdk/90898/python-api---credential-manager

Reply Children
No Data