5 Replies Latest reply on Dec 30, 2016 9:31 AM by peacekeeper

    NPM World Map updates via API

    peacekeeper

      I wrote a python script with a function, that uses the Solarwinds API,  to grab  latitude and longitude for each of our sites from a database and  update two Solarwinds custom properties (Called Latitude and Longitude). This works great.

       

      I then set the World Map to do automatic geolocation and after about 90 minutes I still had no markers on the map. I waited a while longer and still no markers. So after some research I found that the World Map us two properties called Latitude (World Map) and Longitude (World Map), not my custom Latitude and Longitude properties.

       

      Can you update the Latitude (World Map) and Longitude (World Map) via the API? I looked at the API documentation and source code on github, however I have not figured out a way to do it yet.

       

      My current  update line looks like this:  swis.update(uri + '/CustomProperties', Latitude = var2)

       

      Any help is appreciated. Thank you,

      -Matt

        • Re: NPM World Map updates via API
          peacekeeper

          I may have asked this in the wrong forum. Moving post to Orion SDK .

          • Re: NPM World Map updates via API
            derhally

            The World Map coordinates are stored in the Orion.WorldMap.Point entity.  You can use the Orion SDK to add entries to that.

             

            The Instance property should reflect the type of object you are adding.  e.g. for a node it would be "Orion.Nodes"

            The InstanceId is the value of the key of that object.  e.g. the value of NodeID for nodes.

            1 of 1 people found this helpful
              • Re: NPM World Map updates via API
                peacekeeper

                Thank you for the reply. This is very helpful.

                 

                URI: swis://[SERVER HERE]/Orion/Orion.Nodes/NodeID=343

                 

                So after reading your explanation the update should be something like this (?):

                [SERVER HERE]/Orion/Orion.WorldMap.Point/Instance="Orion.Nodes",InstanceID=343

                 

                Sorry if this seems elementary, I am very new to Solarwinds and only have light Python experience.

                 

                Thank you again,

                -Matt

                  • Re: NPM World Map updates via API
                    derhally

                    I apologize but I'm not familiar with the python interface.  If an entry didn't already exist you would have to call Create on

                     

                    e.g.

                     

                    props = {
                            'Instance': 'Orion.Nodes',
                            'InstanceId': 343,
                            'Latitude': 38.889963929167,
                            'Longitude': -77.027206420898
                        }
                    
                    
                        results = swis.create('Orion.WorldMap.Point', **props)
                    

                     

                     

                    If a record exists, then call SWIS update on the uri of the entry in Orion.WorldMap.Points.

                     

                    You can do that by doing a "SELECT Uri from Orion.WorldMap.Points Where Points.Node.NodeID = 343"

                     

                    So it may look like

                     

                     results = swis.query(
                            "SELECT Uri from Orion.WorldMap.Points Where Points.Node.NodeID = @id",
                            id=343)  # set valid NodeID!
                    
                     uri = results['results'][0]['Uri']
                    
                    
                     props = {
                        'Latitude': 38.889963929167,
                        'Longitude': -77.027206420898
                    }
                    swis.Update(uri, **props)
                    
                    1 of 1 people found this helpful
                • Re: NPM World Map updates via API
                  peacekeeper

                  Thank you derhally for the help.

                   

                  I spent some time working on a script to update the World Map Latitude and Longitude and came up with the solution below.

                   

                  First some caveats:

                  1.  I am very new to Python, so there maybe a better way of doing this. I did what I know how to do and will tweak as I learn more.

                  2. I did not include other parts of my script. No included are the MySQL connections and queries where I get our sites information.

                  3. The function has address, city, and state; but I am not using those (yet). When the script is complete it will be updating Solarwinds custom properties at the same time.

                  4. Use this at your own risk. I am providing this to the community because they have helped me. Please look over the code and make sure it fits your environment before using any part of it.

                   

                  Script:

                  def updateSite (node, longitude, latitude, address, city, state):
                     requests.packages.urllib3.disable_warnings()
                     swis = SwisClient(npm_server, username, password)
                     node_ip = node
                  
                  
                      results = swis.query(
                         "SELECT Uri,NodeID FROM Orion.Nodes WHERE IPAddress=@IP",IP=node_ip)
                      try:
                         uri = results['results'][0]['Uri']
                         node_id = results['results'][0]['NodeID']
                      except IndexError:
                         uri = 'null'
                  
                  
                      if uri is not 'null':
                         print "[SYNC NODE] IP:", node_ip, "ID:", node_id
                         results = swis.query(
                            "SELECT Uri from Orion.WorldMap.Point WHERE InstanceID=@NodeID", NodeID=node_id)
                         try:
                            map_uri = results['results'][0]['Uri']
                         except IndexError:
                            map_uri = 'null'
                  
                  
                         if map_uri is 'null':
                            print "\t Adding Node to Map - Lat:", latitude, "Long:", longitude
                            props = {
                               'Instance': 'Orion.Nodes',
                               'InstanceId': node_id,
                               'Latitude': latitude,
                               'Longitude': longitude
                            }
                            results = swis.create('Orion.WorldMap.Point', **props)
                  
                  
                         if map_uri is not 'null':
                            print "\t Updating Node Map Location - Lat:", latitude, "Long:", longitude
                            props = {
                               'Instance': 'Orion.Nodes',
                               'InstanceId': node_id,
                               'Latitude': latitude,
                               'Longitude': longitude
                            }
                            results = swis.update('Orion.WorldMap.Point', **props)
                  

                   

                  Explanation:

                  This script first checks if the Node excites. I do this by looking for and IP Address that I queried from an external MySQL database.

                  If the Node exists it will check for the URI and NodeID.

                  It then uses the NodeID to check Orion.WorldMap.Point for the Map URI.

                  If the Map URI is NULL it adds the node with latitude and longitude to to Orion.WorldMap.Point.

                  If the MAP URI is not NULL if updates the Orion.WorldMap.Point Node's latitude and longitude. (We have nodes that "relocate" so this was needed)

                   

                  I hope this helps someone in Solarwinds Land. If you have any suggestions and question please feel free to ask. I am still new to Solarwinds and Python, but I will try to help.

                   

                  -Matt