Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have this command defined:

define command{
command_name check_http_sane
command_line $USER1$/check_http -H $HOSTNAME$ -r "HTTP/1.1 (200|301|302|303|304|307|401|418|426)"
}

When I run it manually on command line, it works fine, but nagios (2.6) reports a "pattern not found" error. Do I need to escape something?


Edit: As stated below, I solved it by replacing check_http with my own script which works (good enough for our use case, anyway). Script: http://pastebin.com/hNmz6Wa1

share|improve this question
add comment

3 Answers

The source code for check_http.c says the -r option checks the headers and the page contents. The problem you are seeing is probably the Nagios command macro interpreter trying to replace something in your regex string.

You should try escaping all of your (,| and ) characters. If that doesn't work, try just the parentheses and just the pipes. You might also try using single quotes instead of double quotes.

share|improve this answer
add comment
up vote 1 down vote accepted

Since escaping didn't work either (and it does work without on command line, whyever) and I didn't want to spend more time debugging it, I wrote my own Nagios plugin to replace check_http, which works like a charm:

https://github.com/tao-software/nagios-plugin-http-tao

share|improve this answer
2  
Publish and be damned ! –  Iain Feb 21 '12 at 15:03
    
Publish! <!-- Minlength --> –  Bart De Vos Feb 21 '12 at 15:18
    
Moved the plugin to a git repo. –  Creshal Jul 3 '12 at 15:17
add comment

Your assertion that this "works fine" on the command line is questionable. When I run it manually, it does not "work fine":

./check_http -H localhost -r "HTTP/1.1 (200|301|302|303|304|307|401|418|426)" HTTP CRITICAL: HTTP/1.1 302 Found - pattern not found - 650 bytes in 0.001 second response time |time=0.001410s;;;0.000000 size=650B;;;0

As Jeff Strunk suggests, you need to escape the parentheses (so the shell does not consume them), like this:

./check_http -H localhost -r "HTTP/1.1 \(200|301|302|303|304|307|401|418|426\)" HTTP OK: HTTP/1.1 302 Found - 650 bytes in 0.001 second response time |time=0.001425s;;;0.000000 size=650B;;;0

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.