OpsMgr: Extending a Dashboard with the PowerShell Web Browser Widget & Using Static Maps

The PowerShell Web Browser Widget was among the new widgets included in Update Rollup 2 for System Center 2012 R2 Operations Manager (UR2) back in April 2014. The latest Update Rollup available when this article was written is Update Rollup 4 (UR4), released in late October 2014.

The PowerShell Web Browser Widget can be used to display the output of a web page requested by a Windows PowerShell script, a simple web page requiring no parameters, a Get request using parameters with properties of the selected object, a Post request passing data to a web page or a custom web page written to interact with the Operations Console.
For more information on the PowerShell Web Browser Widget and other script based widgets, please refer to the Authoring Guide.

Here is a cool way of how my buddy Dan Kamo extended his custom dashboard by displaying a static map with markers representing site server locations and health states as an output of the URL requested by the PowerShell script within the PowerShell Web Browser Widget.

The Google Static Maps API allows you to embed a static maps image on your web page, where the Google Static Map service creates your map based on URL parameters sent through a standard HTTP request and returns the map as an image you can display on your web page.

Here is an example of how the PowerShell script that makes a call to the Google static map service can be added into the PowerShell Web Browser Widget:

#//////////////////////////////////////////////////////////////////////////////////////////////////////

$dataObject = $ScriptContext.CreateInstance("xsd://Microsoft.SystemCenter.Visualization.Component.Library!Microsoft.SystemCenter.Visualization.Component.Library.WebBrowser.Schema/Request")

        #The initial URL for the static map service:
$datalocation = “https://maps.googleapis.com/maps/api/staticmap?center=Tasmania&zoom=4&size=400x400&scale=2&markers=size:small%7Ccolor:green

$windowscomputer = get-scomclass -Name "Microsoft.Windows.Computer"
$siteservers = Get-SCOMClassInstance -class $windowscomputer | ? {$_.DisplayName -ilike "SCOM*"}

foreach ($server in $siteservers) {
$InMM = $server.InMaintenanceMode

#Mapping servers to location:
if($server.DisplayName -eq "SCOMMS1.SCOM2012.lab")
{$coordinates = "AU-SA-Adelaide"}
elseif($server.DisplayName -eq "SCOMDC.SCOM2012.lab")
{$coordinates = "AU-NSW-Richmond"}
elseif($server.DisplayName -eq "SCOMDW.SCOM2012.lab")
{$coordinates = "AU-NSW-Newcastle"}
elseif($server.DisplayName -eq "SCOMDB.SCOM2012.lab")
{$coordinates = "AU-VIC-Clayton"}
else
{$coordinates = "AU-VIC-Bendigo"}

#If server is NOT in maintenance mode, use: a Red marker of a larger size:
if ($InMM -eq $True) {
$urlstring = $urlstring + "%7C"+$coordinates     }
elseif($InMM -eq $False) {
$redurlstring = $redurlstring + "&markers=color:red%7C"+$coordinates }
else {
$blueurlstring = $blueurlstring + "&markers=color:blue%7C"+$coordinates   }

} #End For Loop

#Append the parameters to the URL string for each server location and health state:
$datalocation = $datalocation+$urlstring+$redurlstring+$blueurlstring

#Return full string in the ScriptContext Collection:
$dataObject["BaseUrl"]=$datalocation

$ScriptContext.ReturnCollection.Add($dataObject)

#//////////////////////////////////////////////////////////////////////////////////////////////////////

Create a dashboard layout, select the PowerShell Web Browser widget and add the above PowerShell script as follows:

image

image

 

Try setting on of the servers included in the script to maintenance mode:

image

The output of the PowerShell Web Browser Widget should look like this (including a different marker for the single server that was set to Maintenance Mode):

image

Thank you for your support !

Disclaimer:
All information on this blog is provided on an as-is basis with no warranties and for informational purposes only. Use at your own risk. The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of my employer.