News:

We really need your input in this questionnaire

Main Menu

WMI query returns codes

Started by ravi2904, November 04, 2019, 03:15:56 PM

Previous topic - Next topic

ravi2904

Hi Victor,

Some WMI queries return code numbers. For example, WMI.Query(root\CIMV2, Win32_Processor, Architecture) returns 0 for x86, 9 for x64. How to write a script which can transform the result ? Some example will be really helpful, as there are lot of queries which return code numbers. I am configuring the queries in DCI configuration.

Thanks in advance,

Ravi

Filipp Sudanov

#1
So, transformation scripts, as well as other scripts in NetXMS are written in NXSL - custom scripting language. It's syntax is resembling C language syntax. Language documentation can be seen here: https://www.netxms.org/documentation/nxsl-3.0/

Here's a sample script:

if ($1 == 9) {
  return "x64";
}
else if ($1 == 0)
{
  return "x86";
}
else
{
  return "unknown: ".$1;
}


$1 is the raw value (after step 1 of transformation), so in this case it's either 0 or 9. Other variables are also available in the script, e.g. $node in the node object to which the DCI belongs to. $node->name would be the name of the node.

You can use trace function to print debug information to server's log file, first parameter of trace is debug level on which the information is printed
trace(0, $node->name)

P.S. For me only the following syntax of the parameter worked on Win7:
WMI.Query(root\CIMV2,SELECT * FROM Win32_Processor, Architecture)



Victor Kirhenshtein

Small addition: if you have lot of values to convert or they change frequently you may want to create mapping table on the server (via Configuration -> Mapping Tables) and use NXSL function map (https://www.netxms.org/documentation/nxsl-3.0/#func-map) to map code to text.

Best regards,
Victor

ravi2904

Thank you so much Filipp  and Victor. I added the script in the transformation and it is working fine. Great.

Another query I had, some of the WMI queries return a list, for example, WMI.Query(root\CIMV2, select * from Win32_LogicalDisk, caption), will return the list containing all the drives i.e. C:, D:, E: etc. How can I address this ? Also, , is it possible anyway, to a different row in raw_dci_values for each of these,  like - Caption: C:, Free Space: 87982829 bytes.

Secondly, in the Object details screen, we get the capabilities list, which displays what kind of device it is, e.g. Printer, Bridge, Router etc. I think this comes from the nodes table from the column capabilities. If it is so, how does the "capabilities" column represent the description, since it contains a long integer. Can you explain this to me ? I needed this info to display in a different screen.

Thanks a lot.

Best regards,

Ravi

Filipp Sudanov

Currently WMI subagent does not support data presentation as table or list, it just takes first from received values. We are planning to implement this at some point of time.

Capabilities are stored as a bitfield in that long integer, here you can find which bit represents what capability: https://www.netxms.org/documentation/datadictionary-3.0/#t-nodes

Filipp Sudanov

Support for WMI queries returning lists or tables will be made available in 3.1 version.

ravi2904

Thank you so much for all the info. I look forward for the 3.1 version.

Thanks and best regards,

Ravi.