X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=plugins.d%2Ffping.plugin;h=232c00630f6992a29ce296c5bc14679077516470;hb=HEAD;hp=32e1b711444f34584e9a3380ad6f8b4862cbe244;hpb=7e5402d248b63c9ab62996d80184f0e5bd776b70;p=netdata.git diff --git a/plugins.d/fping.plugin b/plugins.d/fping.plugin index 32e1b711..232c0063 100755 --- a/plugins.d/fping.plugin +++ b/plugins.d/fping.plugin @@ -5,26 +5,85 @@ # (C) 2016 Costa Tsaousis # GPL v3+ # -# This plugin requires a special version of fping. -# Get it from https://github.com/ktsaou/fping -# and build it, like this: -# -# cd /usr/src -# git clone https://github.com/ktsaou/fping.git fping-netdata.git -# cd fping-netdata.git -# ./autogen.sh -# ./configure --prefix=/usr/local -# make -# cp src/fping /usr/local/bin/ -# chown root:root /usr/local/bin/fping -# chmod 4755 /usr/local/bin/fping -# -# Then, create /etc/netdata/fping.conf -# and set the configuration options given below +# This plugin requires a latest version of fping. +# You can compile it from source, by running me with option: install export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin" export LC_ALL=C +if [ "${1}" = "install" ] + then + [ "${UID}" != 0 ] && echo >&2 "Please run me as root. This will install a single binary file: /usr/local/bin/fping." && exit 1 + + run() { + printf >&2 " > " + printf >&2 "%q " "${@}" + printf >&2 "\n" + "${@}" || exit 1 + } + + download() { + local curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)" + [ ! -z "${curl}" ] && run curl -s -L "${1}" && return 0 + + local wget="$(which wget 2>/dev/null || command -v wget 2>/dev/null)" + [ ! -z "${wget}" ] && run wget -q -O - "${1}" && return 0 + + echo >&2 "Cannot find 'curl' or 'wget' in this system." && exit 1 + } + + [ ! -d /usr/src ] && run mkdir -p /usr/src + [ ! -d /usr/local/bin ] && run mkdir -p /usr/local/bin + + run cd /usr/src + + if [ -d fping-3.15 ] + then + run rm -rf fping-3.15 || exit 1 + fi + + download 'https://github.com/schweikert/fping/archive/3.15.tar.gz' | run tar -zxvpf - + [ $? -ne 0 ] && exit 1 + run cd fping-3.15 || exit 1 + + #if [ -d fping-ktsaou.git ] + # then + # run cd fping-ktsaou.git + # run git pull + #else + # run git clone https://github.com/ktsaou/fping.git fping-ktsaou.git + # run cd fping-ktsaou.git + #fi + + run ./autogen.sh + run ./configure --prefix=/usr/local + run make clean + run make + if [ -f /usr/local/bin/fping ] + then + run mv -f /usr/local/bin/fping /usr/local/bin/fping.old + fi + run mv src/fping /usr/local/bin/fping + run chown root:root /usr/local/bin/fping + run chmod 4755 /usr/local/bin/fping + echo >&2 + echo >&2 "All done, you have a compatible fping now at /usr/local/bin/fping." + echo >&2 + + fping="$(which fping 2>/dev/null || command -v fping 2>/dev/null)" + if [ "${fping}" != "/usr/local/bin/fping" ] + then + echo >&2 "You have another fping installed at: ${fping}." + echo >&2 "Please set:" + echo >&2 + echo >&2 " fping=\"/usr/local/bin/fping\"" + echo >&2 + echo >&2 "at /etc/netdata/fping.conf" + echo >&2 + fi + exit 0 +fi + # ----------------------------------------------------------------------------- PROGRAM_NAME="$(basename "${0}")" @@ -64,6 +123,14 @@ debug() { [ $debug -eq 1 ] && log DEBUG "${@}" } +# ----------------------------------------------------------------------------- + +# store in ${plugin} the name we run under +# this allows us to copy/link fping.plugin under a different name +# to have multiple fping plugins running with different settings +plugin="${PROGRAM_NAME/.plugin/}" + + # ----------------------------------------------------------------------------- # the frequency to send info to netdata @@ -79,41 +146,49 @@ NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}" # can be overwritten at /etc/netdata/fping.conf # the fping binary to use -# we need one that can output netdata friendly info -fping="$(which fping || command -v fping)" +# we need one that can output netdata friendly info (supporting: -N) +# if you have multiple versions, put here the full filename of the right one +fping="$( which fping 2>/dev/null || command -v fping 2>/dev/null )" # a space separated list of hosts to fping +# we suggest to put names here and the IPs of these names in /etc/hosts hosts="" # the time in milliseconds (1 sec = 1000 ms) -# to ping the hosts - by default 2 pings per iteration -ping_every="$((update_every * 1000 / 2))" +# to ping the hosts - by default 5 pings per host per iteration +ping_every="$((update_every * 1000 / 5))" -# how many retries to make if a host does not respond -retries=1 +# fping options +fping_opts="-R -b 56 -i 1 -r 0 -t 5000" # ----------------------------------------------------------------------------- # load the configuration file -if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ] +if [ ! -f "${NETDATA_CONFIG_DIR}/${plugin}.conf" ] then - fatal "configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do." + fatal "configuration file '${NETDATA_CONFIG_DIR}/${plugin}.conf' not found - nothing to do." fi -source "${NETDATA_CONFIG_DIR}/fping.conf" +source "${NETDATA_CONFIG_DIR}/${plugin}.conf" if [ -z "${hosts}" ] then - fatal "no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do." + fatal "no hosts configued in '${NETDATA_CONFIG_DIR}/${plugin}.conf' - nothing to do." fi if [ -z "${fping}" -o ! -x "${fping}" ] then - fatal "command '${fping}' is not executable - cannot proceed." + fatal "command '${fping}' is not found or is not executable - cannot proceed." +fi + +if [ ${ping_every} -lt 20 ] + then + warning "ping every was set to ${ping_every} but 20 is the minimum for non-root users. Setting it to 20 ms." + ping_every=20 fi # the fping options we will use -options=( -N -l -R -Q ${update_every} -p ${ping_every} -r ${retries} ${hosts} ) +options=( -N -l -Q ${update_every} -p ${ping_every} ${fping_opts} ${hosts} ) # execute fping exec "${fping}" "${options[@]}"