These examples assume the use of the UNIX/Linux Authoring Library example MP. For more information on creating and building the MP authoring project, see Getting Started.
Note: contents located between pairs of ## characters should be customized for your environment. This includes ID and property values. Be sure to remove the ## characters before building the MP.
<
ManagementPackFragment
SchemaVersion
=
"2.0"
xmlns:xsd
"http://www.w3.org/2001/XMLSchema"
>
Monitoring
Monitors
UnitMonitor
ID
"##MyMP.ShellScript.LessThan.ThreeState.Monitor##"
Accessibility
"Internal"
Enabled
"true"
Target
"##MyMP.MyCustomRole##"
ParentMonitorID
"Health!System.Health.AvailabilityState"
Remotable
Priority
"Normal"
TypeID
"UnixAuth!Unix.Authoring.ShellScript.LessThanThreshold.ThreeState.MonitorType"
ConfirmDelivery
"false"
Category
>AvailabilityHealth</
AlertSettings
AlertMessage
"##MyMP.ShellScript.LessThan.ThreeState.Monitor.AlertMessage##"
AlertOnState
>##Warning##</
AutoResolve
>true</
AlertPriority
>Normal</
AlertSeverity
>##MatchMonitorHealth##</
AlertParameters
AlertParameter1
##$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$##
</
AlertParameter2
>##$Data/Context///*[local-name()="StdOut"]$##</
OperationalStates
OperationalState
"StatusOK"
MonitorTypeStateID
HealthState
"Success"
/>
"StatusWarning"
"Warning"
"StatusError"
"Error"
Configuration
Interval
>300</
TargetSystem
$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$
ShellScript
##
<![CDATA[
echo $1
]]>
ScriptArguments
>75</
Timeout
>##60##</
UserName
>##$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/UserName$##</
Password
>##$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/Password$##</
FilterExpression
RegExExpression
ValueExpression
XPathQuery
>//*[local-name()="StdOut"]</
Operator
>MatchesRegularExpression</
Pattern
>^[-+]?\d*[0-9]*(\.[0-9]+)?[Ee]?[-+]?[0-9]*$</
WarningThreshold
>##100##</
ErrorThreshold
>##50##</
Presentation
StringResources
StringResource
LanguagePacks
LanguagePack
"ENU"
IsDefault
DisplayStrings
DisplayString
ElementID
Name
>##My shell script monitor##</
Description
>##Monitors the output of a shell command and generates an alert if the output is less than the threshold. ##</
>##Shell script output is too low##</
>##The output of the shell script on the host: {0} is lower than the threshold. The output is: {1}##</
SubElementID
>StatusOK</
>StatusWarning</
>StatusError</
When running a shell command or shell script, the Operations Manager UNIX/Linux agent returns StdOut, StdErr, and ReturnCode values as a single DataItem. If a shell command or script returns multiple values in its output (StdOut), and these values need to be handled as distinct DataItems, a PowerShell script can be used (in the form of a PropertyBag probe) to parse the shell command/script output, perform splitting or filtering operations, and create Property Bags. The Property Bags can then be uniquely evaluated for separate monitors or rules.
This example demonstrates the use of a Shell Script which returns multiple values in StdOut, and the use of a PowerShell Property Bag probe to parse the values and create Property Bags. The Property Bag DataItems are evaluated with numeric thresholds to determine the monitor state.
For additional information about the UnitMonitorType used in this example, as well as other shell command and shell script monitor types that use PowerShell parsing for multiple values, review the documentation of the following Monitor Types in the Unix.Authoring.Library Module Reference:
For more information about quotes and special characters in shell commands, see the appendix section - Commands and Scripts: Quotes and Special Characters Note: contents located between pairs of ## characters should be customized for your environment. This includes ID and property values. Be sure to remove the ## characters before building the MP.
"##MyMP.ShellScript.PropertyBag.GreaterThan.ThreeState.Monitor##"
"UnixAuth!Unix.Authoring.ShellScript.PropertyBag.GreaterThanThreshold.ThreeState.MonitorType"
"##MyMP.ShellScript.PropertyBag.GreaterThan.ThreeState.Monitor.AlertMessage##"
>##$Data/Context/DataItem/Property[@Name='CounterValue']$ ##</
echo "MyCounterA:$1,MyCounterB:$2"
>##88 77##</
>60</
PSScriptName
>##MyPSScript.ps1##</
PSScriptBody
param([string]$StdOut,[string]$StdErr,[string]$ReturnCode)
$api = New-Object -comObject 'MOM.ScriptAPI'
[array]$arCounters=$StdOut.Split(",")
ForEach($counter in $ArCounters){
$sName=$counter.Split(":")[0]
$sValue=$counter.split(":")[1].trim()
if ($sValue -ne $null){
$bag = $api.CreatePropertyBag()
$bag.AddValue("CounterName",$sName)
$bag.AddValue("CounterValue",$sValue)
$bag
}
>##Property[@Name='CounterName'] ##</
>##MatchesRegularExpression##</
>##MyCounterA##</
ValueXPath
>##Property[@Name='CounterValue'] ##</
>##My shell script monitor - MyCounterA##</
>##Monitors the output of a shell command and generates an alert if MyCounterA is greater than the threshold.##</
>##MyCounterA value is too high##</
>##The value of MyCounterA on the host: {0} is higher than the threshold. The value is: {1}##</