XML API wizard or time to build my own plugin?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
davidhughes
Posts: 8
Joined: Mon Feb 22, 2021 5:37 pm

XML API wizard or time to build my own plugin?

Post 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
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: XML API wizard or time to build my own plugin?

Post 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.
[[email protected] ~]$ php /usr/local/nagios/libexec/check_xml.php -u 'https://www.w3schools.com/xml/note.xml' -k 'to' -s 'Tove' -r 0 -n 2
OK - Value 'Tove' matched 'Tove'
Regards,
Benjamin

Reference
Nagios XI - How To Test Check Commands From The Command-line
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!
davidhughes
Posts: 8
Joined: Mon Feb 22, 2021 5:37 pm

Re: XML API wizard or time to build my own plugin?

Post 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
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: XML API wizard or time to build my own plugin?

Post 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
You do not have the required permissions to view the files attached to this post.
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!
davidhughes
Posts: 8
Joined: Mon Feb 22, 2021 5:37 pm

Re: XML API wizard or time to build my own plugin?

Post 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'
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: XML API wizard or time to build my own plugin?

Post 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
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!
davidhughes
Posts: 8
Joined: Mon Feb 22, 2021 5:37 pm

Re: XML API wizard or time to build my own plugin?

Post 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>
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: XML API wizard or time to build my own plugin?

Post 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
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!
davidhughes
Posts: 8
Joined: Mon Feb 22, 2021 5:37 pm

Re: XML API wizard or time to build my own plugin?

Post 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.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: XML API wizard or time to build my own plugin?

Post 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
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