-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
fastpinger
executable file
·49 lines (43 loc) · 1.79 KB
/
fastpinger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# Copyright (C) 2018 Mehdi Abaakouk <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
export SITENAME=$(id -un)
. /omd/sites/${SITENAME}/etc/fastchecker.conf
[ ! "$BASE_DIR" ] && { echo "BASE_DIR is unset, please fill ~/etc/fastchecker.conf"; exit 1; }
. $BASE_DIR/paths.conf
DATE=$(date '+%Y%m%d/%H/fastpinger.dump.%Y%m%d-%H%M%S')
FASTPINGER_ARCHIVE="${FASTPINGER_VARPATH}/${DATE}"
FASTPINGER_DUMP_TMP="${FASTPINGER_DUMP}.tmp"
if ! mkdir $FASTPINGER_TMPPATH/run 2>/dev/null ; then
echo "fastpinger is already running"
exit 0
fi
cleanup() { rmdir $FASTPINGER_TMPPATH/run 2>/dev/null ; }
trap cleanup EXIT
if [[ ! -e ${FASTPINGER_IPSPATH} ]] || [[ ${FASTPINGER_NETWORKSPATH} -nt ${FASTPINGER_IPSPATH} ]]; then
$BASE_DIR/fastpinger_setup
fi
echo "Start fping $(cat ${FASTPINGER_IPSPATH} | wc -l) hosts..."
cmd="fping --quiet --vcount=5 --period=500 --interval=1 --backoff=1 -f ${FASTPINGER_IPSPATH}"
echo $cmd
$cmd 2> ${FASTPINGER_DUMP_TMP}
if [ ! -f ${FASTPINGER_ARCHIVE} ] ; then
mkdir -p $(dirname ${FASTPINGER_ARCHIVE})
cp -f ${FASTPINGER_DUMP_TMP} ${FASTPINGER_ARCHIVE}
nohup xz -9 ${FASTPINGER_ARCHIVE} &> /dev/null &
fi
mv -f ${FASTPINGER_DUMP_TMP} ${FASTPINGER_DUMP}
echo "Stop fping..."