Hard-coded Management Pack Discoveries

Typically when developing management packs, the following is done more or less in order:

  1. Object model (classes and relationships)
  2. Discoveries (to discover classes and relationships)
  3. Monitoring workflows (to target the discovered classes and relationships)

What if the product you will manage with your MP has some experimental or poorly documented API that you would like to use for monitoring. Let's say you want to experiment with it a bit to determine whether or not it is viable for your purposes. In addition, assume that the discovery for that particular application is somewhat tricky and will take time to fully implement. (If the aforementioned API turns out to be a disappointment, all the discovery work will be wasted.)

So why not just hard code the discovery for testing purposes?

To accomplish this, do the following:

  1. Create a composite data source module type consisting of a System.Discovery.Scheduler data source and a System.Discovery.ClassSnapshotDataMapper condition detection module (both from System.Library MP)
  2. Create a discovery that uses your newly created data source.

The following is an example of a data source module type from step 1:

    1:  <DataSourceModuleType ID="MarcinAtWork.HardcodedDiscovery.One.DemoApplicationDiscovery.DS" Accessibility="Internal" Batching="false">
    2:    <Configuration>
    3:      <xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer" />
    4:      <xsd:element minOccurs="1" name="SyncTime" type="xsd:string" />
    5:      <xsd:element minOccurs="1" name="SomeInteger" type="xsd:integer" />
    6:      <xsd:element minOccurs="1" name="SomeString" type="xsd:string" />
    7:    </Configuration>
    8:    <OverrideableParameters>
    9:      <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
   10:      <OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
   11:      <OverrideableParameter ID="SomeString" Selector="$Config/SomeString$" ParameterType="string" />
   12:    </OverrideableParameters>
   13:    <ModuleImplementation Isolation="Any">
   14:      <Composite>
   15:        <MemberModules>
   16:          <DataSource ID="DS" TypeID="System!System.Discovery.Scheduler">
   17:            <Scheduler>
   18:              <SimpleReccuringSchedule>
   19:                <Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
   20:                <SyncTime>$Config/SyncTime$</SyncTime>
   21:              </SimpleReccuringSchedule>
   22:              <ExcludeDates />
   23:            </Scheduler>
   24:          </DataSource>
   25:          <ConditionDetection ID="CD" TypeID="System!System.Discovery.ClassSnapshotDataMapper">
   26:            <ClassId>$MPElement[Name="MarcinAtWork.HardcodedDiscovery.One.DemoApplication"]$</ClassId>
   27:            <InstanceSettings>
   28:              <Settings>
   29:                <Setting>
   30:                  <Name>$MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Name>
   31:                  <Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
   32:                </Setting>
   33:                <Setting>
   34:                  <Name>$MPElement[Name="MarcinAtWork.HardcodedDiscovery.One.DemoApplication"]/SomeInteger$</Name>
   35:                  <Value>$Config/SomeInteger$</Value>
   36:                </Setting>
   37:                <Setting>
   38:                  <Name>$MPElement[Name="MarcinAtWork.HardcodedDiscovery.One.DemoApplication"]/SomeString$</Name>
   39:                  <Value>$Config/SomeString$</Value>
   40:                </Setting>
   41:              </Settings>
   42:            </InstanceSettings>
   43:          </ConditionDetection>
   44:        </MemberModules>
   45:        <Composition>
   46:          <Node ID="CD">
   47:            <Node ID="DS" />
   48:          </Node>
   49:        </Composition>
   50:      </Composite>
   51:    </ModuleImplementation>
   52:    <OutputType>System!System.Discovery.Data</OutputType>
   53:  </DataSourceModuleType>

The following is an example of the discovery from step 2:

    1:        <Discovery ID="MarcinAtWork.HardcodedDiscovery.One.DemoApplicationDiscovery" Enabled="true" Target="Windows!Microsoft.Windows.Computer" ConfirmDelivery="true" Remotable="true" Priority="Normal">
    2:          <Category>Discovery</Category>
    3:          <DiscoveryTypes>
    4:            <DiscoveryClass TypeID="MarcinAtWork.HardcodedDiscovery.One.DemoApplication">
    5:              <Property TypeID="MarcinAtWork.HardcodedDiscovery.One.DemoApplication" PropertyID="SomeInteger" />
    6:              <Property TypeID="MarcinAtWork.HardcodedDiscovery.One.DemoApplication" PropertyID="SomeString" />
    7:              <Property TypeID="System!System.Entity" PropertyID="DisplayName" />
    8:            </DiscoveryClass>
    9:            <DiscoveryRelationship TypeID="Windows!Microsoft.Windows.ComputerHostsLocalApplication" />
   10:          </DiscoveryTypes>
   11:          <DataSource ID="DS" TypeID="MarcinAtWork.HardcodedDiscovery.One.DemoApplicationDiscovery.DS">
   12:            <IntervalSeconds>120</IntervalSeconds>
   13:            <SyncTime />
   14:            <SomeInteger>42</SomeInteger>
   15:            <SomeString>Some test string goes here.</SomeString>
   16:          </DataSource>
   17:        </Discovery>

The entire management pack containing the above snippets is attached to this post. In addition to the above, I included another discovery that uses a System.Discovery.FilteredClassSnapshotDataMapper (also from System.Library MP) to demonstrate how you can use an expression to determine whether or not a discovery should run on a particular computer.

If you import the attached MP (make sure to change string "NLB-CL7-N2.marcin.com" in the MP to a fully-qualified device name of one computer in your maanagement group), the following should happen:

  • Instances of class MarcinAtWork.HardcodedDiscovery.One.DemoApplication will be discovered on every computer in your management group.
  • One instance of class MarcinAtWork.HardcodedDiscovery.One.DemoApplicationSingle will be discovered on the computer whose FQDN you entered in the MP before importing it.

Good luck!

 

This posting is provided "AS IS" with no warranties.
Use of included tools and reports are subject to the terms specified at
https://www.microsoft.com/info/cpyright.htm

MarcinAtWork.HardcodedDiscovery.One.xml