Skip to main content

Hello,

I’m currently playing around with the collection mode for HTTP, to query some JSON Data. The JSON-Data includes boolean values which I want to use insight a count function for filtering elements on a selection. But it seems, that in this case, the boolean value is still something like ‘JSON::PP::Boolean=SCALAR(0x56146594f0d0)’ which I can not use in the filter for the count function.

JSON is like that:

{        "bindingName": "zway",        "creationTime": 1694179518,        "creatorId": 1,        "customIcons": {},        "deviceType": "switchMultilevel",        "firmware": "5.1",        "h": 128847420,        "hasHistory": false,        "id": "ZWayVDev_xxxx",        "location": 3,        "locationName": "xxxxx",        "manufacturer": "Fibaro",        "metrics": {          "icon": "blinds",          "isFailed": false,          "title": "xxxxx",          "level": 99        },

}

I want to count all devices, which are in failed state (metrics.isFailed = true), but I’m not able to get it work:

{
          "type": "count",
          "src": "%(http.tables.devicesRequestEntries)",
          "filter": "%(src.isFailed)",
          "save": "%(failedCount)"
 },

 

Additionally, I want to output those devices. Therefore I’ve defined the corresponding selection_loop and now I need to format the output. I’ve tried:

"formatting": {
        "display_ok": "true",
        "printf_msg": "Device %s is in status %i",
        "printf_var": f
          "%(devicesRequestEntries.title)",
          "%(devicesRequestEntries.isFailed)"
        ]
      },

which leads to many error messages, as type JSON::PP::Boolean=SCALAR(0x56146594f0d0) is neither an integer nor a string. And I need to set the critical clause in the loop too, which get’s me back to the first thing.

 

What am I missing? I think it’s just a layer-8 problem, but I need help to get it solved.

And of course: I’ve already read

And I’ve checked github to make sure to have the latest patches for the collection mode. And yes, the patch of https://github.com/centreon/centreon-plugins/pull/3749 is already included.

Solved with a mapping. If there’s any way to do this without mapping, then let me know please.


Hi @Iralein_priv,

Sorry for answering late… I had a look at your question some days ago but did not understand why you got such a value for you boolean, and switched to something else and forgot to answer.

A mapping does seem like a good way to handle this, actually. What it your mapping’s definition?

 

 

 


Hi omercier,

My mapping:

 "mapping": {
    "status": {
      "0": "false",
      "1": "true"
    }
  }

Simple, but stupid, as the Perl JSON recognizes the boolean values. Without the mapping: if you use the debug ouput of the plugin, then Perl will stringify the true/false values to the corresponding 1/0 for the variable contents, but the verbose output will point out the Scalar messages. From my point of view, it should be possible to create a simple warning/critical clause or filtering for boolean values from the JSON output without the need of parsing them to strings :-(


In your count function, you can use a filter to check if isFailed is true. Since the boolean values are represented as objects, you might need to convert them to scalars. You can try something like this:

{
  "type": "count",
  "src": "%(http.tables.devicesRequestEntries)",
  "filter": "%(bool(src.isFailed))"
}

 

Similar to the filter, you might need to convert boolean objects to scalars in the formatting section. You can use the bool() function here as well:

"formatting": {
  "display_ok": "true",
  "printf_msg": "Device %s is in status %i",
  "printf_var": _
    "%(devicesRequestEntries.title)",
    "%(bool(devicesRequestEntries.isFailed))"
  ]
}

 

If the issue persists, make sure to check for any other potential issues in your configuration or environment. Double-check your JSON structure, ensure that the necessary patches are applied, and confirm that your configuration aligns with the latest updates in the Centreon Plugins.


Reply