
Step 3: Create the discovery transform file based on the antivirus best practice configuration requirements and constraints
The final step in authoring an SML model is writing the SML discovery transform file, "SampleBestPractice.xsl". In this example, the Automatic Update configuration and antivirus configuration data that needs to be discovered resides in the Windows registry. For a full listing of sources of information provided with SML, see the Service Modeling Language Technical Reference (http://go.microsoft.com/fwlink/?LinkId=95309).
The exact registry subkeys were defined in the prerequisite step, which we will repeat here.
-
For our scenario, we have generalized the antivirus application as coming from Contoso Corporation. The fictitious antivirus application is configured using a registry subkey: HKLM\SOFTWARE\Contoso\CurrentVersion\Local Scanner\Scan BootSector. From the documentation we know the subkey must be configured to the value of 1 to represent scanning the boot sector.
-
For our scenario, we know from Automatic Updates documentation that the registry subkey HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\AUOptions must be set to a value of 4. This represents configuring Automatic Updates to download updates and install them at a scheduled time.
The SML discovery provider library contains a “Registry Provider.” It provides the functionality to collect data from the registry. For more information about SML discovery providers, see the Service Modeling Language Technical Reference (http://go.microsoft.com/fwlink/?LinkId=95309).
There are many ways to create the SML discovery transform. Here is one way to create the discovery transform for our best practice scenario.
We start by creating the discovery template for the AntiVirusType schema.
|
<xsl:template name="DiscoverAntiVirus">
<tns:AntiVirus>
<tns:ScanBootSector>
<xsl:value-of select="reg:keyValue('HKLM\SOFTWARE\ Contoso\CurrentVersion\Local Scanner\Scan BootSector')" />
</tns:ScanBootSector>
</tns:AntiVirus>
</xsl:template> |
This template has been named DiscoverAntiVirus. The elements AntiVirus and ScanBootSector are provided, so the XML instance to be created conforms to the AntiVirusType schema. The registry discovery provider's keyValue function as part of the select attribute.
string keyValue(string keyName, string valueName)
where
|
Parameter
|
Description
|
| keyName | The key name, in the format [\\server\]hive[\keyPath]. |
| valueName | The name of the value to retrieve. May be empty, in which case the "(Default)" registry value is retrieved. |
| Returns | The registry value as a string or an empty string if the key or the named value is not found. |
This explains the two parameters being passed to the function and that the value returned is a string.
We next create the discovery template for creating an instance of WindowsUpdateType using the same registry discovery provider and calling the keyValue function, as part of the select attribute.
|
<xsl:template name="DiscoverWindowsUpdate">
<tns:WindowsUpdate>
<tns:AutoUpdateStatus>
<xsl:value-of select="reg:keyValue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update', 'AUOptions')" />
</tns:AutoUpdateStatus>
</tns:WindowsUpdate>
</xsl:template> |
We now create the discovery template for MyMachineConfigurationType. The MyMachineConfigurationType is an aggregate of the DiscoverAntiVirus and WindowsUpdateType templates to generate an instance of MyMachineConfigurationType.
|
<xsl:template name="DiscoverMyMachineConfiguration">
<tns:MyMachineConfiguration>
<xsl:call-template name="DiscoverAntiVirus" />
<xsl:call-template name="DiscoverWindowsUpdate" />
</tns:MyMachineConfiguration>
</xsl:template> |
The last step is to create a parent XSLT style sheet to incorporate the above templates and initiate the transformation process. Each style sheet must contain a template that matches "/", which forms the root of the output document. The XSLT-based transformation process starts from this root.
|
<xsl:template match="/">
<xsl:call-template name="DiscoverMyMachineConfiguration" />
</xsl:template> |
We then combine all these portions of the discover transform into a complete file called "SampleBestPractice.xsl".
|
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:reg="http://schemas.microsoft.com/sml/xsl/registry/2007/03"
xmlns:tns="urn:SampleBestPractice">
<xsl:template match="/">
<xsl:call-template name="DiscoverMyMachineConfiguration" />
</xsl:template>
<xsl:template name="DiscoverAntiVirus">
<tns:AntiVirus>
<tns:ScanBootSector>
<xsl:value-of select="reg:keyValue('HKLM\SOFTWARE\ComputerAssociates\eTrustAntivirus\CurrentVersion\Local Scanner', 'Scan BootSector')" />
</tns:ScanBootSector>
</tns:AntiVirus>
</xsl:template>
<xsl:template name="DiscoverWindowsUpdate">
<tns:WindowsUpdate>
<tns:AutoUpdateStatus>
<xsl:value-of select="reg:keyValue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update', 'AUOptions')" />
</tns:AutoUpdateStatus>
</tns:WindowsUpdate>
</xsl:template>
<xsl:template name="DiscoverMyMachineConfiguration">
<tns:MyMachineConfiguration>
<xsl:call-template name="DiscoverAntiVirus" />
<xsl:call-template name="DiscoverWindowsUpdate" />
</tns:MyMachineConfiguration>
</xsl:template>
</xsl:stylesheet> |