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.
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.
|
|
10 | Next, create an NSH Script Job based on the script that you added in the previous step.
|
|
11 | Execute the NSH Script Job.
|
|
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.