從今天開始,將會分析講解一個完整的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>,直譯的話有探索的意思。這裏是服務器的篩選部分。
<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>
<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>
<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>
<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中將完成兩個關鍵事宜:
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中將完成兩個關鍵事宜: