]> arthur.barton.de Git - netdata.git/blob - plugins.d/fping.plugin
add fping.plugin; fixes #1122
[netdata.git] / plugins.d / fping.plugin
1 #!/usr/bin/env bash
2
3 me="${0}"
4
5 # the frequency to send info to netdata
6 # passed by netdata as the first parameter
7 update_every="${1-1}"
8
9 # the netdata configuration directory
10 # passed by netdata as an environment variable
11 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
12
13 # -----------------------------------------------------------------------------
14
15 # This plugin requires a special version of fping.
16 # Get it from https://github.com/ktsaou/fping
17 # and build it, like this:
18 #
19 # cd /usr/src
20 # git clone https://github.com/ktsaou/fping.git fping-netdata.git
21 # cd fping-netdata.git
22 # ./autogen.sh
23 # ./configure --prefix=/usr/local
24 # make
25 # cp src/fping /usr/local/bin/
26 # chown root:root /usr/local/bin/fping
27 # chmod 4755 /usr/local/bin/fping
28 #
29 # Then, create /etc/netdata/fping.conf
30 # and set the configuration options given below
31
32 # -----------------------------------------------------------------------------
33 # configuration options
34 # can be overwritten at /etc/netdata/fping.conf
35
36 # the fping binary to use
37 # we need one that can output netdata friendly info
38 fping="$(which fping || command -v fping)"
39
40 # a space separated list of hosts to fping
41 hosts=""
42
43 # the time in milliseconds (1 sec = 1000 ms)
44 # to ping the hosts - by default 2 pings per iteration
45 ping_every="$((update_every * 1000 / 2))"
46
47 # how many retries to make if a host does not respond
48 retries=1
49
50 # -----------------------------------------------------------------------------
51
52 # load the configuration file
53 if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ]
54 then
55         echo >&2 "${me}: configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
56         echo "DISABLE"
57         exit 1
58 fi
59
60 source "${NETDATA_CONFIG_DIR}/fping.conf"
61
62 if [ -z "${hosts}" ]
63 then
64         echo >&2 "${me}: no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
65         echo "DISABLE"
66         exit 1
67 fi
68
69 if [ -z "${fping}" -o ! -x "${fping}" ]
70 then
71         echo >&2 "${me}: command '${fping}' is not executable - cannot proceed."
72         echo "DISABLE"
73         exit 1
74 fi
75
76 # the fping options we will use
77 options=( -N -l -R -Q ${update_every} -p ${ping_every} -r ${retries} ${hosts} )
78
79 # execute fping
80 exec "${fping}" "${options[@]}"
81
82 # if we cannot execute fping, stop
83 echo >&2 "${me}: command '${fping} ${options[@]}' failed to be executed."
84 echo "DISABLE"
85 exit 1