47 lines
1.3 KiB
Bash
Executable File
47 lines
1.3 KiB
Bash
Executable File
TIME_LENGTH_TIL_AWAY=1 #660
|
|
startedTimeout="n"
|
|
away="n"
|
|
alertedHome="n"
|
|
alertedAway="n"
|
|
IP="172.16.1.82" #82
|
|
|
|
#stdbuf -oL arping "$IP" | while read line
|
|
while read line
|
|
do
|
|
echo "$line"
|
|
if [ "$line" = "Timeout" ]; then
|
|
if [ "$startedTimeout" = "n" ]; then
|
|
alertedAway="n"
|
|
startedTimeout="y"
|
|
beginOfTimeout=$(date +%s)
|
|
echo "started timeout. begin time= $beginOfTimeout"
|
|
else
|
|
if [ `expr $(date +%s) - $beginOfTimeout` -ge $TIME_LENGTH_TIL_AWAY ]; then
|
|
away="y"
|
|
if [ "$alertedAway" = "n" ]; then
|
|
#alert away
|
|
curl -X POST "https://ths.tnet.space/gotify/message?token=A9jDrGFO6Ob-m88" -F "title=Status" -F "message=Away" -F "priority=4"
|
|
# echo "away"
|
|
alertedAway="y"
|
|
alertedHome="n"
|
|
fi
|
|
fi
|
|
fi
|
|
else
|
|
if [ "$startedTimeout" = "y" ]; then
|
|
startedTimeout="n"
|
|
if [ "$alertedAway" = "y" ]; then
|
|
away="n"
|
|
#alert home
|
|
curl -X POST "https://ths.tnet.space/gotify/message?token=A9jDrGFO6Ob-m88" -F "title=Status" -F "message=Home" -F "priority=4"
|
|
# echo "home"
|
|
alertedHome="y"
|
|
alertedAway="n"
|
|
fi
|
|
fi
|
|
fi
|
|
done < <(stdbuf -oL arping "$IP")
|
|
|
|
# if != Timeout then here; reset timer to 0
|
|
# if == Timeout for more than x minutes then not here
|