Page 1 of 1

difficulty having check_xml.php match a string value

Posted: Tue Feb 09, 2021 4:43 pm
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?

Re: difficulty having check_xml.php match a string value

Posted: Tue Feb 09, 2021 5:14 pm
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'

Re: difficulty having check_xml.php match a string value

Posted: Tue Feb 09, 2021 6:14 pm
by benjaminsmith
Hi @jprince,

Awesome! Glad you got it solved and thanks for posting the solution.