send email when peoplecounter is offline
parent
f78adee9de
commit
c6407b5bf3
|
@ -3,3 +3,4 @@ spaceapikey.txt
|
|||
pychromecast
|
||||
beamerip.txt
|
||||
peoplecounterip.txt
|
||||
mailconfig.py
|
||||
|
|
|
@ -25,6 +25,10 @@ tzselect
|
|||
comment out the last 4 lines of rsyslogd.conf (for xconsole)
|
||||
like explained here https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=122601
|
||||
|
||||
echo "pidor" > /etc/hostname
|
||||
sed -i 's/^127.0.1.1.*/127.0.1.1 pidor/' /etc/hosts
|
||||
|
||||
|
||||
cp -p systemfiles/sudoers.d/* /etc/sudoers.d/
|
||||
|
||||
mkdir /root/var # kinda important
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/python
|
||||
import smtplib
|
||||
import sys
|
||||
import mailconfig as cnf
|
||||
server = smtplib.SMTP(cnf.mailserver, 25)
|
||||
if (len(sys.argv) < 3):
|
||||
print "usage: "+sys.argv[0]+" 'subject' 'body text'"
|
||||
sys.exit()
|
||||
msg = "Subject: " + sys.argv[1] + "\n\n" + sys.argv[2]
|
||||
server.sendmail(cnf.mailsource, cnf.maildestination, msg)
|
||||
server.quit()
|
|
@ -10,7 +10,7 @@ else
|
|||
fi
|
||||
STATSFILE="/run/peoplecounter$DEV"
|
||||
SAMPLES=20 # how many records to keep in file
|
||||
INTERVAL=0 # how long to wait between polls
|
||||
INTERVAL=1 # how long to wait between polls
|
||||
INTERVALSKIP=20 # poll with INTERVAL but only consider every INTERVALSKIP's for SAMPLES
|
||||
MAXFILE="/var/cache/peoplecountermax$DEV"
|
||||
PRESENCYRT="/run/presencyrt$DEV"
|
||||
|
@ -59,7 +59,7 @@ while true
|
|||
do
|
||||
# scrape new value
|
||||
p="$(
|
||||
wget -qO - "http://$PEOPLECOUNTERIP/output.cgi?t=$(date +%s)" |
|
||||
wget --tries=3 --timeout=2 -qO - "http://$PEOPLECOUNTERIP/output.cgi?t=$(date +%s)" |
|
||||
sed 's/.*Occupancy://'|
|
||||
awk '{print $2}')"
|
||||
# echo "p=$p" # debug
|
||||
|
@ -113,12 +113,17 @@ do
|
|||
then
|
||||
state="online"
|
||||
logger $(basename $0) people counter online
|
||||
$(dirname "$0")"/mkmail.py 'peoplecounter level2 online' 'peoplecounter is now reachable'
|
||||
#python -c 'import smtplib ; server = smtplib.SMTP("mail.syn2cat.lu", 25) ; msg = "Subject: peoplecounter level2 onfline\n\npeoplecounter is now reachable" ; server.sendmail("gkess@pt.lu", "gunstick@syn2cat.lu", msg) ; server.quit()'
|
||||
fi
|
||||
else
|
||||
if [ "$state" = "online" ]
|
||||
then
|
||||
state="offline"
|
||||
logger $(basename $0) people counter offline
|
||||
$(dirname "$0")"/mkmail.py 'peoplecounter level2 offline' 'peoplecounter was not reachable'
|
||||
#python -c 'import smtplib ; server = smtplib.SMTP("mail.syn2cat.lu", 25) ; msg = "Subject: peoplecounter level2 offline\n\npeoplecounter was not reachable" ; server.sendmail("gkess@pt.lu", "gunstick@syn2cat.lu", msg) ; server.quit()'
|
||||
|
||||
fi
|
||||
fi
|
||||
sleep "$INTERVAL"
|
||||
|
|
|
@ -3,16 +3,24 @@
|
|||
if [ "$1" = "closed" ] && [ "$2" = "open" ]
|
||||
then
|
||||
p="$(tail -1 /run/peoplecounter)"
|
||||
if [ "$p" != "0" ]
|
||||
pp="$(tac /run/peoplecounter | awk -v p="$p" 'p!=$1 {print;exit}')" # get previous count. this may fail if people exit and after long time close door
|
||||
if [ "$pp" = "" ]
|
||||
then
|
||||
logger $(basename $0) There are $p people, closed door from inside. Waiting 1 min.
|
||||
pp=0 # if no variation found, don not do anything
|
||||
fi
|
||||
if [ "$p" != "0" ] && # there are people present
|
||||
[ "$p" -ge "$pp" ] # nobody left i.e. current count is greater or equal to previous count
|
||||
then
|
||||
logger $(basename $0) There are $p people, previusly $pp, closed door from inside. Waiting 1 min.
|
||||
sleep 60
|
||||
p="$(tail -1 /run/peoplecounter)"
|
||||
if [ "$p" = "0" ]
|
||||
np="$(tail -1 /run/peoplecounter)"
|
||||
if [ "$np" -lt "$p" ] # new count is lower than previous
|
||||
then
|
||||
logger $(basename $0) There are $p people, after 1 min wait. All OK.
|
||||
logger $(basename $0) There are now $np people, after 1 min wait. All OK.
|
||||
else
|
||||
logger $(basename $0) There are $p people, after 1 min. Maybe ALARM
|
||||
logger $(basename $0) There are $np people, after 1 min. Maybe ALARM
|
||||
python -c 'import smtplib ; server = smtplib.SMTP("mail.syn2cat.lu", 25) ; msg = "Subject: ALARM level2 intruder\n\ndoor closed with people inside" ; server.sendmail("gkess@pt.lu", "gunstick@syn2cat.lu", msg) ; server.quit()'
|
||||
|
||||
fi
|
||||
else
|
||||
logger $(basename $0) There are $p people, correctly closed door from outside. All OK.
|
||||
|
|
Loading…
Reference in New Issue