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.

Automatically Update World Map Points Based On Custom Property Value

< BACK TO TO THE MAGIC OF SQL SCRIPTS SERIES LIST

Challenge:

  • At present moment (NPM v11) it is not possible to automatically handle nodes placement on the map
  • In the future (NPM v12) it will be possible to do so by utilising "Location" field on the SNMP devices. This will still leave few limitations:
    • first of all not all nodes are SNMP
    • second, SNMP field is not controlled by monitoring team - hence - very difficult to ensure consistency across the board

Solution

(1)

Create node custom property field "n_site_id" and make it drop down, with more or less meaningful names (better IDs) for your sites. You may already have one - in this case simply fine-tune SQL script below for it to work

04.PNG

(2)

Create new table in auxiliary database called "Sites"

05.PNG

Note:

LocationID field will not be used in this solution, but we will need it in other solutions. So, if you have intentions of following my future SQL magic series - please create this column as well

(3)

Populate this table with information about your sites, including coordinates, which you can extract from Google Map URL

06.PNG

03.PNG

(4)

Now, here is were Magic begins... below is a SQL script which you can use to populate your World Map Points.

MERGE SolarWinds.dbo.WorldMapPoints AS target

USING

  ( SELECT

       n.NodeID

      ,n.EntityType

      ,s.Latitude

      ,s.Longitude

      ,s.[Description]

    FROM SolarWinds.dbo.Nodes n

      LEFT JOIN SolarWindsAux.dbo.Sites s ON s.SiteID=n.n_site_id

   LEFT JOIN SolarWinds.dbo.WorldMapPoints wm ON n.NodeID=wm.InstanceID

  ) AS source (NodeID, EntityType, Latitude, Longitude, [Description]) ON (target.InstanceID = source.NodeID)

-- Delete from MAP if node no longer exist in Nodes table

WHEN NOT MATCHED BY source

THEN DELETE

-- Delete from MAP if Latitude/Longitude values were not specified

WHEN MATCHED

  AND (source.Latitude IS NULL or source.Longitude IS NULL)

THEN DELETE

-- Update if Latitude/Longitude were changed

WHEN MATCHED

  AND source.Latitude <> target.Latitude

  OR (source.Latitude IS NOT NULL AND target.Latitude IS NULL)

  OR source.Longitude <> target.Longitude

  OR (source.Longitude IS NOT NULL AND target.Longitude IS NULL)

  OR source.[Description] <> target.StreetAddress

  OR (source.[Description] IS NOT NULL AND target.StreetAddress IS NULL)

THEN

UPDATE SET Latitude = source.Latitude, Longitude = source.Longitude, StreetAddress = source.[Description]

-- Synch new node

WHEN NOT MATCHED BY target

  AND source.EntityType IN ('Orion.Nodes','Orion.VIM.Hosts','Orion.VIM.VCenters')

    --Ideally, everything from NODES should be included, but I don't know if all objects from Nodes can be displayed on the map.

    --So far, I know that this values will definitely work (they will be replaced with 'Orion.Nodes' values in World Map table)

  AND source.Latitude IS NOT NULL

  AND source.Longitude IS NOT NULL

THEN

INSERT (Instance, InstanceID, Latitude, Longitude, StreetAddress)

VALUES ('Orion.Nodes', source.NodeID, source.Latitude, source.Longitude, source.[Description])

;

Remember to change database name

(5)

The last thing which is left - schedule the above script to fire automatically, on schedule. Script is very resource-friendly - you can run it as often as you wish. How often - this will depend on your environment. Main questions to answer would be - how often location changes are being made by your team across all nodes and how quickly you want them to be populated on the map. In my case I decided to stick with "every 1 hour"

Please refer to the below step-by-step guide from MSDN on how to create SQL scheduled job:

Schedule a Job

(6)

... in 1 hour ...

001.PNG

Afterword

Obviously the above solution will fit into scenario, whereby you are managing your nodes locations with custom properties. However, the logic still the same - keep all your locations and coordinates separate and centrally accessible. Then - fiddle with SQL script a little bit to suite your needs and requirements. Feel free to ask any questions about adopting this script in your environment

To Your Success,

Alex Soul

www.pixace.com

  • Hi Guys, in my latest deployment I started to create tables right within SlarWinds database. The main idea for using separate AUX database was to segregate custom setup from what comes out-of-the-box. This way I was pretty confident that my custom tables will not be wiped-out upon the next upgrade. However, in light of the response above I think I will changed my approach from now on. So, from the perspective of what this script does - it doesn't matter where your table sit

  • I would hold off for just a bit. I ran in to a BIG issue and I am not sure what the cause it. My custom table is gone. At this point I do not know if it has anything to do with SolarWinds, or if there was something done to the test server by our database group. I am going to look into it and will keep you all updated.

  • I would hold up, and see my post above.

  • If someone was just to do this, and none of the other "mods" you have done, wouldn't it be possible to just create a lat/lon custom property and run the script off of that? I would think so, but I'm not sure how to edit your script. I don't really know SQL, and adding and updating a table is about all I can do at the moment.

  • It is possible indeed and you are right - there is a bit SQLing involved, but principle is exactly same as in above script - you take a bunch of records > you compare them to another table > you update/insert/delete as required. It is basically sync between two tables, which is being accomplished with MERGE SQL function. My dear friend danbran‌ has shared with me awesome resource recently - here it is: T-SQL Step by Step Course - Mr.Bool Courses Take a look at lesson #37 (funny enough - the last one emoticons_happy.png must be very advanced though... lol) - this is exactly what you see here

    Word of caution: I was also considering an option to keep it all more or less with minimum "mods", but it would look quite clunky and I am actually doing much more with sites records in custom table than just sticking them on the map. Take a look here - there are at least 3 different solutions that are using this Site table for reference of different things and I have bunch more pending to be published soon. So, it definitely comes handy.

    If you are still not convinced - I would recommend to construct your lat/lon custom property drop-down values in such a way so that you have site name/id there as well - for example "Big Ben | 51.500 | -0.124". Use delimiters of your choice. Then, with SQL you will need to separate this into 3 different values - Site, Lat, Lon - and then feed this into Worldmap table. Take a closer look at this custom property now - it is really taking a shape of a table. So, why not use one instead?

    P.S. If you really want it quick without learning a bit of SQL yourself - PM me, I will help you for f(r)ee emoticons_wink.png

  • This is very odd ... can you tell me how did you name it? I have few custom tables (Orion Platform 2014.2.1, SAM 6.1.1, QoE 1.0, NCM 7.3.2, NPM 11.0.1) sitting there with no problems. What is your SW version? Are there any backup/restore jobs in place? SQL jobs?

  • Orion Platform 2015.1.2, NPM 11.5.2, DPA 10.0.0, QoE 2.0, NTA 4.1.1, IVIM 2.1.0, SAM 6.2.2


    As for jobs, I have an help desk ticket out to our database team to see if that is the case.

  • ok, I have seen your post: Custom Tables So, we will track this issue there...

  • You will never guess what the answer is. I found out that you must make sure you are connected to the correct database. I really do feel dumb right now. TGIF.