Several Servers hidden behind single IP

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
tkircht
Posts: 4
Joined: Fri Oct 07, 2011 5:16 am

Several Servers hidden behind single IP

Post by tkircht »

We have several customers that hide more than one (Windows/NSClient++) server behind one single IP-address. What I usually do in these cases is forward increasing port numbers to those hosts (12489-> HostA, 12490->HostB, 12491->HostC, etc.). On the Nagios side I need to create a service definition for every combination of portnumber and service ( one for CPULOAD at 12489, CPULOAD at 12490, etc.) which tends to fill the service-definitions-file with a bunch of definition entries.

Can anybody stir me towards a better (i.e. more readable and manageable) setup for this problem? I'd love a way to pass the port number to the host definition and use a generic definition for each service. I feel like I could add the port number to the host address (12.34.56.78:1290) but am at a loss on how to parse this in the command definition.

Any ideas for me there?

Thanks for any hints!

Thomas
tkircht
Posts: 4
Joined: Fri Oct 07, 2011 5:16 am

Re: Several Servers hidden behind single IP

Post by tkircht »

I guess I solved it myself - was rather straightforward even. Just in case anyone needs this... Feel free to comment if you see something you don't like...

Parser script:

Code: Select all

  1 #!/bin/bash
  2 # check_parse_nt
  3 # parses socket and executes check_nt
  4 # Thomas Kirchtag 2011
  5
  6 #
  7 FULLADDRESS="${1}"
  8 shift
  9
 10 IPADDRESS="${FULLADDRESS%:*}"
 11 PORTNUMBER="${FULLADDRESS#*:}"
 12 CHECK_NT="/usr/lib/nagios/plugins/check_nt"
 13 $CHECK_NT -H "${IPADDRESS}" -p "${PORTNUMBER}" "$@"
command definitions:

Code: Select all

define command {
  command_name  check-nt-variable
  command_line $USER1$/check_parse_nt $HOSTADDRESS$ -v $ARG1$ $ARG2$
}

define command {
  command_name  check-host-alive-nt-variable
  command_line  $USER1$/check_parse_nt  $HOSTADDRESS$ -v CLIENTVERSION $ARG1$ $ARG2$
}
Host template:

Code: Select all

# Generic NSClient-Host
define host{
        use                             generic-host;
        name                            nsclient-host-variable    ; The name of this host template
        check_command                   check-host-alive-nt-variable!CLIENTVERSION! -p12490 -s Password
        hostgroups                      windows-servers,NSClient-Servers-variable
        register                        0       ; 
        }
Sample host definition:

Code: Select all

define host {
  use nsclient-host-variable;
  host_name 0000-002-IP-W2K8R2-03;
  address  123.45.67.17:12490;
  check_command check-host-alive-nt-variable
}
Service template:

Code: Select all

define service {
    use                             generic-service
    name                            nsclient-service
    notification_interval           0 ; set > 0 if you want to be renotified
    max_check_attempts              3
    register                        0
 }
Sample service definition:

Code: Select all

define service {
        use                             nsclient-service
        hostgroup_name                  NSClient-Firewall-2K8-variable
        service_description             Firewall
        check_command                   check-nt-variable!SERVICESTATE!-l 'MpsSvc'  -s Password 
}
JenyZ
Posts: 1
Joined: Sun Oct 09, 2011 9:35 pm

Re: Several Servers hidden behind single IP

Post by JenyZ »

I actually found this very helpful....kinda a newbie with php, talk about mind boggling, but am enjoying all the techie language!
tkircht
Posts: 4
Joined: Fri Oct 07, 2011 5:16 am

Re: Several Servers hidden behind single IP

Post by tkircht »

Well, seeing that somebody (Hi Jeny!) is actually reading this I have to admit that I threw that solution into the garbage bin already. The clean way to solve this problem of course uses user-defined macros and good host templates. I now have all my host specific information like port numbers, urls etc in my host definitions and address these macros from within my command.cfg. Just a small sample - tell me if you need more:

Code: Select all

 define host {
   use nsclient-host-variable;
   host_name 0000-002-IP-W2K8R2-03;
   address  12.34.56.17;
   _NSCP_PORT  12490;
   _NSCP_PW  topsecret;
   check_command check-host-alive-nt-variable
   hostgroups +NSClient-AD-2K8,NSClient-Firewall-2K8
 }

Code: Select all

 define command {
   command_name  check-nt-variable
   command_line $USER1$/check_nt -H $HOSTADDRESS$ -p $_HOSTNSCP_PORT$ -s $_HOSTNSCP_PW$ -v $ARG1$ $ARG2$
 }
Locked