Introduction to Custom Inventory in Notification Server 7.1 or later (including 8.x) [Altiris]

book

Article ID: 178432

calendar_today

Updated On:

Products

Endpoint Encryption

Issue/Introduction

 

Resolution

Introduction to Custom Inventory in Notification Server 7.1 or later (including 8.x)

 

Notification Server 7.1 introduced major enhancements and changes to the custom inventory process. This article provides a preview of the process, as of the date of this article.

Further examples can be found in HOWTO10487

Introduction

Custom Inventory in Notification Server 7.1 and later is cross-platform and script-based. The same console screens are used to create and configure custom inventory across all platforms - Windows, Unix, Linux and Macintosh. However, the code is not cross-platform. Custom inventory scripts must be written in a language that can be executed on each OS. The following scripting languages are supported:

  • JavaScript
  • Perl
  • PowerShell
  • Python
  • Unix Shell script
  • VBScript

Note that while 'Run Script' tasks can be ran in additional languages, only the languages listed here are capable of processing custom inventory logic and objects. Several sample custom inventory scripts are attached to this article. 

 

Custom Inventory requires that the data class that will hold the custom data be created on the Notification Server prior to deploying the custom inventory task to clients. These data classes are referred to as 'custom data classes'.

The basic process of creating a custom inventory task is:

  1. Create the data class in the NS console
  2. Create the task with scripting logic in the Notification Server console
  3. Deploy the custom inventory task to clients, which send results back to the NS
  4. Create a report to view the results of custom inventory. (This document will not discuss report creation.)
 

Create a Custom Data Class

  1. In the NS Console, click Settings, All Settings, . Then, expand Discovery and Inventory, Inventory Solution, Manage Custom Dataclasses.
  2. Click on '* New Dataclass' and enter a Name and Description. In this example, I will be selecting data from the Win32_UserAccount class and creating attributes for the following three fields: Name, Disabled and SID. Note: After saving changes in step 7 below, the system will create a table in the CMDB with the data class name you entered prefixed by Inv_ (Inv_Win32_UserAccount for example).
  3. Highlight the new dataclass and click 'Add attribute'. Enter a name and select or enter the appropriate Data Type, Maximum size, Key option and Data required option.
  4. Repeat this for each attribute/column you wish to collect data for.
  5. A completed custom dataclass would appear as shown here.
  6. Note the option to 'Allow multiple rows from a single computer resource'. This is helpful, and necessary, as is the case with a User report, for example, where multiple users can be reported on each computer.
  7. When you are done adding attributes, click 'Save changes' at the bottom of the screen.
  8. The GUID for this dataclass will be required to be entered in the script. To find the guid, click on a dataclass name, then click the 'Details' button, which is the little hand between the 'New dataclass' button and the red 'X' button. Make a note of the guid value and save it for later use. (Note: this is a Windows-only requirement. Unix, Linux and Macintosh scripting do not have this requirement.)

Create a Custom Task and Script for Windows

The easiest way to create a new custom inventory task is to clone a sample. The sample already contains the required code for a WMI query. You will only need to add your own logic to gather the data you require and to populate the attribute variables in the script.

For this example, we will walk through the steps required to create a new task and manually enter the custom inventory code. This code can be copied from a sample, or previously existing, custom inventory task prior to creating this new task.

  1. In the NS Console, click on 'Manage' > 'Jobs and Tasks' and click on the 'Jobs and Tasks' menu entry in the left-hand pane.
  2. Click on 'Create a new job or task' in the right-hand pane. A new window will open.
  3. Scroll to the bottom of the left-hand pane in the new window and click on 'Run Script' to select the appropriate type of task.
  4. Enter an appropriate name for this task in top text field.
  5. Select the desired script type. Again, Custom Inventory in NS can run AppleScript, Command Script, JavaScript, Perl, Powershell, Python, Unix shell scripts or VBScript.
  6. Enter the following code. Similar code will already exist if you cloned the task. This task performs the following:
    1. Creates a wmi object, executes a wmi query and stores the result set.
    2. Creates an Altiris NSE object.
    3. Creates an Altiris 'Inventory data block' and associates it with a specific custom data class.
    4. Loops through each row in the result set and populates each row of the result set into a row in the datablock.
    5. Processes and sends the NSE to the Notification Server.
      On Error Resume Next
      'Create instance of Wbem service object, connect to namespace and run wmi query
      strComputer = "."
       
      Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      Set objCIMObj = objWMIService.ExecQuery("select * from win32_useraccount")
       
      'Create instance of Altiris NSE component and set the header data of the NSE
      dim nse
      ' The Altiris.AeXNSEvent class is installed with the inventory plugin and can be referenced externally. 
      set nse = WScript.CreateObject ("Altiris.AeXNSEvent")
       
      ' Please don't modify this GUID. This is the 'Inventory Capture Item'. 
      nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
      nse.Priority = 1
       
      'Create Inventory data block for this dataclass. 
      'Specify either the name or the guid of the associated dataclass. The name is recommended. 
      dim objDCInstance
      'set objDCInstance = nse.AddDataClass ("{3ce8a021-ffaa-4467-a01a-872e0fcabbdf}")
      set objDCInstance = nse.AddDataClass ("WinUsers")
      dim objDataClass
      set objDataClass = nse.AddDataBlock (objDCInstance)
       
      
      For each objInfo in objCIMObj
       
      'Add a new row and set column values
      dim objDataRow
      set objDataRow = objDataClass.AddRow
      objDataRow.SetField 0, objInfo.Name
      objDataRow.SetField 1, objInfo.Disabled
      objDataRow.SetField 2, objInfo.SID
      Next
       
      nse.SendQueued
  7. Note that custom inventory includes the ability to add 'tokens', or pre-defined variables, to scripts. The available tokens are shown below. It is possible to create new,
  8. It is also possible to create new tokens. The values can be selected from the Symantec_cmdb database, as shown below. '%COMPUTERID% is a predefined token that contains the client's guid value.
  9. The advanced tab contains settings for authentication, windowing of the client task, and task control.

     

  10. Click 'Save Changes' to save the script and associated settings. At this point, the task is ready to run.
  11. The 'Task Status' section of this screen contains scheduling and other options. Scheduling is partly controlled by core NS functionality and partly by Inventory Solution functionality.
    1. Quick Run - When this option is selected, a combo list box is presented. The desired client computer name can be entered. Also, a drop-down list of available resources will be populated and the desired resource can be chosen from the list. Selecting a resource and clicking 'run' will initiate the task on the selected client immediately, depending on maintenance windows, etc.
    2. New Schedule - This is a standard scheduling window. A new schedule will be associated with the current task, allow for selection of specific resources, and can be ran 'Now' or on a specified schedule that has the option to repeat at a specified frequency. There is also an option to override maintenance windows.
  12. Other features in the 'Task Status' section are the task details screen, delete task entries, task history view, grouping and search options and the refresh button.
    1. Details - This is the little hand icon. It shows details of when the highlighted task ran, if it succeeded, etc.
    2. Delete - The red 'X' allows you to delete highlighted entries in the task status section.
    3. View - Allows for seeing current or archived entries.
    4. Group By - Provides a drop-down list for grouping entries to see a higher-level view.
    5. Search - Allows for searching for specific entries.
    6. Refresh - Reloads entries and status of entries. The down-arrow allows for setting an automatic refresh interval.

Create a Custom Task and Script for Unix, Linux or Macintosh

Creating a Unix or Linux custom inventory task is exactly the same as creating a custom inventory task for Windows except for the scripting language and the actual code, or logic, used in the script. The Unix and Linux custom inventory in NS7 was built to facilitate the re-use of custom inventory logic from an NS6 environment.

  1. Create a custom data class, as explained above.
  2. Create a new task, as explained above. Or, simply browse to "Jobs and Tasks -> Samples -> Custom ->Custom Inventory - PS List", right-click on this task and select clone.
  3. Add and modify the code of your new task as required for your specific requirements. See the sample code and explanation, below.
  4. After saving the task, it may be helpful to move it to a more appropriate folder in the menu tree. Simply open the desired location in the menu tree and drag the task to that location.
  5. The task can be ran and scheduled the same as any other task in the NS console.

    Following is a sample shell script for Unix, Linux and Macintosh custom inventory.

    ## Sample script for Unix, Linux and Macintosh custom inventory
    . `aex-helper info path -s INVENTORY`/lib/helpers/custominv_inc.sh
     
    # The custominv_inc.sh inclusion is required at the begin of the script, prior to any other custom inventory logic.
    # The following comment/label is also required to mark the beginning of the custom inventory logic.
    # SCRIPT_BEGINS_HERE
     
    #!/bin/sh
    echo UNIX_PS_List
    echo "Delimiters=\" \" "
    echo string20 string20 string20 string256
    echo PID Terminal Time Command
    if [ "`uname -s`" = "Darwin" ] ; then
    	ps -ax | sed -e "1d" | awk '{print $1 " " $2 " " $4 " " $5 " " }'
    else
    	ps -e  | sed -e "1d" | awk '{print $1 " " $2 " " $3 " " $4 " " }'
    fi

This code does the following:

  1. Include a file required to format the data.
  2. Specify the data class.
  3. Specify delimeters for use in parsing the data returned from the command to be executed.
  4. Specify the datatypes and lengths of each column.
  5. Specify the column names. Note: this is only required when the command to be executed does NOT already include column headings.
  6. Run the desired command. In this case, we check for and run appropriate platform-specific commands.

Attachments

ns8_capture_regkey_Ex.vbs.txt get_app
ns7_wmi_Processor_Ex.vbs.txt get_app
ns7_wmi_Processor_Ex.py.txt get_app
ns7_wmi_Processor_Ex.ps1.txt get_app
ns7_wmi_Processor_Ex.pl.txt get_app
ns7_wmi_Processor_Ex.js.txt get_app
macfonts.txt get_app
cpuinfo.sh.txt get_app