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 want to create a nagios check that test if a certain file is available on a public website and if that file contains a certain line of text.

From the command line I have been executing:

./check_http -H 192.168.1.2 -u http://192.168.1.2/index.html -t 5 -s "Company Name"

Which passes OK and fails if I delete the file or change the text it is looking for.

Now I want to incorporate this into my nagios config files.

I create a Host which has the address of the ip address above and create a service as follows.

check_command check_http!-u /index.html -t 5 -s "Company Name"

But if I change the filename it is checking or the text it is checking it still passes even though I know they don't exist on the website.

What am I doing wrong I think I must be testing a different file or something for it to always pass.

share|improve this question
    
Can you have a look at the web server logs and see exactly what the request is, if it's a 200, or 404, or 500 etc, to begin with? –  Xerxes Jun 2 '09 at 13:27
    
Can you show us the command_line value in the command definition as well? –  Kyle Brandt Jun 2 '09 at 13:33

3 Answers 3

up vote 3 down vote accepted

When you are executing the command manually, you are calling /usr/lib/nagios/plugins/check_http correct?

When you are calling check_http from the nagios config, it looks at /etc/nagios-plugins/config/http.cfg to determine the check_http command arguments.

What you need to do is create a custom check like:

define command {
    command_name                   check_web_content
    command_line                   $USER1$/check_http -H $HOSTADDRESS$ -t 60 -w 15 -c 45 -u $ARG1$ -s $ARG2$

}

Then in your service configuration your check_command should be something like:

check_command check_web_content!http://www.domain.com/index.html!"Text on site"
share|improve this answer
    
Thanks that worked great. One question -w and -c are they what determine if the alerts is a warning or critical? –  Funky Si Jun 2 '09 at 13:52
    
Yes, those are timeouts in seconds. (I just grabbed the line I use in my nagios file - which uses custom timeouts) –  Brent Jun 2 '09 at 14:03

First you need to define a command:

define command {
    command_name    check_http
    command_line    $USER1$/check_http -H $HOSTADDRESS$ \
                    -u $ARG1$ -t $ARG2$ -s $ARG3$
}

Then for your host entry define the check_command as follows:

check_command    check_http!/index.html!5!"Company Name"
share|improve this answer
2  
You might want to define a separate command like "check_http_text" to differentiate it from the default "check_http" –  Mike Fiedler Jun 2 '09 at 13:40

You can set the following in the Nagios config too see what command is actually be executed ( see the expansion of the full command):

debug_level=-1
debug_verbosity=2
debug_file=/usr/local/nagios/var/nagios.debug
share|improve this answer
2  
Are these options available on nagios 2.11 or were they only introduced in nagios 3? –  Funky Si Jun 2 '09 at 14:02

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.