User-defined host/service attributes

John P. Rouillard rouilj at cs.umb.edu
Sat Oct 14 21:11:02 CEST 2006


In message <20061014152954.GH11651 at torres.l21.ma.zugschlus.de>,
Marc Haber writes:
>This, however, means that one has to have the DNS name of the host in
>the host_name field:
>
>define host {
>        use                     my-linux-host
>        host_name               ipdesc.iface.host.loc.mydomain.example
>        hostgroups              defaultping, snmp-w68, ssh, hostnameip
>        alias                   foo server running bar and baz services, col
>ocated in blu
>        address                 10.1.1.47
>        parents                 localhost
>}
>
>This is a bit clumsy since our host names are complicated and lengthy.
>
>I'd like to have something like
>
>define command {
>        command_name check_hostnameip
>        command_line $USER1$/check_dns --hostname=$CUSTOMATTR$ --expected-ad
>dress=$HOSTADDRESS$
>}
>
>define host {
>        use                     my-linux-host
>	host_name		host.mydomain.example
>        custom_attribute        ipdesc.iface.host.loc.mydomain.example
>        hostgroups              defaultping, snmp-w68, ssh, hostnameip
>        alias                   foo server running bar and baz services, col
>ocated in blu
>        address                 10.1.1.47
>        parents                 localhost
>}
>
>If this possible in Nagios2? If not, are there other ideas how to
>solve this?

Nagios 3.0 has native support for this. I use a simple wrapper script
and define things like:

define service{
        service_description     VpnExternalIFPingCheck
        hostgroup_name          vpn_ip
        use                     generic-service
        check_command           check_host_by_icmp!300,20%!500,40%!!`$USER1$/ge
t_custom_attributes $HOSTNAME$ VPN-IP`
        contact_groups          renesys-admins-nopage
        }

# 'check_host_via_icmp' command definition
define command{
        command_name    check_host_by_icmp
        command_line    $USER1$/check_icmp -w $ARG1$ -c $ARG2$ -n 2 $ARG3$ $ARG
4$
        }

with the custom attribute $HOSTNAME$-VPN-IP defined as comment in the host definition like:

  define host{
        host_name               example
        alias                   examplesite1
        address                 192.168.9.7
        parents                 sc01_site1
        use                     generic-host
  # custom_macro ops01-INSTALL-IP 192.168.9.10
  # custom_macro ops01-YUM-IP     192.168.97.11
  # custom_macro ops01-VPN-IP     169.184.83.10
        hostgroups              standard_services,standard_linux_services,linux
_prod_hosts,internal_hosts,mht1,3ware_raid,dhcp_testers,yum_hosts,install_hosts
,web_role,vpn_hosts,vpn_ip
        }

The get_custom_attributes script below goes in the plugins directory
($USER1$) and change HOSTFILES (files with host object definitons) to
a pattern that matches your installation:

#! /bin/sh

# this needs to run as fast as possible.
HOSTFILES="/etc/nagios/hosts/*.cfg"

# use cache file if present
# create cache file with:
#   grep -h custom_macro HOSTFILES > custom_macros.cache
# where HOSTFILES are the same files as specified above.
CACHEFILE="/etc/nagios/hosts/custom_macros.cache"

if [ -r $CACHEFILE ]; then
    FILES="$CACHEFILE"
else
    FILES="$HOSTFILES"
fi

# sed out lines of the form:
#  "# custom_macro HOST-VARIABLE VALUE" allowing arbitrary white space before
#  and after each token. Stripping white space from before (any maybe after)
#  the value. The sed command will exit on first match.
value=`sed -n -e "s/^[  ]*#[    ]*custom_macro[         ]*$1-$2[        ]*\([^ 
        ].*\)[  ]*$/\1/p" -e "t exit" -e "T" -e ":exit;q" $FILES`

if [ -z "$value" ]; then
  echo "'Unable to find $1-$2'"
else
  echo "$value"
fi


I keep all my nagios files under Config and when new hosts files are
pushed a simple command (grep custom_macro $HOSTFILES >
.../custom_macros.cache) updates the cache file on every host file
change.

				-- rouilj
John Rouillard
===========================================================================
My employers don't acknowledge my existence much less my opinions.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list