difficulty having check_xml.php match a string value

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
jprince
Posts: 2
Joined: Mon Apr 22, 2019 3:55 pm

difficulty having check_xml.php match a string value

Post by jprince »

I'm trying to use check_xml.php to match a string value. Reading the php, I've figured out that keys are meant to be formatted as start[level][keyname].

This is how I'm executing the check:

Code: Select all

php check_xml.php -u https://example.org/xml -k list-item[bonder_status][state] -s up
This is a simplified version of the xml response being scraped:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<root>
  <list-item>
    <id>5</id>
    <tuning></tuning>
    <bonder_status>
      <state>up</state>
    </bonder_status>
  </list-item>
</root>
The response I get is

Code: Select all

CRITICAL - Value 'Array' did not match 'up'
I've done some debugging and find that it looks like maybe isset($current_arr[$key]) doesn't think bonder_status is set…or at least, having it print the $key it's checking before the check, checks bonder_status, but then never checks state.

I don't think I'm using this wrong, I've tried every format I can think of passing in the values. I don't seem to be able to find any examples of actually using check_xml.php this way and the documentation is as minimal as can be.

Anyone have any hints?
jprince
Posts: 2
Joined: Mon Apr 22, 2019 3:55 pm

Re: difficulty having check_xml.php match a string value

Post by jprince »

Alas, and naturally, I figured it out shortly after posting.

Dumping the entire XML array helped me to see that list-item is an array and therefore I have to add a reference to which element I want it to look at. This works:

Code: Select all

php check_xml.php -u https://example.org -k list-item["0"]["bonder_status"]["state"] -s up
OK - Value 'up' matched 'up'
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: difficulty having check_xml.php match a string value

Post by benjaminsmith »

Hi @jprince,

Awesome! Glad you got it solved and thanks for posting the solution.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked