NetXMS Support Forum

Please login or register.

Login with username, password and session length

Author Topic: WMI query returns codes  (Read 306 times)

ravi2904

  • Newbie
  • *
  • Posts: 15
    • View Profile
WMI query returns codes
« on: November 04, 2019, 03:15:56 pm »

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
Logged

Filipp Sudanov

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 50
    • View Profile
Re: WMI query returns codes
« Reply #1 on: November 04, 2019, 06:46:35 pm »

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:
Code: [Select]
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
Code: [Select]
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)


« Last Edit: November 04, 2019, 07:05:59 pm by Filipp Sudanov »
Logged

Victor Kirhenshtein

  • Lead Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6806
    • View Profile
Re: WMI query returns codes
« Reply #2 on: November 05, 2019, 11:03:14 am »

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
Logged

ravi2904

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: WMI query returns codes
« Reply #3 on: November 05, 2019, 11:38:42 am »

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
Logged

Filipp Sudanov

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 50
    • View Profile
Re: WMI query returns codes
« Reply #4 on: November 06, 2019, 05:15:57 pm »

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
Logged

Filipp Sudanov

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 50
    • View Profile
Re: WMI query returns codes
« Reply #5 on: November 11, 2019, 12:30:19 pm »

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

ravi2904

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: WMI query returns codes
« Reply #6 on: November 12, 2019, 02:46:20 pm »

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

Thanks and best regards,

Ravi.
Logged