variable change, reduce noise
- s/cntFailures/cntNotify/; - emit status only on state transitions, can get noisy if testing once a minute in crontab - uses file names to track node status
This commit is contained in:
parent
ddeb6e4f73
commit
439a4ca5d7
41
path-loss.sh
41
path-loss.sh
|
@ -17,27 +17,52 @@ nodes=( \
|
||||||
)
|
)
|
||||||
|
|
||||||
# local variables
|
# local variables
|
||||||
cntFailures=0
|
cntNotify=0
|
||||||
status=""
|
status="|"
|
||||||
tmpLog=$(mktemp)
|
tmpLog=$(mktemp)
|
||||||
tmpPing=$(mktemp)
|
tmpPing=$(mktemp)
|
||||||
|
|
||||||
# preload output
|
# preload output
|
||||||
date > ${tmpLog}
|
date > ${tmpLog}
|
||||||
|
|
||||||
# loop through nodes nd test
|
# loop through nodes and test
|
||||||
for node in ${!nodes[*]}; do
|
for node in ${!nodes[*]}; do
|
||||||
echo -e ${txtSeparator} >> ${tmpLog};
|
echo -e ${txtSeparator} >> ${tmpLog};
|
||||||
echo "checking node ${nodes[${node}]}:" >> ${tmpLog};
|
echo "checking node ${nodes[${node}]}:" >> ${tmpLog};
|
||||||
echo "" >> ${tmpLog}
|
echo "" >> ${tmpLog}
|
||||||
|
|
||||||
ping -W 1 -c ${nAttempts} ${node} > ${tmpPing}
|
ping -W 1 -c ${nAttempts} ${node} > ${tmpPing}
|
||||||
cat ${tmpPing} >> ${tmpLog}
|
cat ${tmpPing} >> ${tmpLog}
|
||||||
|
|
||||||
value=$(grep transmitted ${tmpPing} | cut -d ' ' -f 4)
|
value=$(grep transmitted ${tmpPing} | cut -d ' ' -f 4)
|
||||||
if [[ nTrigger -ge value ]]; then
|
if [[ nTrigger -ge value ]]; then flagNxt="dn"
|
||||||
((cntFailures++));
|
else flagNxt="up"; fi
|
||||||
mtr -w -b --report ${node} >> ${tmpLog};
|
|
||||||
status="${status} ${nodes[${node}]}"
|
flagPrv="na"
|
||||||
|
|
||||||
|
if [[ -f /tmp/pl.dn.${node} ]]; then
|
||||||
|
flagPrv="dn"
|
||||||
|
if test "up" = "${flagNxt}"; then
|
||||||
|
rm /tmp/pl.dn.${node}
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -f /tmp/pl.up.${node} ]]; then
|
||||||
|
flagPrv="up"
|
||||||
|
if test "dn" = "${flagNxt}"; then
|
||||||
|
rm /tmp/pl.up.${node}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "${flagPrv}" != "${flagNxt}"; then
|
||||||
|
touch /tmp/pl.${flagNxt}.${node}
|
||||||
|
((cntNotify++));
|
||||||
|
mtr -w -b --report ${node} >> ${tmpLog};
|
||||||
|
status="${status} ${nodes[${node}]} ${flagPrv}>${flagNxt} |"
|
||||||
|
echo "" >> ${tmpLog}
|
||||||
|
echo "Above State Change: ${flagPrv}>${flagNxt}" >> ${tmpLog}
|
||||||
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# footer
|
# footer
|
||||||
|
@ -45,7 +70,7 @@ echo -e ${txtSeparator} >> ${tmpLog};
|
||||||
date >> ${tmpLog}
|
date >> ${tmpLog}
|
||||||
|
|
||||||
# notify on failure
|
# notify on failure
|
||||||
if [[ cntFailures -gt 0 ]]; then
|
if [[ cntNotify -gt 0 ]]; then
|
||||||
cat ${tmpLog} | mail -s "${txtSubject}:${status}" ${txtEmail};
|
cat ${tmpLog} | mail -s "${txtSubject}:${status}" ${txtEmail};
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue