Check_http string not working

icinga2

(Lucas Possamai) #1

Hi all.

I want to test the status of my API. The API provides an XML output as below:

<?xml version="1.0" encoding="UTF-8"?><ping><service name="VStatic" status="up"/><service name="MPlus" status="up"/><service name="MRequest" status="up"/></ping>

So, I need to check if those services are “UP”, else, triggers an alert, i.e:

VStatic" status=“up” = OK
VStatic" status=“down” = DOWN

With the check_http command I do this way:

/usr/lib/nagios/plugins/check_http -H api.example.com -u /Ping/1.0 -S -J /etc/icinga2/pki/cert.pem -K /etc/icinga2/pki/cert.key -r ““VStatic” status=“up””

output:
HTTP OK: HTTP/1.1 200 OK - 1167 bytes in 0.048 second response time |time=0.047564s;;;0.000000;10.000000 size=1167B;;;0

Checking if it is down while it is up, just to double check if the pattern string check works:

/usr/lib/nagios/plugins/check_http -H api.example.com -u /Ping/1.0 -S -J /etc/icinga2/pki/cert.pem -K /etc/icinga2/pki/cert.key -r ““VStatic” status=“down””

output:
HTTP CRITICAL: HTTP/1.1 200 OK - pattern not found - 1169 bytes in 0.045 second response time |time=0.045116s;;;0.000000;10.000000 size=1169B;;;0

So, that works. Now, with icinga2 I am trying to do the same; on my host.conf file:

vars.local_http_VStatic["http_api_VStatic"] = {
   http_uri = "/Ping/1.0"
   http_address = "api.example.com"
   http_ssl = "true"
   http_clientcert = "/etc/icinga2/pki/cert.pem"
   http_privatekey = "/etc/icinga2/pki/cert.key"
   http_string = "\"VStatic\" status=\"up\""
}

However, it is not working. A couple of hours ago the service was down and icinga was reporting it as up.

Questions:

  • Is there a way to run the command from icinga and see the output? just like as curl or with check_http?
  • What am I doing wrong? isn’t the “http_string” the correct one?

Cheers!


(Carsten Köbke) #2

Hi,

you problem is -r != -s

so change http_string to http_expect_body_regex then it will match your test on the commandline.


(Lucas Possamai) #3

Hi,

hmmm… I will test it and come back to you. Thanks!


(Lucas Possamai) #4

hi @Carsten. I confirm this is working. Thanks again!