Article Figure 1 Figure 2 Listing 1 Listing 2
Listing 3 Listing 4 Listing 5 Listing 6 dec2005.tar

Listing 2 This script provides the ability to create single services that check more than one port by wrapping around check_tcp, and check_udp.

#!/bin/bash
#call check_tcp once for each port. aggregate the result
#dave josephsen

HOME='/usr/local/nagios/libexec'
PROTO='Nullz0r'

printusage ()
{
echo "this plugin calls check_tcp once for each port"
echo "usage:"
echo "check_multi_tcp -H host -u|-t -p \"port [port] ...\"" 
echo "-h : print this message"
echo "-H hostname: The hostname of the box you want to query \
      (default localhost)"
echo "-p port number: A space seperated list of port numbers"
echo "-t wrap around check_tcp"
echo "-u wrap around check_udp"
exit ${EXITPROB}
}

while getopts ":hH:utp:" opt
do
        case $opt in
                h )     printusage;;
                H )     HOST=${OPTARG};;
                p )     PORT=${OPTARG};;
                u )     PROTO='udp';;
                t )     PROTO='tcp';;
                ? )     printusage;;
        esac
done

if echo "${PROTO}" | fgrep -q 'Nullz0r'
then
   echo "ERROR: either -u or -t required" 
   echo
   printusage
fi

for i in `echo ${PORT}`
do
   ${HOME}/check_${PROTO} -H ${HOST} -p ${i}>/dev/null
   if [ "$?" -ne 0 ]
   then
      echo "port ${PROTO}/$i is not open"
      exit 2
   fi
done

echo "all ports are open"
exit 0