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 the use of a “shell command” to discover a custom Computer Role for monitored UNIX/Linux computers. The output (StdOut) of the command is evaluated with a Regular Expression, and if the expression is matched, the Role is discovered. The example includes definition of the class types for the role and a computer group, as well as discovery of the role and computer group. The example shell command: ls /opt/myapp |wc –l will return the number 1 if the directory “/opt/myapp” exists on the UNIX/Linux computer. For additional information about “Discovery” data sources defined in the Unix.Authoring.Library, review the documentation of the following data sources in the Unix.Authoring.Library Module Reference:
Note: contents located between pairs of ## characters should be customized for your environment. This includes ID and string values. Be sure to remove the ## characters before building the MP.
<
ManagementPackFragment
SchemaVersion
=
"2.0"
xmlns:xsd
"http://www.w3.org/2001/XMLSchema"
>
TypeDefinitions
EntityTypes
ClassTypes
<!-- Class definition for a UNIX/Linux Computer Role -->
ClassType
ID
"##MyMP.MyCutomRole##"
Abstract
"false"
Accessibility
"Public"
Hosted
"true"
Singleton
Base
"Unix!Microsoft.Unix.ComputerRole"
Property
"RoleName"
Type
"string"
Key
/>
</
<!-- Class definition for a Computer Group -->
"##MyMP.MyCustomRole.Group##"
"SC!Microsoft.SystemCenter.ComputerGroup"
Extension
Monitoring
Discoveries
<!-- Discovery to discover instances of a Computer Role on UNIX/Linux computers, using a Shell Command -->
Discovery
"##MyMP.MyCustomRole.Discovery##"
Target
"Unix!Microsoft.Unix.Computer"
Enabled
ConfirmDelivery
Remotable
Priority
"Normal"
Category
>Discovery</
DiscoveryTypes
DiscoveryClass
TypeID
"##MyMP.MyCustomRole##"
"##MyMP.MyCustomRole###"
PropertyID
DataSource
"DS"
"UnixAuth!Unix.Authoring.TimedShellCommand.Discovery.DataSource"
Interval
>28800</
TargetSystem
>$Target/Property[Type="Unix!Microsoft.Unix.Computer"]/PrincipalName$</
ShellCommand
>##ls /opt/myapp |wc –l##</
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
>##^1##</
ClassId
>$MPElement[Name="##MyMP.MyCustomRole##"]$</
InstanceSettings
Settings
Setting
Name
>$MPElement[Name='##MyMP.MyCustomRole##']/RoleName$</
Value
>##MyApp##</
>$MPElement[Name='Unix!Microsoft.Unix.Computer']/PrincipalName$</
>$MPElement[Name='System!System.Entity']/DisplayName$</
<!-- Discovery to populate a Computer Group with computers hosting the Role-->
"##MyMP.MyCustomRole.Group.Discovery##"
DiscoveryRelationship
"SC!Microsoft.SystemCenter.ComputerGroupContainsComputer"
"GroupPopulationDataSource"
"SC!Microsoft.SystemCenter.GroupPopulator"
RuleId
>$MPElement$</
GroupInstanceId
>$MPElement[Name="##MyMP.MyCustomRole.Group##"]$</
MembershipRules
MembershipRule
MonitoringClass
>$MPElement[Name="Unix!Microsoft.Unix.Computer"]$</
RelationshipClass
$MPElement[Name="SC!Microsoft.SystemCenter.ComputerGroupContainsComputer"]$
Expression
Contains
LanguagePacks
LanguagePack
"ENU"
IsDefault
DisplayStrings
DisplayString
ElementID
>##MyRole##</
Description
></
SubElementID
>Role Name</
>##MyRole Computer Group##</
>##MyRole Discovery##</
>##Populate MyRole Computer Group##</
Ed Price - MSFT edited Revision 2. Comment: Needed the technology context in the title. Added it.
Hi Kris,
Shouldn't <ShellCommand>##ls /opt/myapp |wc –l##</ShellCommand> be <ShellCommand>##ls /opt/myapp -d |wc –l##</ShellCommand> ?
Either way I couldn't get the linux box discovered using this template. No errors showed up in Event log. Is there a better way to track what SCOM is doing when it's trying to work through the discovery?
Rupert,
You are correct, ls -d is appropriate for directories. I can update the example. For troubleshooting discoveries, I'd generally recommend the following:
1) override the interval temporarily to something like 5 minutes
2) Check the eventlog on the Mgmt Servers. An event 10801 would indicate problems in the Instance Settings or ClassId
3) If the eventlog doesn't make it obvious, load up the Workflow Analzer. The tool can be found as described in the debugging section here: social.technet.microsoft.com/.../18075.scom-2012-getting-started-with-the-unixlinux-authoring-library.aspx
The WFA takes some getting used to, but is invaluable in allowing you to see the actual WS-Man data returned, the expression filter results, etc.
It probably wouldn't hurt to check system logs on the agent to make sure you weren't attempting to use sudo when you didn't mean to.