zoneminder报警(微信、QQ提醒)

来源:互联网 发布:mac 资料库在哪 编辑:程序博客网 时间:2024/04/29 18:17

zoneminder报警:当无人在家(dhcp保留手机IP,通过ping手机IP判断是否有人在家),过去10秒所有帧画面平均分值超过10分时,发送报警邮件到QQ邮箱,微信开通邮件提醒后,可以直接经过微信通知

suspend:检测到手机,不报警

fine:检测不到手机,开启报警,无警报

alarm:检测不到手机,开启报警,有警报

#!/usr/bin/python# -*- coding: UTF-8 -*-import MySQLdbimport smtplibimport datetimeimport osfrom email.mime.text import MIMETextmail_host = 'smtp.163.com'mail_user = '***'mail_pass = '***'mail_postfix = '163.com'mail_subject = 'zm_alarm:' + datetime.datetime.now().strftime('%y-%m-%d_%H:%M:%S')strsql='select e.id,f.score from frames f,events e where f.eventid=e.id and e.monitorid=1 and f.timestamp>date_sub(now(), interval 10 second)'def send_mail(sub,content):        me='zm<' + mail_user + '@' + mail_postfix + '>'        msg = MIMEText(content,_subtype='html',_charset='utf-8')        msg['Subject'] = sub        msg['From'] = me        msg['To'] = '***@qq.com'        try:                server = smtplib.SMTP()                server.connect(mail_host)                server.login(mail_user,mail_pass)                server.sendmail(me, '***@qq.com', msg.as_string())                server.close()        except Exception, e:                print str(e)if len(os.popen('ping -c 2 -W 1 192.168.2.188 | grep time | grep from ').readlines()) == 0:        db = MySQLdb.connect('192.168.2.50','zmuser','zmpass','zm' )        cur = db.cursor()        num = cur.execute(strsql)        data = cur.fetchall()        score = 0        scoremax = 0        eventid = 0        for rec in data:                score = score + rec[1]                if rec[1] > 10:                        eventid = rec[0]                if scoremax < rec[1]:                        scoremax=rec[1]        if score > num * 10:                print 'ALARM'                send_mail(mail_subject + '[mx:%s]'%(scoremax,),\                        'Alarm <br />EventID:<a href="http://***/zm?view=event&mode=stream&amp;mid=1&eid=%s">%s</a>'\                        '<br />Frames: %s<br />MaxScore: %s<br />'\                        'CAM_VIEW:<a href="http://***/zm/?view=montage&group=0" target="_blank">http://***/zm/?view=montage&group=0</a>'%(eventid,eventid,num,scoremax))                os.system('echo `date "+%Y-%m-%d %H:%M:%S : 1 - ALARM."` >> /var/works/mlog')        else:                os.system('echo `date "+%Y-%m-%d %H:%M:%S : 0 - FINE."` >> /var/works/mlog')        cur.close()        db.close()else:        os.system('echo `date "+%Y-%m-%d %H:%M:%S : 0 - SUSPEND."` >> /var/works/mlog')
0 0
原创粉丝点击