Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

share|improve this question

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

share|improve this answer
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

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

Your Answer


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.