Jaa


OpsMgr: Displaying Knowledge Information of Alerts Contextually with a Text Display Widget

This post demonstrates how the PowerShell Text Display Widget Template (Download Here), can be used to create a custom widget in the OpsMgr 2012 Operations Console, to contextually display the knowledge information of an alert (generated from a rule or monitor) selected from an alert widget.

Here is an example of a PowerShell Text Display Widget being used to contextually display a small part of the knowledge information of a “Logical Disk Fragmentation Level is high” alert selected in the alert widget.

image

To create an instance of the example above using a custom PowerShell text display widget, first create a dashboard layout with 2 cells, Click to add widget on a cell, then select the Sample PowerShell Text Display Widget template located under the "All Templates/WeiOutThere Text Display" folder , go through the UI pages of the template and enter the required information.

image

The sample PowerShell script used in the PowerShell Script page of the widget is as follows:

A big shout out to my colleague Stefan Stranger for sharing his expertise by providing a very efficient method to extract the actual text from a string wrapped with MAML sections (fonts in Italics).

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

Param($globalSelectedItems)

$dataObject = $ScriptContext.CreateInstance("xsd://TextDisplayTemplate!Widget/ContextualText")
$dataObject["Id"] = "ObjectID"

foreach ($globalSelectedItem in $globalSelectedItems)

{
#Get The Name of the selected object

  $selectedObjectId = $globalSelectedItem["Id"]
}

$identifyalert = get-scomalert -id $selectedObjectId

if($identifyalert.IsMonitorAlert -eq $True)  
{

#If the alert is generated by a monitor, get knowledge information in MAML format
#Use the “getknowledgearticle()” function

  $monitor = get-scommonitor -id $identifyalert.MonitoringRuleId
$content = $monitor.getknowledgearticle("ENU")

#Extract only the text from the MAML output

[xml]$maml = "<logroot>$($content.mamlcontent)</logroot>"
  $kb = ((($maml.logroot.section) | select -ExpandProperty para) -join "`n")
}
else
{
#If the alert is generated by a rule, get knowledge information in MAML format
#Use the “getknowledgearticle()” function

  $monitor = get-scomrule -id $identifyalert.MonitoringRuleId
  $content = $monitor.getknowledgearticle("ENU")

#Extract only the text from the maml output
  
[xml]$maml = "<logroot>$($content.mamlcontent)</logroot>"
  $kb = ((($maml.logroot.section) | select -ExpandProperty para) -join "`n")
}

#Assign a string to the ReturnString property of the data object to display on the Text Display Widget

$dataObject["ReturnString"] = $kb

$ScriptContext.ReturnCollection.Add($dataObject)

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

   

On the “Refresh Interval” page, enter a numerical value for the refresh interval of the widget (in seconds), then click the Finish button to create the custom PowerShell Text Display widget.

Here is another example to contextually display the knowledge information of an “Ops DB Free Space Low” alert selected in the alert widget.

image

For more information, about the Sample PowerShell Text Display Widget Template, refer to:
https://blogs.msdn.com/b/wei_out_there_with_system_center/archive/2015/11/28/opsmgr-sample-powershell-text-display-widget-template.aspx

     

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.