Page 1 of 2
XML API wizard or time to build my own plugin?
Posted: Mon Feb 22, 2021 6:27 pm
by davidhughes
One of the DEV teams my NOC supports has an in-house monitoring tool which provides sensor feedback and system diagnostic checks via an XML API.
I am attempting to use the XML monitoring wizard to monitor these devices, but I am just getting errors such as:
UNKNOWN - Could not parse XML data
UNKNOWN - Value 'Array' did not match ''
UNKNOWN - Could not find the key or the value is not numeric
I am so far unsuccessful at finding documentation on the check_xml CLI. Can anybody recommend next steps for me?
Thank you,
David
edit: my Nagios is a deployed VMware template
Re: XML API wizard or time to build my own plugin?
Posted: Tue Feb 23, 2021 3:04 pm
by benjaminsmith
Hi David,
Hope you are enjoying the trial of Nagiso XI. As far as the XML Wizard goes, you shouldn't need to write your plugin, let's see if we can get this working for you.
Can you attach or PM a sample of the xml output from the page. It's likely to due to error traversing the XML document. Also, post the full check command as run from the command line ( see the link below for directions).
This is a very simple example, but here's a link to a simple XML doc.
https://www.w3schools.com/xml/note.xml
A simple check against the
to element, would be as follows.
Regards,
Benjamin
Reference
Nagios XI - How To Test Check Commands From The Command-line
Re: XML API wizard or time to build my own plugin?
Posted: Mon Mar 01, 2021 3:45 pm
by davidhughes
Hi Benjamin, sorry I didn't notice your reply until recently. Thank you for the prompt response! an example of xml output:
<wfs:FeatureCollection xmlns:xs="
http://www.w3.org/2001/XMLSchema" xmlns:company="
http://company" xmlns:wfs="
http://www.opengis.net/wfs" xmlns:gml="
http://www.opengis.net/gml" xmlns:ogc="
http://www.opengis.net/ogc" xmlns:ows="
http://www.opengis.net/ows" xmlns:xlink="
http://www.w3.org/1999/xlink" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="1" timeStamp="2021-03-01T20:38:48.358Z" xsi:schemaLocation="
http://www.opengis.net/wfs http://127.0.0.1:2080/geoserver/schemas ... .0/wfs.xsd http://company http://127.0.0.1:2080/geoserver/company ... servations">
<gml:featureMembers>
<company:latestObservations gml:id="latestObservations.fid--6099248f_177ed2b17ff_3fa4">
<company:source>WTC</company:source>
<company:longitude>-74.01426</company:longitude>
<company:latitude>40.71042</company:latitude>
<company:altitude>25.0</company:altitude>
<company:height>0.0</company:height>
<company:capability_name>company_SURFACE_OBS/AQTS_NO_UNIT_VALUE_PT1M_1</company:capability_name>
<company:sequence_number>1</company:sequence_number>
<company:parameter_name>AQTS</company:parameter_name>
<company:unit_name>NO_UNIT</company:unit_name>
<company:statistic_name>VALUE</company:statistic_name>
<company:period>60000</company:period>
<company:observed>2021-03-01T20:37:55.468Z</company:observed>
<company:value>0</company:value>
<company:raw_value>0</company:raw_value>
<company:quality_level>1</company:quality_level>
<company:quality_value>0</company:quality_value>
</company:latestObservations>
</gml:featureMembers>
</wfs:FeatureCollection>
and the command associated is:
check_xml!-u 'https://<<address>>' -k 'valuel' -w 0 -c 0
Re: XML API wizard or time to build my own plugin?
Posted: Tue Mar 02, 2021 4:26 pm
by benjaminsmith
Hi,
check_xml!-u 'https://<<address>>' -k 'valuel' -w 0 -c 0
Thanks for posting the XML output. I don't see a value for value in the XML posted. Is this the correct field and check? Let's verify this by going to Configure > Core Config Manager > Monitoring > Services .. find the search for this service, then click on service, and from the Common Settings tab, select
Run Check Command. Then cut and paste the full check command to the thread.
run-check_command-3.png
Also, most of those fields are strings, so if you are using the -k option, make sure the field is in fact an integer or you will get the same error message.
Lastly, if you can run the check from the CLI but add the following, just below line 60, that would help us figure the XML structure when it gets parsed.
Code: Select all
vi /usr/local/nagios/libexec/check_xml.php
print_r($current_arr);
Regards,
Benjamin
Re: XML API wizard or time to build my own plugin?
Posted: Wed Mar 03, 2021 4:59 pm
by davidhughes
Hi Benjamin,
When I search for strings I get comparison I am running up against value: array did not match ''. I feel like no matter how I identify a key, I'm not pulling a data point from the xml.
check_xml!-u 'https://' -k 'company:raw_value' -s '0' -r 0 -n 2
adding the print_r line yields this result:
Array
(
[@attributes] => Array
(
[numberOfFeatures] => 1
[timeStamp] => 2021-03-03T21:57:45.103Z
)
)
CRITICAL - Value 'Array' did not match '0'
Re: XML API wizard or time to build my own plugin?
Posted: Thu Mar 04, 2021 6:00 pm
by benjaminsmith
Hi David,
Thanks for posting the output with the print command added. I don't think it's able to retrieve the full XML file (or there is a parsing error). From the XI server, let's run a curl command against the XML page, and post the results.
Example Command:
Code: Select all
curl -k -XGET https://www.w3schools.com/xml/note.xml
Re: XML API wizard or time to build my own plugin?
Posted: Tue Mar 09, 2021 9:32 am
by davidhughes
I've retrieved the curled xml- I took the liberty of adding linebreaks.
<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns:wfs="
http://www.opengis.net/wfs" xmlns:gml="
http://www.opengis.net/gml" xmlns:ogc="
http://www.opengis.net/ogc" xmlns:ows="
http://www.opengis.net/ows" xmlns:company="
http://company" xmlns:xlink="
http://www.w3.org/1999/xlink" xmlns:xs="
http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="1" timeStamp="2021-03-09T14:26:33.605Z" xsi:schemaLocation="
http://www.opengis.net/wfs http://127.0.0.1:2080/geoserver/schemas ... .0/wfs.xsd http://company http://127.0.0.1:2080/geoserver/company ... servations">
<gml:featureMembers>
<company:latestObservations gml:id="latestObservations.fid--6099248f_17815f7fcbf_-bb2">
<company:source>WTC</company:source>
<company:longitude>-74.01426</company:longitude>
<company:latitude>40.71042</company:latitude>
<company:altitude>25.0</company:altitude>
<company:height>0.0</company:height>
<company:capability_name>company_SURFACE_OBS/AQTS_NO_UNIT_VALUE_PT1M_1</company:capability_name>
<company:sequence_number>1</company:sequence_number>
<company:parameter_name>AQTS</company:parameter_name>
<company:unit_name>NO_UNIT</company:unit_name>
<company:statistic_name>VALUE</company:statistic_name>
<company:period>60000</company:period>
<company:observed>2021-03-09T14:25:57.370Z</company:observed>
<company:value>0</company:value>
<company:raw_value>0</company:raw_value>
<company:quality_level>1</company:quality_level>
<company:quality_value>0</company:quality_value>
</company:latestObservations>
</gml:featureMembers>
</wfs:FeatureCollection>
Re: XML API wizard or time to build my own plugin?
Posted: Wed Mar 10, 2021 12:43 pm
by benjaminsmith
Hi David,
Thanks for testing that curl command. After quite a bit of testing this internally, we've found that the ': ' characters in the XML names do not work with the PHP function that converts the XML data into an object. So this XML page is not compatible with the Configuration Wizard.
I could submit a feature request to add this type of functionality.
Benjamin
Re: XML API wizard or time to build my own plugin?
Posted: Thu Mar 11, 2021 9:29 am
by davidhughes
Hello Benjamin,
This would be a great feature for my company's use case. We have a vast array of sensors in the field which produce XML similar to this, and many would not be able to have their protocol reconfigured to eschew the colons. Digesting to extend monitoring of this XML is a golden goose for many project teams within our organization.
Re: XML API wizard or time to build my own plugin?
Posted: Thu Mar 11, 2021 11:23 am
by benjaminsmith
Hi David,
I just submitted a request for you. I'm chatting with the developer right now, and he's looking into the issue for possible workarounds. I'll let you know what I find out.
Benjamin