]> arthur.barton.de Git - netdata.git/commitdiff
add fping.plugin; fixes #1122
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 16 Oct 2016 00:35:27 +0000 (03:35 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 16 Oct 2016 00:35:27 +0000 (03:35 +0300)
plugins.d/Makefile.am
plugins.d/fping.plugin [new file with mode: 0755]

index 4bc0dc4471fe290794c421527ae4f6da8069853c..326192f8f193fb93f0ccb1dc22aeae35dcefa177 100644 (file)
@@ -13,6 +13,7 @@ dist_plugins_SCRIPTS = \
        cgroup-name.sh \
        charts.d.dryrun-helper.sh \
        charts.d.plugin \
+       fping.plugin \
        node.d.plugin \
        python.d.plugin \
        tc-qos-helper.sh \
diff --git a/plugins.d/fping.plugin b/plugins.d/fping.plugin
new file mode 100755 (executable)
index 0000000..fa3b62f
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/env bash
+
+me="${0}"
+
+# the frequency to send info to netdata
+# passed by netdata as the first parameter
+update_every="${1-1}"
+
+# the netdata configuration directory
+# passed by netdata as an environment variable
+NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
+
+# -----------------------------------------------------------------------------
+
+# 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
+
+# -----------------------------------------------------------------------------
+# configuration options
+# 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)"
+
+# a space separated list of hosts to fping
+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))"
+
+# how many retries to make if a host does not respond
+retries=1
+
+# -----------------------------------------------------------------------------
+
+# load the configuration file
+if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ]
+then
+       echo >&2 "${me}: configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
+       echo "DISABLE"
+       exit 1
+fi
+
+source "${NETDATA_CONFIG_DIR}/fping.conf"
+
+if [ -z "${hosts}" ]
+then
+       echo >&2 "${me}: no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
+       echo "DISABLE"
+       exit 1
+fi
+
+if [ -z "${fping}" -o ! -x "${fping}" ]
+then
+       echo >&2 "${me}: command '${fping}' is not executable - cannot proceed."
+       echo "DISABLE"
+       exit 1
+fi
+
+# the fping options we will use
+options=( -N -l -R -Q ${update_every} -p ${ping_every} -r ${retries} ${hosts} )
+
+# execute fping
+exec "${fping}" "${options[@]}"
+
+# if we cannot execute fping, stop
+echo >&2 "${me}: command '${fping} ${options[@]}' failed to be executed."
+echo "DISABLE"
+exit 1