Nagios Custom Object Variables

In large Nagios environments, configuring everything at the host level can be cumbesome.  Nagios has nice grouping / templating features that make deploying checks alot faster as well as easier to manager.  Sometimes you may need to "customize" the check to the specific host.  For example, specify the databasename on the indivudal database server to query.  This is where Nagios "Custom Object Variables" come into play.

As always, you can find some very useful information in the Nagios documentation.

In my case, we will start with defining the custom object variable on the host object by adding a like in the "define host {" block like so:

define host{
        use             server-template
        host_name       dbserver1
        alias           DB Server 1
        address         dbserver1.domain.local
        _DATABASE1              DB01

I have a hostgroup definition for "Database Servers" and a list of common checks for each database server.  You can see how I have my Nagios check configured to use the local variable in the hostgroup definition....

define hostgroup{
        hostgroup_name  database-servers
        alias           Database Servers
        members         dbserver1,dbserver2,dbserver3
define service{
        use                     template
        hostgroup_name          database-servers
        service_description     database-test
        check_command           check_mssql!username!password!-p 1433 -D \
                                $_HOSTDATABASE1$ -w 3 -c 5 -q "exec \
                                $_HOSTDATABASE1$.dbo.sp_test" -s -W 10 -C 20

Note that the backslashes are only for readability here, and the check is a single line in my definition.

Remeber when using the custom variables, they always start with the underscore and then prefixed with the type of variable... HOST, SERVICE, CONTACT, etc.