initial commit
commit
28acb73969
|
|
@ -0,0 +1,46 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
TOKEN="A9jDrGFO6Ob-m88"
|
||||
IP="172.16.1.82"
|
||||
COUNT_TO_AWAY=900
|
||||
|
||||
startedTimeout="n"
|
||||
away="n"
|
||||
alertedHome="y"
|
||||
alertedAway="n"
|
||||
counter=0
|
||||
|
||||
#alert function takes $1 as title, $2 as message. Set TOKEN variable with token.
|
||||
alert() {
|
||||
curl -X POST "https://ths.tnet.space/gotify/message?token=${TOKEN}" -F "title=${1}" -F "message=${2}" -F "priority=4"
|
||||
}
|
||||
|
||||
#stdbuf -oL arping "$IP" | while read line
|
||||
while read line
|
||||
do
|
||||
echo "$line"
|
||||
if [ "$line" = "Timeout" ]; then
|
||||
if [ "$startedTimeout" = "n" ]; then
|
||||
startedTimeout="y"
|
||||
counter=1
|
||||
echo "$counter"
|
||||
else
|
||||
let "counter += 1"
|
||||
echo "******** $counter"
|
||||
if [ $counter -eq $COUNT_TO_AWAY ]; then
|
||||
alert "Status" "Away"
|
||||
alertedHome="n"
|
||||
alertedAway="y"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [ "$startedTimeout" = "y" ]; then
|
||||
if [ "$counter" -ge 100 ]; then
|
||||
echo "$counter" >> count.hayleyiphone
|
||||
fi
|
||||
startedTimeout="n"
|
||||
counter=0
|
||||
if [ "$alertedHome" = "n" ]; then
|
||||
alert "Status" "Home"
|
||||
alertedHome="y"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < <(stdbuf -oL arping -W 1 "$IP")
|
||||
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
IP="$1"
|
||||
OUTFILE="$2"
|
||||
|
||||
TIME_LENGTH_TIL_AWAY=60
|
||||
startedTimeout="n"
|
||||
away="n"
|
||||
alertedHome="n"
|
||||
alertedAway="n"
|
||||
#IP="172.16.1.66" #64
|
||||
counter=0
|
||||
|
||||
#stdbuf -oL arping "$IP" | while read line
|
||||
while read line
|
||||
do
|
||||
echo "$line"
|
||||
if [ "$line" = "Timeout" ]; then
|
||||
if [ "$startedTimeout" = "n" ]; then
|
||||
startedTimeout="y"
|
||||
counter=1
|
||||
else
|
||||
let "counter += 1"
|
||||
fi
|
||||
else
|
||||
if [ "$startedTimeout" = "y" ]; then
|
||||
startedTimeout="n"
|
||||
if [ $counter -ge 100 ]; then
|
||||
echo "$(date +%H:%M:%S) -- $counter" >> "$OUTFILE"
|
||||
fi
|
||||
counter=0
|
||||
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
|
||||
Loading…
Reference in New Issue