Q:

Avoiding Nagios commands.cfg

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!

A:

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.

