5 Replies Latest reply on Sep 15, 2017 2:05 PM by dan jagnow

    Help: How to enable Dynamic IP Address (DHCP or BOOTP) and assign a DNS Hostname through API

    kteng

      Hi, I can add node to SolarWinds perfectly, but I have some nodes need to enable DHCP option with DNS hostname.

       

      I tried to use 'DynamicIP': 1, but it return an error.

       

      Below is my code.

      results = addNode(swis)

       

      def addNode(s):

          print "Adding Node...",

          node_props = {

              'IPAddress': node_ip_address,

              'EngineID':    1,

              'ObjectSubType': 'SNMP',

              'Status': 1,

              'SNMPVersion':    2,

              'Community': node_community,

              'Caption': node_name,

              'AgentPort': node_snmp_port,

          }

          res = s.create('Orion.Nodes', **node_props)

          nodeid = re.search(r'(\d+)$', res).group(0)

          print " Done!"

          print "  Node ID: " + nodeid

          for n in node_props:

              print " ", n,": ",node_props[n]

          return res

        • Re: Help: How to enable Dynamic IP Address (DHCP or BOOTP) and assign a DNS Hostname through API
          kteng

          I fixed myself.

          I used 'DNS' and 'DynamicIP'.
          resolution:

              node_props = {

                  'IPAddress': node_ip_address,

                  'DNS': node_dns,

                  'EngineID':    1,

                  'ObjectSubType': 'SNMP',

                  'Status': 1,

                  'SNMPVersion':    2,

                  'Community': node_community,

                  'Caption': node_name,

                  'AgentPort': node_snmp_port,

                  'DynamicIP': True

              }

          1 of 1 people found this helpful
          • Re: Help: How to enable Dynamic IP Address (DHCP or BOOTP) and assign a DNS Hostname through API
            dan jagnow

            Kevin, here is a full sample adapted from orionsdk-python/add_node.py at master · solarwinds/orionsdk-python · GitHub

             

            from __future__ import print_function
            import re
            import requests
            from orionsdk import SwisClient
            
            
            def main():
                npm_server = 'localhost'
                username = 'admin'
                password = ''
            
                swis = SwisClient(npm_server, username, password)
                print("Add an SNMP v2c node:")
            
                # fill these in for the node you want to add!
                dns_name = 'myserver.mydomain.local'
                community = 'public'
            
                # set up property bag for the new node
                props = {
                    'DNS': dns_name,
                    'DynamicIP': True,
                    'EngineID': 1,
                    'ObjectSubType': 'SNMP',
                    'SNMPVersion': 2,
                    'Community': community
                }
            
                print("Adding node {}... ".format(props['DNS']), end="")
                results = swis.create('Orion.Nodes', **props)
                print("DONE!")
            
                # extract the nodeID from the result
                nodeid = re.search(r'(\d+)$', results).group(0)
            
                pollers_enabled = {
                    'N.Status.ICMP.Native': True,
                    'N.Status.SNMP.Native': False,
                    'N.ResponseTime.ICMP.Native': True,
                    'N.ResponseTime.SNMP.Native': False,
                    'N.Details.SNMP.Generic': True,
                    'N.Uptime.SNMP.Generic': True,
                    'N.Cpu.SNMP.HrProcessorLoad': True,
                    'N.Memory.SNMP.NetSnmpReal': True,
                    'N.AssetInventory.Snmp.Generic': True,
                    'N.Topology_Layer3.SNMP.ipNetToMedia': False,
                    'N.Routing.SNMP.Ipv4CidrRoutingTable': False
                }
            
                pollers = []
                for k in pollers_enabled:
                    pollers.append(
                        {
                            'PollerType': k,
                            'NetObject': 'N:' + nodeid,
                            'NetObjectType': 'N',
                            'NetObjectID': nodeid,
                            'Enabled': pollers_enabled[k]
                        }
                    )
            
                for poller in pollers:
                    print("  Adding poller type: {} with status {}... ".format(poller['PollerType'], poller['Enabled']), end="")
                    response = swis.create('Orion.Pollers', **poller)
                    print("DONE!")
            
            
            requests.packages.urllib3.disable_warnings()
            
            
            if __name__ == '__main__':
                main()
            1 of 1 people found this helpful
              • Re: Help: How to enable Dynamic IP Address (DHCP or BOOTP) and assign a DNS Hostname through API
                kteng

                Thanks. And I have another question is how to change the "Web Browse Template". The default value is "http://{{ HrefIPAddress }}". I have some devices using https with non-default port.

                  • Re: Help: How to enable Dynamic IP Address (DHCP or BOOTP) and assign a DNS Hostname through API
                    dan jagnow

                    From SWQL Studio you can view the Web Browse Template settings as follows:

                     

                    SELECT NodeID, SettingName, SettingValue, NodeSettingID
                    FROM Orion.NodeSettings
                    WHERE SettingName = 'Core.WebBrowseTemplate'

                     

                    To add this setting when you add the node, you can add a little code like this after you've retrieved the nodeid.

                     

                        # set up property bag for the new node settings
                        custom_url = "https://www.myserver.com:443"
                        
                        settingsProps = {
                            'NodeID': nodeid,
                            'SettingName': 'Core.WebBrowseTemplate',
                            'SettingValue': custom_url
                        }
                      
                        print("Adding node settings for web browse template {}... ".format(settingsProps['SettingValue']), end="")
                        results = swis.create('Orion.NodeSettings', **settingsProps)
                        print("DONE!")
                  • Re: Help: How to enable Dynamic IP Address (DHCP or BOOTP) and assign a DNS Hostname through API
                    dan jagnow

                    I have a correction to my earlier response.  The discussion at Re: Adding node with DNS instead of IP  indicates that an initial IP address should be provided even when setting DynamicIP to True.  An updated example follows, which imports socket and calls socket.gethostbyname to get the current IP address of the node you want to add.

                     

                    from __future__ import print_function
                    import re
                    import requests
                    import socket
                    from orionsdk import SwisClient
                    
                    
                    def main():
                        npm_server = 'localhost'
                        username = 'admin'
                        password = ''
                    
                        swis = SwisClient(npm_server, username, password)
                        print("Add an SNMP v2c node:")
                    
                        # fill these in for the node you want to add!
                        dns_name = 'myserver.mydomain.local'
                        ip_address = socket.gethostbyname(dns_name)
                        community = 'public'
                    
                        # set up property bag for the new node
                        props = {
                            'IPAddress': ip_address,
                            'DNS': dns_name,
                            'DynamicIP': True,
                            'EngineID': 1,
                            'ObjectSubType': 'SNMP',
                            'SNMPVersion': 2,
                            'Community': community
                        }
                      
                        print("Adding node {}... ".format(props['DNS']), end="")
                        results = swis.create('Orion.Nodes', **props)
                        print("DONE!")
                    
                    
                        # extract the nodeID from the result
                        nodeid = re.search(r'(\d+)$', results).group(0)
                    
                        pollers_enabled = {
                            'N.Status.ICMP.Native': True,
                            'N.Status.SNMP.Native': False,
                            'N.ResponseTime.ICMP.Native': True,
                            'N.ResponseTime.SNMP.Native': False,
                            'N.Details.SNMP.Generic': True,
                            'N.Uptime.SNMP.Generic': True,
                            'N.Cpu.SNMP.HrProcessorLoad': True,
                            'N.Memory.SNMP.NetSnmpReal': True,
                            'N.AssetInventory.Snmp.Generic': True,
                            'N.Topology_Layer3.SNMP.ipNetToMedia': False,
                            'N.Routing.SNMP.Ipv4CidrRoutingTable': False
                        }
                    
                        pollers = []
                        for k in pollers_enabled:
                            pollers.append(
                                {
                                    'PollerType': k,
                                    'NetObject': 'N:' + nodeid,
                                    'NetObjectType': 'N',
                                    'NetObjectID': nodeid,
                                    'Enabled': pollers_enabled[k]
                                }
                            )
                    
                        for poller in pollers:
                            print("  Adding poller type: {} with status {}... ".format(poller['PollerType'], poller['Enabled']), end="")
                            response = swis.create('Orion.Pollers', **poller)
                            print("DONE!")
                    
                    
                    requests.packages.urllib3.disable_warnings()
                    
                    
                    if __name__ == '__main__':
                        main()