SCOM 2007 Management Pack 教程(4)

從今天開始,將會分析講解一個完整的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之後,可以再對象中發現,你之前所定義的類型。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章