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!
  • As far as I know it's not possible. And what is profit?
    – ALex_hha
    Aug 26, 2013 at 10:33
  • Note that -u is not expecting a full URL, but rather a path like /index.html or similar. Also be sure to understand the distinction between -H and -I (and that you might need both in some cases).
    – Keith
    Aug 26, 2013 at 13:32

4 Answers 4


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.


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
  • looks pretty insecure. So anyone with local access can run any command with nagios privilege, tell me you are not running nagios as root.
    – DukeLion
    Aug 26, 2013 at 12:08
  • No, Nagios does not run as root. Nagios runs with significantly less privilege than any other local user. Not sure why this deserves a down-vote; it directly answers the question asked, and another user also posted this same answer and got an up-vote.
    – fredden
    Aug 26, 2013 at 19:33
  • idk, maybe it's because he warned not to use it.
    – DukeLion
    Aug 27, 2013 at 9:01

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

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.

  • Yep! I'd add that you can also do $USER1$/footest $ARG1$ if you don't have a reasonable ability to guess what parameters might be required; you can then use a check_command like footest!-b something -c something.
    – BMDan
    Aug 26, 2013 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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