Sometimes you may need to report information based on command line types, you know the 'install', 'uninstall', 'Custom', 'Repair' etc.
But how do you get this information out of the Symantec CMDB. Today we will do excatly that with a short SQL query so you don't have to work it all out yourself.
First, you need to know which table contains the data, and in which form. We have 2 tables that contain all of the interesting data:
- RM_ResourceSoftware_Command_Line
- RM_ResourceCommand_Line_Type
Unlike many relations between items or resources the mapping from command line to command line type is not done in ItemRefernece or ResourceAssociation. Rather the command line type guid is embedded inside the Software Command Line state.
So we need to do the following (pseudo sql):
select * from <cmd line> join <cmd type> on <cmd line>.state(command line guid) = <cmd type>.guid
In order to extract the command line type guid we will be using Microsoft SQL xml 'value' method. The value method takes an xpath query and sql datatype argument pair.
The state xml looks like this:
<item> <SomeNode param="valueX" /> <OtherNode param="valueY">Node Content</OtherNode> <commandLineType guid="<guid>" /> <SomeOtherNode parmaT="reituoer" paramV="orietper">This is the some other node content</SomeOtherNode> </item>
So the XQuery to access the command line type node is simple: '/item/commandLineType', and extracting the guid parameter is a little more complex, but not by a stretch: '(/item/commandLineType/@guid)[1]'. In English, we access the first entry ([1]) in the guid parameter (@guid) found under the root node item, sub-node commandLineType (/item/commandLineType).
Final SQL query:
select cmd.guid, cmd.name, typ.Name, cast(cmd.state as xml).value('(/item/commandLineType/@guid)[1]', 'char(36)') from RM_ResourceSoftware_Command_Line cmd join RM_ResourceCommand_Line_Type typ on typ.Guid = cast(cmd.state as xml).value('(/item/commandLineType/@guid)[1]', 'char(36)')