Walkthrough: Obtaining the hardware information for a specific server using RESTful web services


This topic walks you through the process of using the TrueSight Server Automation Command Line Interface (BLCLI) Get command in a REST query to pull hardware or server data from a server. 

 This topic includes the following sections:

Introduction

This topic is intended for system administrators who want to use a script to query the servers in their environment and obtain specific model information.

What does this walkthrough show?

In this walkthrough, a system administrator wants to use a script to obtain hardware information from servers in the TrueSight Server Automation managed environment. The administrator wants to use this information to create Smart Groups based on the hardware model of a server. 

This walkthrough shows an example of how you can obtain the hardware information of a specific server using the BLCLI GET command within a script.

How to obtain hardware information for a server using RESTful web services

 

Step

Example

1

Within the Servers folder, create a Smart Server Group.

  1. In the Servers folder, select the location where you want to create a smart group, right-click, and select New > Server Smart Group.
  2. On the Server Smart Group General panel, enter the name for the smart group, and the rules and conditions for smart group membership.
  3. The rules and conditions should specify the system model you want to collect in the group.
  4. Click Finish.

Repeat the process for any other model types you want to identify.


2

The first thing you need to do is to create the script that contains the BLCLi commands.

You can use Notepad, vi editor,I or a similar editor in NSH on either the local desktop computer or on a server managed by TrueSight Server Automation.

The first part of the script obtains the DB key for the server, and then uses the DB key to create a list of the data you can get from the server.  

This example uses xmllint to format the output.

blcli_execute Server getServerDBKeyByName blapp88-1.local
blcli_storeenv serverKey
blcli_execute GenericObject getRESTfulURI ${serverKey}
blcli_storeenv serverURI
blcli_execute Get "${serverURI}/"
blcli_storeenv resp1
echo "${resp1}" | xmllint --format -

3

The second query lists all the assets for the server, but not the properties and other information that the first query listed.

blcli_execute Get "${serverURI}/Assets/"
blcli_storeenv resp2
echo "${resp2}" | xmllint --format -

4

Next, we go down another level using the SystemInfo uri from resp2.

Note: The SystemInfo provides the same information as the Hardware Information item when you Live Browse the server.

blcli_execute Get "${serverURI}/Assets/SystemInfo"
blcli_storeenv resp3
echo "${resp3}" | xmllint --format -

5

The next step is to obtain the model information. In this example, examining the output of resp3 displays the URI component for the model information.

echo "${resp3}" | xmllint --format - | grep Model
<AssetAttributeValue name="Model" type="String" value="VMware Virtual Platform" uri="/id /SystemObject /Server /a279b6b7-c453-49fb-bf10-b1c6b6e0fb0a /Assets /SystemInfo /System /AssetAttributeValues/Model"/>

6

Next, use the GET command to obtain just the model information.

As an alternative, you could just process the output from the SystemInfo hardware component.

 

blcli_execute Get "${serverURI}/Assets/SystemInfo/System/AssetAttributeValues/Model/"
blcli_storeenv resp4
echo "${resp4}" | xmllint --format -

7

The output from resp4 provides the model information, which you can obtain by parsing the XML and pulling out the value tag.

<?xml version="1.0" encoding="UTF-8"?>
<RESTXMLResponse>
<AssetAttributeValueResponse>
<AssetAttributeValue>
<AssetAttributeValue name="Model" type="String" value="VMware Virtual Platform" uri="/id /SystemObject /Server /a279b6b7-c453-49fb-bf10-b1c6b6e0fb0a /Assets /SystemInfo /System /AssetAttributeValues/Model"/>
</AssetAttributeValue>
</AssetAttributeValueResponse>
</RESTXMLResponse>

8

Save the script.

 

9

The next step is to add the script to the Depot.

  1. Under the Depot folder, right-click the folder in which you want to store the NSH script, and select New > NSH Script.
  2. In the Add NSH Script to Depot wizard, enter a name for the script in the Name field, and specify the location of the script in the File Location field.
  3. Click Finish.


 

 10

Next, create an NSH Script Job based on the script that you added in the previous step.

  1. In the Depot folder, navigate to the script that you added.
  2. Right-click the script and select NSH Script Job from the pop-up menu.
  3. Provide information for the Network Shell Script Job, as described in xxxx.
  4. Click Finish after completing the last step of the wizard.

 

11 

Execute the NSH Script Job.

  1. In the Jobs folder, navigate to the job you created in the previous step.
  2. Right-click the job and select Execute.

 

 12

Browse to the Server folder. The servers are included in the Smart Groups you created, grouped by model type.

 

Wrapping it up

Congratulations! You have used the BLCLI and REST web services to obtain the hardware information for a specific server, and have categorized the servers in smart groups based on the hardware information you obtained.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*