从今天开始,将会分析讲解一个完整的Mp包。
今天主要讲筛选类的定义,和筛选数据的填充。
Code:
============================================
    <TypeDefinitions>
        <EntityTypes>
            <ClassTypes>
                <ClassType ID="Sxt.Services.SxtService" Abstract="false" Accessibility="Internal" Hosted="true" Base="Windows!Microsoft.Windows.LocalApplication">
                     <Property ID="Version" Type="string"/>
                     <Property ID="Path" Type="string"/>
                </ClassType>
      </ClassTypes>
        </EntityTypes>
    </TypeDefinitions>
=============================================
定义类部分相对简单,在< TypeDefinitions>的< ClassTypes>中,我们可以定义自己的数据类。通常它被用来作为筛选数据的容器。
Property是类中的属性,这里我有定义" Version"和" Path"两个字符串属性。
这里要注意的一点事,这里和面向对象程序的类有着类似的概念。如果你不去初始化一个类的话,它将 什么都不做

在< Monitoring>对象中,我们可以找到< Discoveries>,直译的话有探索的意思。这里是服务器的筛选部分。
Code:
============================================
        <Discoveries>
            <Discovery ID="Sxt.Services.SxtService.Discovery" Target="Windows!Microsoft.Windows.Server.Computer" Remotable="false" Enabled="true">
                <Category>Discovery</Category>
                <DiscoveryTypes>
                    <DiscoveryClass TypeID="Sxt.Services..SxtService">
                        <Property PropertyID="Version"/>
                        <Property PropertyID="Path"/>
                        <Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
                    </DiscoveryClass>
                </DiscoveryTypes>
                <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.FilteredRegistryDiscoveryProvider">
                    <ComputerName>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
                    <RegistryAttributeDefinitions>
                        <RegistryAttributeDefinition>
                            <AttributeName>SxtServiceExists</AttributeName>
                            <Path>SOFTWARE\SXT\SxtService</Path>
                            <PathType>0</PathType>
                            <AttributeType>0</AttributeType>
                        </RegistryAttributeDefinition>
                        <RegistryAttributeDefinition>
                            <AttributeName>SxtServiceVersion</AttributeName>
                            <Path>SOFTWARE\SXT\SxtService\Version</Path>
                            <PathType>1</PathType>
                            <AttributeType>1</AttributeType>
                        </RegistryAttributeDefinition>
                        <RegistryAttributeDefinition>
                            <AttributeName>SxtServicePath</AttributeName>
                            <Path>SOFTWARE\SXT\SxtService\Path</Path>
                            <PathType>1</PathType>
                            <AttributeType>1</AttributeType>
                        </RegistryAttributeDefinition>
                    </RegistryAttributeDefinitions>
                    <Frequency>60</Frequency>
                    <ClassId>$MPElement[Name="Sxt.Services.SxtService"]$</ClassId>
                    <InstanceSettings>
                      <Settings>
              <Setting>
                <Name>$MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Name>
                <Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
              </Setting>
              <Setting>
                <Name>$MPElement[Name="System!System.Entity"]/DisplayName$</Name>
                <Value>SxtService ($Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosComputerName$)</Value>
              </Setting>
              <Setting>
                <Name>$MPElement[Name="Sxt.Services.ProPack.SxtService"]/Version$</Name>
                <Value>$Data/Values/SxtServiceVersion$</Value>
              </Setting>
              <Setting>
                <Name>$MPElement[Name="Sxt.Services.ProPack.SxtService"]/Path$</Name>
                <Value>$Data/Values/SxtServicePath$</Value>
              </Setting>
                      </Settings>
                    </InstanceSettings>
                    <Expression>
            <SimpleExpression>
              <ValueExpression>
                <XPathQuery Type="Boolean">Values/SxtServiceExists</XPathQuery>
              </ValueExpression>
              <Operator>Equal</Operator>
              <ValueExpression>
                <Value Type="Boolean">true</Value>
              </ValueExpression>
            </SimpleExpression>
          </Expression>
                    </DataSource>
        </Discovery>
        </Discoveries>
============================================
筛选部分,我使用了官方提供的注册表探针:
Windows!Microsoft.Windows.FilteredRegistryDiscoveryProvider
是我筛选的目标是Windows Server:
Microsoft.Windows.Server.Computer
筛选器ID为:
Sxt.Services.SxtService.Discovery
注意这里已计算机名为筛选的一个关键Key,来实现计算机的一一对应关系:
<ComputerName>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
在DataSource中将完成两个关键事宜:
1、定义筛选内容
2、根据筛选出来的数据,填充进一个类中

初始化类在:
<ClassId>$MPElement[Name="Sxt.Services.SxtService"]$</ClassId>
XPathQuery 中对注册表的路径进行搜索核实。

注意:我这里只是一个简单的实例,在工作环境中,筛选不仅仅是微软的基础类型,也可以是自己的VBS亦或Poweshell的脚本。记。得将数据返回你的数据到DS中
2009-08-21_00316
在完成编译,并导入SCOM之后,可以再对象中发现,你之前所定义的类型。