check_ssh and host definitions

Hello, first off let me apologize for asking something that I’m sure has been addressed before, I’ve just been unable to find any information using searches.
Anyways, the situation is that I have a large number of servers sitting behind a VPN router (read: NAT) and I need to run the check_ssh command on each of them. Currently, to get to ssh, we have port forwarding rules set up on the VPN router such that each server gets its own external ssh port (e.g. 111.222.1.123:2201 is the ssh port for one server while 111.222.1.123:2202 is another server). If I understand things correctly (I’m new at this) this means I’d have to create a separate check_ssh_port command for each server. What I’m hoping is possible is that I can put a new piece of information into the host definition somewhere so that I don’t have to define a new service for each server. Is this possible?
To make matters worse, I have many services that are in a similar situation.

check how to use macros in the documentation…

you can pass an extra parameter to check_ssh… you will need to create a new check command which passes the port number as parameter :wink:

Ah, this was exactly what I was looking for. Many thanks.

nagios.sourceforge.net/docs/3_0/macros.html

example 2 is what you need :wink:

Just in case anyone ever wanders across this, I did the following:

  1. For each host I have defined a “custom object variable” (see: nagios.sourceforge.net/docs/3_0/ … tvars.html) called _ssh_port.
  2. I created a custom check_ssh command which I called check_ssh_port. The only difference between this version and the standard check_ssh was that I added “-p $HOSTSSH_PORT$” to the command.
  3. I created a service that used my new command and restarted Nagios, success!