]> arthur.barton.de Git - netdata.git/blob - plugins.d/fping.plugin
Merge remote-tracking branch 'firehol/master'
[netdata.git] / plugins.d / fping.plugin
1 #!/usr/bin/env bash
2
3 # netdata
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6 # GPL v3+
7 #
8 # This plugin requires a special version of fping.
9 # Get it from https://github.com/ktsaou/fping
10 # and build it, like this:
11 #
12 # cd /usr/src
13 # git clone https://github.com/ktsaou/fping.git fping-netdata.git
14 # cd fping-netdata.git
15 # ./autogen.sh
16 # ./configure --prefix=/usr/local
17 # make
18 # cp src/fping /usr/local/bin/
19 # chown root:root /usr/local/bin/fping
20 # chmod 4755 /usr/local/bin/fping
21 #
22 # Then, create /etc/netdata/fping.conf
23 # and set the configuration options given below
24
25 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
26 export LC_ALL=C
27
28 # -----------------------------------------------------------------------------
29
30 PROGRAM_NAME="$(basename "${0}")"
31
32 logdate() {
33     date "+%Y-%m-%d %H:%M:%S"
34 }
35
36 log() {
37     local status="${1}"
38     shift
39
40     echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
41
42 }
43
44 warning() {
45     log WARNING "${@}"
46 }
47
48 error() {
49     log ERROR "${@}"
50 }
51
52 info() {
53     log INFO "${@}"
54 }
55
56 fatal() {
57     log FATAL "${@}"
58         echo "DISABLE"
59     exit 1
60 }
61
62 debug=0
63 debug() {
64     [ $debug -eq 1 ] && log DEBUG "${@}"
65 }
66
67 # -----------------------------------------------------------------------------
68
69 # the frequency to send info to netdata
70 # passed by netdata as the first parameter
71 update_every="${1-1}"
72
73 # the netdata configuration directory
74 # passed by netdata as an environment variable
75 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
76
77 # -----------------------------------------------------------------------------
78 # configuration options
79 # can be overwritten at /etc/netdata/fping.conf
80
81 # the fping binary to use
82 # we need one that can output netdata friendly info (supporting: -N)
83 # if you have multiple versions, put here the full filename of the right one
84 fping="$( which fping 2>/dev/null || command -v fping 2>/dev/null )"
85
86 # a space separated list of hosts to fping
87 # we suggest to put names here and the IPs of these names in /etc/hosts
88 hosts=""
89
90 # the time in milliseconds (1 sec = 1000 ms)
91 # to ping the hosts - by default 5 pings per host per iteration
92 ping_every="$((update_every * 1000 / 5))"
93
94 # other fping options
95 other_opts="-R -i 10 -r 0"
96
97 # -----------------------------------------------------------------------------
98 # load the configuration file
99
100 if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ]
101 then
102         fatal "configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
103 fi
104
105 source "${NETDATA_CONFIG_DIR}/fping.conf"
106
107 if [ -z "${hosts}" ]
108 then
109         fatal "no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
110 fi
111
112 if [ -z "${fping}" -o ! -x "${fping}" ]
113 then
114         fatal "command '${fping}' is not executable - cannot proceed."
115 fi
116
117 if [ ${ping_every} -lt 20 ]
118     then
119     warning "ping every was set to ${ping_every} but 20 is the minimum for non-root users. Setting it to 20 ms."
120     ping_every=20
121 fi
122
123 # the fping options we will use
124 options=( -N -l -Q ${update_every} -p ${ping_every} ${other_opts} ${hosts} )
125
126 # execute fping
127 exec "${fping}" "${options[@]}"
128
129 # if we cannot execute fping, stop
130 fatal "command '${fping} ${options[@]}' failed to be executed."