SCOM 2012: UNIX/Linux Authoring with Shell Commands
Monitoring with Shell Commands
This example assumes the use of the UNIX/Linux Authoring Library example MP. For more information on creating and building the MP authoring project, see Getting Started*.
*This example demonstrates monitoring with a Shell Command that is run on the UNIX/Linux agent - in this case, the command is: echo 'Warning'. The output of the shell command (StdOut), is evaluated with multiple Regular Expressions to determine if the monitor is in a Healthy, Warning or Error State.
For additional information about the UnitMonitorType used in this example, as well as other shell command monitor types, review the documentation of the following Monitor Types in the Unix.Authoring.Library Module Reference:
- UNIX/Linux Shell Command Matches Expression Two-State Monitor Type
- UNIX/Linux Shell Command Matches Expression Three-State Monitor Type
- UNIX/Linux Shell Command Less Than Threshold Three-State Monitor Type
- UNIX/Linux Shell Command Greater Than Threshold Three-State Monitor Type
For more information about quotes and special characters in shell commands, see Commands and Script: 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.
<ManagementPackFragment SchemaVersion="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Monitoring>
<Monitors>
<UnitMonitor ID="##MyMP.ShellCommand.Expression.ThreeState.Monitor##" Accessibility="Internal" Enabled="true" Target="##MyMP.MyCustomRole##" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="true" Priority="Normal" TypeID="UnixAuth!Unix.Authoring.ShellCommand.MatchesRegExp.ThreeState.MonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="##MyMP.ShellCommand.Expression.ThreeState.Monitor.AlertMessage##">
<AlertOnState>##Warning##</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>##MatchMonitorHealth##</AlertSeverity>
<AlertParameters>
<AlertParameter1>
##$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$##
</AlertParameter1>
<AlertParameter2>##$Data/Context///*[local-name()="StdOut"]$##</AlertParameter2>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="StatusOK" MonitorTypeStateID="StatusOK" HealthState="Success" />
<OperationalState ID="StatusWarning" MonitorTypeStateID="StatusWarning" HealthState="Warning" />
<OperationalState ID="StatusError" MonitorTypeStateID="StatusError" HealthState="Error" />
</OperationalStates>
<Configuration>
<Interval>300</Interval>
<TargetSystem>
$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$
</TargetSystem>
<ShellCommand>##echo 'Warning'##</ShellCommand>
<Timeout>60</Timeout>
<UserName>$RunAs[Name="##Unix!Microsoft.Unix.ActionAccount##"]/UserName$</UserName>
<Password>$RunAs[Name="##Unix!Microsoft.Unix.ActionAccount##"]/Password$</Password>
<ErrorRegExp>##^Error##</ErrorRegExp>
<WarningRegExp>##^Warning##</WarningRegExp>
</Configuration>
</UnitMonitor>
</Monitors>
</Monitoring>
<Presentation>
<StringResources>
<StringResource ID="##MyMP.ShellCommand.Expression.ThreeState.Monitor.AlertMessage##" />
</StringResources>
</Presentation>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="true">
<DisplayStrings>
<DisplayString ElementID="MyMP.ShellCommand.Expression.ThreeState.Monitor">
<Name>##My shell command monitor##</Name>
<Description>##Monitors the output of a shell command and generates an alert if the warning or error expressions are matched. ##</Description>
</DisplayString>
<DisplayString ElementID="##MyMP.ShellCommand.Expression.ThreeState.Monitor.AlertMessage##">
<Name>##Shell command output is not OK##</Name>
<Description>##The output of the shell command on the host: {0} is not OK. The output is: {1}##</Description>
</DisplayString>
<DisplayString ElementID="##MyMP.ShellCommand.Expression.ThreeState.Monitor##" SubElementID="StatusOK">
<Name>StatusOK</Name>
<Description>StatusOK</Description>
</DisplayString>
<DisplayString ElementID="##MyMP.ShellCommand.Expression.ThreeState.Monitor##" SubElementID="StatusWarning">
<Name>StatusWarning</Name>
<Description>StatusWarning</Description>
</DisplayString>
<DisplayString ElementID="##MyMP.ShellCommand.Expression.ThreeState.Monitor##" SubElementID="StatusError">
<Name>StatusError</Name>
<Description>StatusError</Description>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPackFragment>