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.

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 Reply Children
  • Ok that was not soo bad after all, here is what worked for me

    import requests
    from orionsdk import SwisClient
    
    npm_server = ''
    username = ''
    password = ''
    
    verify = False
    if not verify:
        from requests.packages.urllib3.exceptions import InsecureRequestWarning
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    
    swis = SwisClient(npm_server, username, password)
    
    # select the URIs from the nodes NodeSettings
    results = swis.query("select Uri from Orion.NodeSettings where NodeId=28")
    
    # extract just the Uris from the results
    uris = [row['Uri'] for row in results['results']]
    
    # submit the request
    swis.bulkupdate(uris, SettingName='WMICredential', SettingValue=1)

  • Well that puts me to shame haha. Thank you! So that should allow me to change the SNMPV3 username, password etc?  Can I do it by grabbing a node based on IP?  My understanding of writing the queries breaks down when I have to mix items from different tables. Ie snmp credentials seem to sit in Orion.nodesettings and IP address in Orion.nodes

  • That example allows you to change the credential assigned to a node from a list of existing credentials. The credentials are seen in the Orion.Credentials entity

    SELECT Name, Description, CredentialType, CredentialOwner
    FROM Orion.Credential
    

    Do you want to create a new SNMPv3 credential definition and then assign it to a node or update an existing SNMPv3 credential already assigned to the node?

  • So I need to take a list of IP addresses of nodes and for each node change the current snmpv3 username and password to a new set (either custom or via a credential set)

  • Yea, this is how I do as well. If credentials are to be changed for a single node I will go for swis.update instead of bulkupdate and uri will string by then. This is the only 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" ?