Avoiding Nagios commands.cfg
Written by: J Dawg
Nagios comes with a set of pre-installed check commands. They are installed at /usr/libexec/nagios or /usr/local/nagios/libexec (anyway, the $USER1$ is expanded to the right place)
In that folder you can find several check_whatever commands, most of them are binary files, some are shell or perl scripts.
If there is not a suitable check program to a special service in your site you can write one and drop it in that folder. After that just add a definition to it, just like above.
I want to call a command directly from a Nagios service file, instead of passing arguments clumsily to commands.cfg. For example I want do this:
define service { service_description footest check_command $USER1$/check_http example.com -u http://example.com/index.html use generic-service host_name example }
But I get a:
Error: Service check command '/usr/share/nagios/libexec/check_http example.com -u http://example.com/index.html' specified in service 'footest' for host 'example' not defined anywhere!
If you absolutely insist on doing this, which is a really, really terrible idea, this snippet should work:
define command { command_name check_by_arbitrary_path check_command /bin/sh -c "$ARG1$" } define service { use remote-service host_name example service_description This is a bad idea, seriously check_command check_by_arbitrary_path!$USER1$/check_http example.com -u http://example.com/index.html }
Seriously, though, please don’t.
Nagios best practice is to split your check into a command and check, a check_command is defined as a command like
define command {
command_name footest
command_line $USER1$/footest -a some-fixed-option -b $ARG1$ -c $ARG2$
}
before it should be used in a service check.
I have had success with a check_any command definition in commands.cfg
define command {
command_name check_any
command_line $USER1$/check_$ARG1$
}
Which I use in a definition like:
define service { service_description Forest is not on fire check_command check_any!forest --on-fire=false use generic-service host_name example }
You need to break it into two parts, the first the check_command and the second the check itself.
Create the template to check a URL:
define command {
command_name check_http_url
command_line $USER1$/check_http -I'$HOSTADDRESS$' -u '$ARG1$'
}
Use the template to check a specific URL (www.example.com in this case):
define service { host_name example service_description Check www.example.com URL check_command check_http_url!www.example.com use generic-service }
Leave a Reply
You must be logged in to post a comment.