Even MORE SCOM 2012 R2 Dashboard Fun with Multi-Pin Bing Maps

This post builds on the recent sterling work of Tao Yang, leveraging the System Center 2012 R2 U2 PowerShell Web Browser widget to display a Google Map, centred on address attributes derived via a custom discovery which interrogates a custom key seeded in the Windows Registry. Please check out Tao’s inspiring post here before you proceed, as the following makes NO SENSE without doing that. Mandatory reading people!

I noticed and discussed (well, if you can call exchanging tweets a discussion) some of the limitations and design choices Tao made when putting his initial offering together. The ones I thought that were interesting problems and likely beatable were:

  1. Being welded to Google Maps, as it’s accuracy on matching geographical location to address lookups is higher than the alternative mapping providers
  2. No support for multiple object selection, or put in Google Maps terms, only one pin per map view, which turns out to be the last SCOM object selected

To tackle these two challenges, I needed to do three things:

  1. Get the longitude & latitude co-ordinates Google is using when it renders any given address search, so we can feed these to other mapping services
  2. Work out the URL syntax for dropping multiple pins onto a map in a mapping service
  3. Work out how to construct the PowerShell Microsoft.SystemCenter.Visualization.Component.Library!Microsoft.SystemCenter.Visualization.Component.Library.WebBrowser.Schema/Request request to handle the multiple objects being selected

 

Who needs Geocaching? Geocoding is where it’s at…

The first action was pretty easy. I took to learning how to leverage the Google Geocode API service, which allows you enter a plain English address or location query and it will return, in either JSON or XML (requesters choice), the relevant geographical data. It’s pretty accessible, and XML is so easily parsed via PowerShell that it’s frankly trivial.

Feeding the address attributes from the SCOM discoveries associated with our custom class into Geocode API calls return the XML (captured to variable $XML, in this example) from which we get the attribute we care about, specifically $XML.GeocodeResponse.result.geometry.location.lat & $XML.GeocodeResponse.result.geometry.location.lng

One Map to Rule Them All (once we’ve stolen Google’s co-ordinates)

The second action was interesting from a research point of view. Some observations:

  • Google Maps does not support insertion of multiple pins onto a map via URL construction
  • Google Static maps does support multiple pins, but the sizes are limited and fixed. It also requires an API key, which may expose you to cost, depending on your use-case
  • Bing maps supports multiple pins via URL construction and these pins can be assigned properties (A tag, name & description), all in band!
  • Bing ‘Static Maps’ AKA Virtual Earth supports labelling of pins & colouring of pins. However, it also requires an access API, looks like puke (frankly) and only puts out fixed size maps, albeit that the user can define.

So, given these experiences, I decided to work with straight Bing Maps. Although it has the same ‘task area open by default’ issue that Google Maps has, it has enough other features available to make it worth my time. The Bing Maps Map URL structure is also pretty well documented, which reduces our ‘time to value’

Finally, The (refried) SCOM Bit!

The final challenge was in working out how to adjust Tao’s PowerShell Web Browser script to build a multiple pin map, on Bing Maps rather than Google Maps.

Thanks to Tao’s clean initial work, the code pretty much speaks for itself, but I will talk about it, just in case you’re interested…

 

The significant technical changes are:

  • The base URL is Bing Maps
  • The constructed parameters use Bing Maps Syntax
  • Instead of constructing the $parameter variable in the foreach ($globalSelectedItem in $globalSelectedItems) loop, which gets overridden each time leaving the values calculated from the last $globalSelectedItem, we construct a string, which we append to during each loop
  • Each time we loop, we lookup the address of the monitored object against the Google Geocode API and capture the returned longitude and latitude to variable
  • The constructed string is built from properties of the monitored object, the Web Console URL setting of the management group and the Geocode co-ordinates
  • AFTER the foreach ($globalSelectedItem in $globalSelectedItems) loop completes, we instantiate the URLparameter parameters
  • Some logic here – If only one pin is applied to the map, we drop the trailing tilde from our URL string, as isn’t needed. We also create a new parameter which sets the zoom level to 15 (street view, rather than satellite level). We count the pins by querying for substrings in our constructed string
  • We then pass all populated parameters into the parameter collection, which is then passed into the data object

They do say seeing is believing, so if you want to see it in action, just replace the Map widget PowerShell script block section with my fork of Tao’s code when following his blog post (you read that, yeah?), and you’ll get the following benefits:

  1. Bing Maps over Google Maps, if you’re a Microsoft purist, or have to be for a living
  2. Ability to select multiple SCOM objects, resulting in an auto-scaled multi-pin map
  3. Single object selection results in a sensible zoom level on the map view
  4. Pins are labelled, with address in the description
  5. The pins hyperlink will take you to the SCOM Web Console Health Explorer for the object concerned

One enhancement I do like the idea of – If one was to expand the custom registry with, say, a URL for an internal Wiki or CMDB, you could have the hyperlink on Bing Maps take you there. Linking it to the Health Explorer is a little redundant, as being in a SCOM console you have other ways of getting there. Surfacing your other internal (non-SCOM) data would be more valuable (but less universally applicable). Also wondering if I might make a ‘static map’ version to get rid of the ‘task area of death’ issue for non-interactive use cases, such as NOCs or the like.

Please note – I’m not as kind as Tao, nor do I want to steer well deserved traffic away from his site, so I wont be uploading a management pack, sealed or otherwise, with my revisions contain within. Please download them from his post, and retrofit my modification. It’ll be fun, trust me!

Here’s a video the dashboard in action, so you can decide if the ten minutes it will take you to implement is going to be time well invested:

SCOM 2012 PowerShell Web Widget Dashboard calling Bing Maps & Google Geocode

 

*** Update ***

Tao spotted a bug in my code, where if the Google Geocode API returned an array of results/address matches, bad things happened. We’ve put a catch in there for that now! Thanks again Tao!

Leave a Reply