User defined variables and check configuration

Hi everyone,
we have a number of servers that we’re monitoring with Nagios 3.04 - linux, windows and netware.

What I’m trying to do is setup generic checks for each type of server - for example, for the linux servers I’d like to check the CPU load and alert if its above a certain level, but I need a different level for each server. For example, I might have server1, server2 and server3 each of which run with different loads.

What I’ve tried is setting up the hosts as below:

define host{
use linux-server
host_name server1
alias server1.domain
_load_warning 5,5,5
_load_critical 10,8,8
}

define host{
use linux-server
host_name server2
alias server2.domain
_load_warning 9,7,7
_load_critical 12,11,11
}

Then in I’ve setup a hostgroup

define hostgroup{
hostgroup_name linux-servers
members server1, server2
}

and setup a check

define service{
use generic-service;
service_description Current Load
hostgroup_name linux-servers
check_command check_linux_load
}

and finally in commands.cfg I’ve added

# ‘check_linux_load’ command definition
define command{
command_name check_linux_load
command_line $USER1$/check_snmp_load.pl -H $HOSTNAME$ -C public -w $_HOSTload_warning$ -c $_HOSTload_critical$ -Tnetsl
}

however, this doesn’t work - it doesn’t seem to recognise the variables.

Should I be able to do something like this or am I just making a silly mistake somewhere?

Thanks,
Simon

What do you get when you try to run the command from the terminal?
Post nagios log errors here also. I don’t see anything wierd here, it should work, but more information could be helpful.
Have you reloaded Nagios configuration?

Albin and all,
sorry for not getting back earlier - have been busy on other stuff.

It looks like I’m not using the variables properly - I’ve setup a simple command in commands.cfg:

# ‘check_echo’ command definition
define command{
command_name check_echo
command_line echo "Arg1 = " $HOST_load_warning$ " Arg2 = " $_HOST_load_warning$
}

and when this runs with the above host configuration, I get the output

Arg1 = $ Arg2 = $

Looking in the nagios.debug file, I have the following section:

*[1225711587.205063] [2048.1] [pid=581] **** BEGIN MACRO PROCESSING ***********
[1225711587.205068] [2048.1] [pid=581] Processing: ‘echo "Arg1 = " $HOST_load_warning$ " Arg2 = " $_HOST_load_warning$’
[1225711587.205075] [2048.2] [pid=581] Processing part: 'echo "Arg1 = " '
[1225711587.205081] [2048.2] [pid=581] Not currently in macro. Running output (15): 'echo "Arg1 = " '
[1225711587.205087] [2048.2] [pid=581] Processing part: ‘HOST_load_warning’
[1225711587.205095] [2048.0] [pid=581] WARNING: Could not find a macro matching ‘HOST_load_warning’!
[1225711587.205101] [2048.2] [pid=581] Processed ‘HOST_load_warning’, Clean Options: 0, Free: 1
[1225711587.205107] [2048.0] [pid=581] WARNING: An error occurred processing macro ‘HOST_load_warning’!
[1225711587.205114] [2048.2] [pid=581] Non-macro. Running output (15): 'echo "Arg1 = " '
[1225711587.205131] [2048.2] [pid=581] Processing part: ’ " Arg2 = " '
[1225711587.205138] [2048.2] [pid=581] Not currently in macro. Running output (45): 'echo "Arg1 = " $HOST_load_warning$ " Arg2 = " '
[1225711587.205145] [2048.2] [pid=581] Processing part: ‘_HOST_load_warning’
[1225711587.205153] [2048.2] [pid=581] Processed ‘_HOST_load_warning’, Clean Options: 0, Free: 1
[1225711587.205159] [2048.0] [pid=581] WARNING: An error occurred processing macro ‘_HOST_load_warning’!
[1225711587.205166] [2048.2] [pid=581] Non-macro. Running output (45): 'echo "Arg1 = " $HOST_load_warning$ " Arg2 = " '
[1225711587.205173] [2048.2] [pid=581] Processing part: ‘’
[1225711587.205179] [2048.2] [pid=581] Not currently in macro. Running output (64): ‘echo "Arg1 = " $HOST_load_warning$ " Arg2 = " $_HOST_load_warning$’
[1225711587.205186] [2048.1] [pid=581] Done. Final output: ‘echo "Arg1 = " $HOST_load_warning$ " Arg2 = " $_HOST_load_warning$’
[1225711587.205192] [2048.1] [pid=581] **** END MACRO PROCESSING **************

which to me, looks like its not recognising the syntax to use the _HOST variable.

I would suggest you to make the echo command definition like this:

# 'check_echo' command definition define command{ command_name check_echo command_line echo "Arg1 = " $ARG1$ " Arg2 = " $ARG2$ }
And then, under the service definition you use:

check_command    check_echo!$_HOSTLOAD_WARNING$!$_HOSTLOAD_CRITICAL$

Try to use the syntax exactly like on the documentation pages:
nagios.sourceforge.net/docs/3_0/ … tvars.html
With this I’ve meant the capital letters.

Although you have mistyped your macros in this row:
[blockquote]command_line echo "Arg1 = " $HOST_load_warning$ " Arg2 = " $HOST_load_warning$[/blockquote]
First one doesn’t have the leading underscore character **
** and both of them have underscore character between HOST and variable_name which they shoudn’t.

Albin,
using uppercase characters seems to have fixed it - despite the nagios docs page saying the variable names are case insensitive :frowning:

Thanks for your help with this!