1#!@@GOODSH@@ 2# -*- sh -*- 3 4: << =cut 5 6=head1 NAME 7 8ping_ - Plugin to monitor ping times 9 10=head1 CONFIGURATION 11 12The following environment variables are used by this plugin 13 14 ping_args - Arguments to ping (default "-c 2") 15 ping_args2 - Arguments after the host name (required for Solaris) 16 ping - Ping program to use 17 host - Host to ping. By default taken from command name. 18 ping_warn - Warning limit for nagios notification 19 ping_crit - Critical limit for nagios notification 20 packetloss_warn - Warning limit for nagios notification 21 packetloss_crit - Critical limit for nagios notification 22 23=head2 CONFIGURATION EXAMPLES 24 25The following configuration should be used for solaris hosts: 26 27 [ping_*] 28 env.ping_args -s 29 env.ping_args2 56 2 30 31=head1 AUTHOR 32 33Copyright (C) 2004 Jimmy Olsen 34 35=head1 LICENSE 36 37This program is free software; you can redistribute it and/or modify 38it under the terms of the GNU General Public License as published by 39the Free Software Foundation; version 2 dated June, 1991. 40 41This program is distributed in the hope that it will be useful, but 42WITHOUT ANY WARRANTY; without even the implied warranty of 43MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 44General Public License for more details. 45 46You should have received a copy of the GNU General Public License 47along with this program; if not, write to the Free Software 48Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 4902110-1301 USA. 50 51=head1 MAGIC MARKERS 52 53 #%# family=manual 54 55=cut 56 57# shellcheck disable=SC1090 58. "$MUNIN_LIBDIR/plugins/plugin.sh" 59 60case $0 in 61 *ping6_*) 62 # use "ping6" if available - otherwise fall back to "ping" 63 if command -v ping6 >/dev/null; then 64 ping_func() { ping6 "$@"; } 65 else 66 ping_func() { ping -6 "$@"; } 67 fi 68 file_host=${0##*/ping6_} 69 V=IPv6 70 ;; 71 *ping_*) 72 if command -v ping4 >/dev/null; then 73 ping_func() { ping4 "$@"; } 74 else 75 # Some implementations (e.g. "inetutils-ping") do not support the "-4" argument. 76 # This careful approach sadly prohibits the explicit selection of the IPv4 address 77 # family. Thus we are just hoping for the best (as this plugin always did). 78 ping_func() { ping "$@"; } 79 fi 80 file_host=${0##*/ping_} 81 V=IPv4 82 ;; 83esac 84 85host=${host:-${file_host:-www.google.com}} 86if [ -n "${ping:-}" ]; then 87 ping_func() { "$ping" "$@"; } 88fi 89 90if [ "$1" = "config" ]; then 91 echo "graph_title $V ping times to $host" 92 echo 'graph_args --base 1000 -l 0' 93 echo 'graph_vlabel roundtrip time (seconds)' 94 echo 'graph_category network' 95 echo 'graph_info This graph shows ping RTT statistics.' 96 echo "ping.label $host" 97 echo "ping.info Ping RTT statistics for $host." 98 echo 'packetloss.label packet loss' 99 echo 'packetloss.graph no' 100 print_warning ping 101 print_warning packetloss 102 print_critical ping 103 print_critical packetloss 104 exit 0 105fi 106 107 108# shellcheck disable=SC2086 109ping_func ${ping_args:-'-c 2'} "${host}" ${ping_args2:-} \ 110 | perl -n -e 'print "ping.value ", $1 / 1000, "\n" if m@min/avg/max.*\s\d+(?:\.\d+)?/(\d+(?:\.\d+)?)/\d+(?:\.\d+)?@; print "packetloss.value $1\n" if /(\d+)% packet loss/;' 111