Custom nagios command, append $HOSTADDRESS$

nagios

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)

Best Answer

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.

Related Topic