Ad Widget

Collapse

Zabbix 4.4: wmi.getall[] - the problem is the value of the returned data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 4ernomor
    Junior Member
    • Feb 2020
    • 3

    #1

    Zabbix 4.4: wmi.getall[] - the problem is the value of the returned data

    Hi!

    The WMI query returns values of type Real32.
    When using wmi.get[] - the returned value is correct.
    When using wmi.get all [] - the return value is incorrect.
    Example:
    Code:
    C:\Program Files\Zabbix Agent>zabbix_get -s 127.0.0.1 -k wmi.get[root\OpenHardwareMonitor,"select Max from sensor where (Parent LIKE '%RAM%' AND SensorType = \"Load\")"]
    79.757965
    
    C:\Program Files\Zabbix Agent>zabbix_get -s 127.0.0.1 -k wmi.getall[root\OpenHardwareMonitor,"select Max from sensor where (Parent LIKE '%RAM%' AND SensorType = \"Load\")"]
    [{"Max":4635312884778270720.}]
    [LEFT][COLOR=#252C2F][FONT="Open Sans"][/FONT][/COLOR][/LEFT]

    How to use wmi.getall [], get a human readable value?
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    As the documentation for the Windows-specific item types points out, wmi.get[] returns one value, with a particular type (like Real32).

    wmi.getall[] instead returns a JSON Object, since it's designed to return multiple values of potentially different types.

    The comment for wmi.getall[] indicates you can use pre-processing to extract specific values. There's a link from the pre-processing area to the details about JSONPath in the appendix.

    Comment

    • 4ernomor
      Junior Member
      • Feb 2020
      • 3

      #3
      Clarify (sorry for bad English):
      Key "wmi.getall[] " - returns a JSON object, but the Real32 data in this object is incorrect.
      Key "wmi.get[]" data of type Real32 returns as "79.757965", whereas the key is "wmi.getall[]" returns as "4635312884778270720."
      If you use JavaScript preprocessing, example of a built-in Zabbix template: "Template Module Windows physical disks by Zabbix", which uses JavaScript for Discovery rule "Physical disks discovery":

      Code:
      output = JSON.parse(value).map(function(dev){
      return {
      "{#DEVNAME}": dev.Name,
      "{#DEVQUEUE}": dev.CurrentDiskQueueLength,
      "{#DEVREADS}": dev.DiskReadsPersec,
      "{#DEVTIME}": dev.PercentDiskTime,
      "{#DEVWRITES}": dev.DiskWritesPersec
      }})
      return JSON.stringify({"data": output})
      adapted in my case:

      Code:
      output = JSON.parse(value).map(function(dev){
      return {
      "{#SENSORID}": dev.Identifier,
      "{#SENSORINDEX}": dev.Index,
      "{#SENSORINSTANCE}": dev.InstanceId,
      "{#SENSORMAX}": dev.Max,
      "{#SENSORMIN}": dev.Min,
      "{#SENSORNAME}": dev.Name,
      "{#SENSORPARENT}": dev.Parent,
      "{#SENSORPARENT}": dev.ProcessId,
      "{#SENSORTYPE}": dev.SensorType,
      "{#SENSORVAL}": dev.Value
      }})
      return JSON.stringify({"data": output})
      then an error is returned for a value with the type Real32:
      "SyntaxError: invalid json (at offset 86) at [anon] (duktape.c:34342) internal at parse () native strict preventsyield at [anon] (function:1) preventsyield"
      Last edited by 4ernomor; 24-02-2020, 09:56.

      Comment

      • tim.mooney
        Senior Member
        • Dec 2012
        • 1427

        #4
        Your English was fine, I just misunderstood what the problem was. Sorry about that.

        You're correct that the returned "Max" value seems to be completely different, even though the query appears to be exactly the same. I don't know what's causing that.

        I'm not a strong JavaScript programmer, but I think you can't just take the "physical disks" JSON preprocessing and use that here. The reason is that the physical disks template
        must be returning a JSON Object named "dev", with keys for Identifier, Index, Min, Max, etc. But the WMI query you're getting isn't returning an object named "dev" with those keys.

        Comment

        Working...