[Nagiosplug-devel] Ping multiple IP addresses

Gabriel Somlo somlo at acns.colostate.edu
Wed Dec 15 21:04:03 CET 2004


Hey,

I needed to figure out when our connectivity to the Net is down (e.g.,
to determine whether it's worth sending an alert to something like 
<cellphone-number>@provider.net

If our outside connectivity is down, these pages won't make it through
and I need to use a modem-dialer to deliver the pages.

So, I came up with a plugin that pages multiple hosts or IP addresses
and has warning and critical thresholds on how many of them must be
'up' before I call our outside connectivity 'down'.

Do you guys think this might be a worthwhile addition to the
nagios-plugins package ? Should I rewrite it in C, or is it good
enough as a shell script ?

Please let me know what you think. Cc me on followups, or tell me to
quit whining and subscribe to the list :)

Thanks,
Gabriel

-----------begin multiping script-------------------------------------

#!/bin/bash

#
# multiping -- ping a list of hosts for Nagios
# Gabriel L. Somlo, 2004-12-15
#

print_usage () {
  echo
  echo "Usage:  $0 HOST[:HOST[:HOST...]] <#warn> <#crit>"
  echo
  echo "   First arg. is a colon-separated list of HOSTs to ping"
  echo "   Second arg. is the warning threshold"
  echo "   Third arg. is the critical threshold"
  echo "      Note: #warn > #crit !"
  echo
}

# check presence of required arguments
if [ -z "${1}" -o -z "${2}" -o -z "${3}" ]; then
  print_usage
  exit 1
fi

# check validity of #warn and #crit thresholds
if ((${2}<=${3})); then
  print_usage
  exit 2
fi

# count total hosts and 'up' hosts
let TOTAL=0 UP=0
for H in $(echo "${1}" | tr ':' ' '); do
  ping -qc1 ${H} > /dev/null 2>&1
  if [ "${?}" == "0" ]; then
    let UP++
  fi
  let TOTAL++
done

# print results
if ((UP>${2})); then
  echo "MULTIPING OK - up ${UP}/${TOTAL}"
elif ((UP>${3})); then
  echo "MULTIPING WARNING - up ${UP}/${TOTAL}"
else
  echo "MULTIPING CRITICAL - up ${UP}/${TOTAL}"
fi

-----------end multiping script----------------------------------------
-- 
-----------------------------------------------------------------------
Gabriel L. Somlo               Academic Computing & Networking Services
Colorado State University      Tel: (970)297-3707   Cell: (970)567-1017
601 Howes St., Room 619C       Fax: (970)491-1958 
Fort Collins, CO 80523-2028 e-mail: somlo at acns dot colostate dot edu
-----------------------------------------------------------------------




More information about the Devel mailing list