Custom Inventory - Parsing XML in NS7

Article:HOWTO10488  |  Created: 2009-08-12  |  Updated: 2009-08-12  |  Article URL http://www.symantec.com/docs/HOWTO10488
Article Type
How To



Question
Custom Inventory - Parsing XML in NS7

Answer

The following is a walkthrough of using custom inventory in NS7 to parse an xml file. In this example, we will use a VBScript and only parse specific fields from the xml file, while ignoring the remainder of the fields.

Overview

Briefly, this will entail the following steps:

  1. Identify the desired data in the xml file.
  2. Create a custom inventory data class.
  3. Create a vbscript to parse the desired fields from the xml file.
  4. Add the Altiris. AeXNSEvent logic to the vbscript.
  5. Create a 'Run script' task in the Notification Server console.
  6. Create a custom SQL report to report the new data.

Sample XML File

The examples in this document make use of the attached 'iso19770-2.xml' file, which is attached to this article. This example will return the following information from that file.

…<sit:product_title>Veritas NetBackup v6.0, Enterprise Server, Master Server</sit:product_title><sit:product_version><sit:name>6.0</sit:name><sit:numeric><sit:major>6</sit:major><sit:minor>0</sit:minor><sit:build>1</sit:build><sit:review>0</sit:review></sit:numeric></sit:product_version>…<sit:platform><sit:vendor>Hewlett-Packard</sit:vendor><sit:model>HP-UX 11i v3</sit:model></sit:platform><sit:cluster_name>argolis</sit:cluster_name><sit:cpu_count>2</sit:cpu_count><sit:hostname>david</sit:hostname><sit:ip_address>127.0.1.6</sit:ip_address>…

Step 1: Create a custom data class

In the Symantec Management Console:

  1. Browse to the Settings tab, then Settings, Discovery and Inventory, Inventory Solution and click on Manage Custom Data classes.
  2. Create a new data class by clicking the 'New data class' button.
  3. Enter an appropriate name and description.
  4. Allow the screen to refresh.
  5. Click on the name of the new data class in the 'Data class' list.
  6. Create the attributes (or columns) for this data class by clicking on the '+ Add attribute' button.
  7. Enter an appropriate name and select the desired Data type, Maximum size, Key and Data required values, as shown in the following image.

    imagebrowser image

  8. Repeat this for the following attributes:

    a. Title
    b. Version
    c. Vendor
    d. Model
    e. Cluster_name
    f. CPU_Count
    g. Hostname
    h. IP_Address.

  9. There should be no need for multiple rows to be populated for a given machine, so do not check the 'Allow multiple rows from a single computer resource' checkbox.
  10. Click the 'Save changes' button. The data class and corresponding table will be created.
  11. The following image shows a completed custom data class for this project.

    imagebrowser image

  12. Click the 'Details' button, which is the little hand with a pointing finger, will show the following information, some of which is needed in the VBScript.

    imagebrowser image

  13. The following image shows where the data class can be viewed (and even deleted) in the Symantec Management Console.

    imagebrowser image

Step 2: Create a VBScript

This is a fairly simple VBScript. There is nothing particularly complicated about it. The difficult parts are identifying the XMLDom method(s) to use and updating the appropriate Altiris.AeXNSEvent logic (which isn't really that difficult).

For this script, we know the exact node values we want, so only the "documentElement.selectSingleNode" is utilized. There are many other methods that can be employed that may require additional looping logic, i.e., selectNodes, firstChild, lastChild, getElementsByTagName, etc. A great overview of the available methods is found at: http://devguru.com/technologies/xmldom/quickref/xm....

Following is a partial listing of the VBScript. The complete vbscript is attached with a .txt file extension. Note that the script will parse the xml source file, load all desired data into variables, THEN we will start our custom inventory logic using the Altiris.AeXNSEvent.dll.

Sample VBScript code to parse the XML values

'***************************************************Set xmlDoc= CreateObject("Microsoft.FreeThreadedXMLDOM")xmlDoc.load (".\iso19770-2.xml")Set xmlRoot = xmlDoc.documentElement'***************************************************' Get product_titleSet Node = xmlDoc.documentElement.selectSingleNode("sit:product_title") Wscript.Echo Node.textproduct_title = Node.text'***************************************************'***************************************************' Get Product VersionSet Node = xmlDoc.documentElement.selectSingleNode("sit:product_version/sit:numeric/sit:major") major = Node.textSet Node = xmlDoc.documentElement.selectSingleNode("sit:product_version/sit:numeric/sit:minor") minor = Node.textSet Node = xmlDoc.documentElement.selectSingleNode("sit:product_version/sit:numeric/sit:build") build = Node.textSet Node = xmlDoc.documentElement.selectSingleNode("sit:product_version/sit:numeric/sit:review") review = Node.textproduct_version = major & "." & minor & "." & build & "." & reviewWscript.Echo product_version' End of Get Product Version'***************************************************'***************************************************' Get vendorSet Node = xmlDoc.documentElement.selectSingleNode("sit:extended_information/sit:net_backup_data/sit:platform/sit:vendor") Wscript.Echo Node.textvendor = Node.text'***************************************************(The VBScript continues for the remaining xml values to be retrieved)

Sample VBScript code to create the NSE object, populate the data class row with values from the xml file and send the NSE to the Symantec Management Console

'Create instance of Altiris NSE componentdim nseset nse = WScript.CreateObject ("Altiris.AeXNSEvent")' Set the header data of the NSE' Please don't modify this GUIDnse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"nse.Priority = 1'Create custom inventory instance, dataclass and associated row(s) of data.'The data class must be created in the SMC.'The data class name or its guid must be used here. In this example, the guid is commented out.dim objDCInstance'set objDCInstance = nse.AddDataClass ("{9c03deff-ebf6-496a-b898-e6d90c45f8cb}")set objDCInstance = nse.AddDataClass ("NBU Master Server")dim objDataClassset objDataClass = nse.AddDataBlock (objDCInstance)'Add a new rowdim objDataRowset objDataRow = objDataClass.AddRow'Set columnsobjDataRow.SetField 0, product_titleobjDataRow.SetField 1, product_versionobjDataRow.SetField 2, vendorobjDataRow.SetField 3, modelobjDataRow.SetField 4, cluster_nameobjDataRow.SetField 5, cpu_countobjDataRow.SetField 6, hostnameobjDataRow.SetField 7, ip_addressnse.SendQueued

The Altiris.AeXNSEvent.dll

This dll contains a class that defines the custom inventory, or NSE, objects and methods that can be utilized to create an NSE. Note that this class provides for the following to be accomplished:

  1. Create an instance of an NSE object.
  2. Set the header To and Priority values. Note that the 'To' guid should never be changed. This values is used by the Symantec Management Console.
  3. Create an instance of a data class object.
  4. Create a data block that will contain the rows of data.
  5. Create a data row object.
  6. Populate the data row object with data from the xml file.
  7. Send the NSE to the Symantec Management Console.

I prefer to create the VBScript in a developer style text editor that provides for highlighting of keywords, indenting, etc. Once the code is complete, I copy and paste the code into the Symantec Management Console's task script window.

Note: It is possible to test this script from a command line of a Notification Server that has the Altiris.AeXNSEvent.dll registered. The VBScript will find the registered dll and be able to work with the class, the same as it would if it ran from a task. Even the data will load into the CMDB properly. It's very nice to be able to test that way.

Step 3: Create a Scripting Task

To create the actual task to run on client computers:

  1. Open the Symantec Management Console in a browser
  2. Browse to the 'Manage' menu item
  3. Click on 'Jobs and Tasks', which is the top menu tree item in the left-hand screen.
  4. In the 'Jobs and Tasks Quick Start' web part, click on 'Create a new job or task'. A new window will open.
  5. Scroll to the very bottom of the menu tree to find the correct 'Run Script' menu tree entry. In this image, all menu tree folders have been collapsed to show the menu tree hierarchy. The correct menu tree entry is highlighted.
  6. Enter a name for the task or job in the top line (above 'Script Details').
  7. Paste in the VBScript code into the main editing portion of the screen, as shown below.

    imagebrowser image

  8. Click 'OK'. The job will be saved and the window will disappear. The new job will appear in the menu tree under Jobs and Tasks, System Jobs and Tasks, Notification Server, as shown here.

    imagebrowser image

Step 4: Run the New Task

At this point, the task be ran using the 'Quick Run' option or it can be scheduled. To use the quick run option:

  1. Click the 'Quick Run' button in the 'Task Status' section of the screen.
  2. Type in the name of the desired endpoint client computer.
  3. Click the 'Run' button. An entry will appear in the 'Task Status' section of the screen for that new task instance.
  4. After a few seconds, click the 'Refresh' button, which is the round, green double-arrow toward the right-hand side of the 'Task Status' section of the screen. After a minute or so, it should show a green bar with a '0% failed' message. At that point, the data should be in the data base.

    imagebrowser image

Step 5: Validate the Data

Open SQL Server Management Studio and connect to the appropriate SQL server. Open a new query window and run something like 'select * from <my new custinv table>'. The name of the table is given in the Custom Data Class details window, which was noted earlier.

The results should show the nine columns and associated values from the xml file you processed in your VBScript.

Step 6: Create a Report

Following is a brief overview of how to create a simple custom report in the Symantec Management Console.

  1. In the SMC, click on 'Reports' and select 'All Reports'.
  2. Create a new folder for custom or in-house reports, if desired.
  3. Right-click on the desired report folder in the menu tree and select New, Report, SQL Report.

    imagebrowser image

By default, reports appear to have security and scoping logic already. While a bit daunting, it makes sense. Just add the desired attributes, table joins and where, grouping or other logic to what is there. In this case, "nms.*" was added (and the required comma on the preceding line). Also, the last line, which joins the new custom inventory table to one of the existing tables, was added. All non-default test is bold. The tables join on resourceguid assigned to endpoint clients.

DECLARE @v1_TrusteeScope nvarchar(max)SET @v1_TrusteeScope = N'%TrusteeScope%'SELECT  [vri2_Resource].[Guid] AS [_ItemGuid],  [vri2_Resource].[Name],  nms.*FROM  [vRM_Resource_Item] AS [vri2_Resource]  INNER JOIN [fnGetTrusteeScopedResources](@v1_TrusteeScope) AS [fnGTSR_3]     ON [vri2_Resource].[Guid] = [fnGTSR_3].[ResourceGuid]  join inv_nbu_master_server nms on nms._resourceguid = [vri2_resource].[guid]

The report should appear as shown in the following screen.

imagebrowser image

Note that if the values in the xml file are changed, and the VBScript is run from a command prompt, then the values in the database and, subsequently the report, will change. The script does not need to run from an actual SMC task when ran on the Notification Server. It can be ran from a command prompt. This is great for testing.


Attachments

iso19770-2.vbs_.txt (4 kBytes)
iso19770-2.xml_.xml (4 kBytes)



Legacy ID



48569


Article URL http://www.symantec.com/docs/HOWTO10488


Terms of use for this information are found in Legal Notices