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 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!
share|improve this question
    
As far as I know it's not possible. And what is profit? –  ALex_hha Aug 26 '13 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 '13 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.

share|improve this answer

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
}
share|improve this answer
    
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 '13 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 '13 at 19:33
    
idk, maybe it's because he warned not to use it. –  DukeLion Aug 27 '13 at 9:01

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.

share|improve this answer
    
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 '13 at 13:24

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

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.