Page 1 of 1

check_http regex question

Posted: Fri Jul 15, 2016 7:45 am
by zovy
I'm looking for a method to return a value with check_http from a unique tag that is found on a short XML page. An added bonus would be if the returned value is greater than 4000000 to have NAGIOS treat it as a critical, however just getting the value returned and displayed on the NAGIOS console would be fine.

Scenario : An application (I have hundreds of these) accepts a URL and returns a short XML page with about 20-25 lines of unique XML tags with dynamic values that are always growing. I'm looking for the number between the documents tags. The number grows over time and I would like to know when it exceeds 4,000,000 so that I can perform some maintenance.

Code: Select all

<documents>4765129</documents>
I've tried check_http -H serverIP -p port# -u URLtoXML -r <documents>[\s\S]*?<\/documents> but I get a critical pattern not found response. I must admit I am terribly new to regular expressions. I am also aware that NAGIOS can be a headache with escape characters too and not sure if this might be part of my problem.

Re: check_http regex question

Posted: Fri Jul 15, 2016 11:08 am
by rkennedy
The -r parameter will allow you to match HTML, but it won't allow you to pull the data that it matches.

You should be able to write up a custom plugin, that pulls data between two fields. This article might help -
https://www.namepros.com/threads/how-to ... ag.611100/

You'll want to match the field, in your case <documents> and </documents>, and have the script set the containing information as a variable. Then, you'll need to have a function for the warning / critical, definitions to see how the plugin should exit. Exit 0 = ok, 1 = warning, 2 = critical. This link might help when it comes to writing a plugin - http://www.yourownlinux.com/2014/06/how ... cript.html

See what you can take from all of this, and let us know any questions you run into.