4

I'm very new to nagios, and trying to get a custom command to bend to my will.

I have looked through various examples, and can't find anyone appending the $HOSTADDRESS$ macro, so maybe I have to go about this a different route, but what I need, is to pass an argument to command that looks something like this:

HOST_ADDRESS/StatusCheck?auth=secretKey

Here is an example that works (for only 1 host)

define service {
    use                   generic-service
    hostgroup_name        my-hostgroup
    service_description   my custom check
    check_command         check_custom_status!http://example.com/StatusCheck?auth=secretKey
}

Obviously that doesn't work for me as it only checks a single host (example.com in this case).

Here is an example that doesn't work, but I wish it did, can I switch the syntax a bit to get this to work?

define service {
    use                   generic-service
    hostgroup_name        my-hostgroup
    service_description   my custom check
    check_command         check_custom_status!$HOSTADDRESS$/StatusCheck?auth=secretKey
}

(it doesn't check the /StatusCheck page). How do I append the $HOSTADDRESS$ macro?

I'm hoping there is a really easy fix for this, apologies if I overlooked something very simple.

Command Definition

define command {
    command_name    check_custom_status
    command_line    $USER1$/check_custom_status.pl -U $ARG1$
}

My perl script takes in a single url parameter (-U)

  • Can we see the command definition for check_custom_status? I have a suspicion, but I'd like to be sure before answering :) – Halfgaar Jul 8 '14 at 9:49
  • @Halfgaar I have added my command definition – Kyle Jul 8 '14 at 9:53
  • 1
    It's not what I thought. If it does connect to the host, but doesn't use the full URL, at least part of your argument is passed on. Can you write it to some tmp file in your perl script to see its contents. Also, what is your HOSTADDRESS? If its an IP address, it will probably not match the virtual host of the web server. – Halfgaar Jul 8 '14 at 9:58
  • @Halfgaar thanks for your help, I logged what was being passed in, turns out it was working fine, I just needed a http (i.e http://$HOSTADDRESS$/whatever), no protocol given when defining the host (facepalm). – Kyle Jul 8 '14 at 11:49
  • Glad you figured it out. I would put the http:// in the service definition. A host address should ideally really only be the address. – Halfgaar Jul 8 '14 at 12:02
2

You don't use macros in host and service definitions. You'd put the $HOSTADDRESS$ macro in the command definition if you want to use it.

The $HOSTADDRESS$ macro is already available to the command being run, along with dozens of other macros, because Nagios knows what host/service the command is associated with.

In your case, you'd probably want something this, where you pass the auth key in as ARG1:

define command {
    command_name    check_custom_status
    command_line    $USER1$/check_custom_status.pl -U http://$HOSTADDRESS$/StatusCheck?auth=$ARG1$
}

See the Macros and how they work and List of available macros docs pages to get an idea of how it all works.

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.