def AlertIfArmed(nodeId, current, previous): with alertLock: name = getNodeName(nodeId) alarmState = getCurrentAlarmState() if (alarmState != "DISARMED"): logger.info("Sensor tripped on node " + name + " in alarm state: " + alarmState + " on " + str(current.time)) timeDelta = getLastAlertTimeDelta() if timeDelta.total_seconds() <= ignoreReAlertWithinSeconds: logger.info("Last alert was " + convert_timedelta_str(timeDelta) + " ago. Ignoring.") return setLastAlertTime() alarmStateDelay = getAlarmStateDelayForNode(nodeId, alarmState) if alarmStateDelay is None: logger.info("No delay defined for alarm state: [" + alarmState + "]. Defaulting to 10 seconds.") alarmStateDelay = 10 then = datetime.datetime.now() + datetime.timedelta(seconds=alarmStateDelay) setAlertPanicTime(str(then)) logger.info("We are in the following armed state: [" + alarmState + "]. Siren will be enabled in " + str(alarmStateDelay) + " seconds") subject = "[" + alarmState + "] Sensor tripped on node " + name + " on " + str(current.time) body = "Siren will fire in " + str(alarmStateDelay) + " seconds at " + str(then) sendEmail(mailto, subject, body) sleepWithBeep(then) # Now check is enduser has been able to disarm the alarm if (getCurrentAlarmState() != "DISARMED"): notification = getLatestNotification(nodeId) panic(nodeId = nodeId, info = "Triggered by " + name + ". " + name + " is currently " + getSensorState(notification.value) + ".") else: sendEmail(mailto, "Alarm disarmed in time!", "") logger.info("Alarm disarmed in time!") resetAlertPanicTime()
def crux(*args): logger.info('AutoStateSet: If Current State has been ' + args[1] + ' for more than ' + args[2] + ' seconds then set state to: ' + args[3]) processArguments() if (len(sys.argv) > 4): if (args[4].lower() == 'false'): persistent = isPersistent() if persistent: logger.info( "AutoStateSet will not set state since persistent is enabled." ) return 0 alarmState = getCurrentAlarmState() if (alarmState == args[1]): lastStateChangeTimeDelta = getLastStateChangeTimeDelta() secondsInCurrentState = lastStateChangeTimeDelta.total_seconds() if (secondsInCurrentState > int(args[2])): logger.info('AutoStateSet: Current State has been ' + alarmState + ' for ' + str(secondsInCurrentState) + ' seconds. Auto setting state to: ' + args[3]) setAlarmState(args[3]) else: logger.info( "AutoStateSet will not set state since current state has been " + alarmState + ' for only ' + str(secondsInCurrentState) + ' seconds') else: logger.info("AutoStateSet will not set state since current state is " + alarmState) return 0
def sleepWithBeep(then): while True: if (getCurrentAlarmState() == "DISARMED"): logger.info("Alarm disarmed while sleeping") break seconds = secondsLeft(then) logger.info("Siren is going to go off in " + str(seconds) + " seconds") if seconds < 0: break elif seconds < 30: logger.info("Beeping every second") beep() sleep(1) elif seconds < 60: logger.info("Beeping every 2 seconds") beep() sleep(2) elif seconds < 90: logger.info("Beeping every 3 seconds") beep() sleep(3) elif seconds < 120: logger.info("Beeping every 4 seconds") beep() sleep(4) else: sleep(5)
def EmailAlertAlways(nodeId, current, previous): name = getNodeName(nodeId) alarmState = getCurrentAlarmState() subject = "[" + str(alarmState) + "] " + str(name) + " is " + getSensorState(current.value) + " at " + str(current.time) body = name + " had been " + getSensorState(previous.value) + " for " + getTimeElapsed_HHMMSS(previous.time) + ".\n\n" body += "Current: " + str(current) + "\n" body += "Previous: " + str(previous) + "\n" body += getNodeReport(nodeId) sendEmail(mailto, subject, body);
def crux(*args): logger.info('AutoStateSet: If Current State has been ' + args[1] + ' for more than ' + args[2] + ' seconds then set state to: ' + args[3]) processArguments() if (len(sys.argv) > 4): if (args[4].lower() == 'false'): persistent = isPersistent() if persistent: logger.info("AutoStateSet will not set state since persistent is enabled.") return 0 alarmState = getCurrentAlarmState() if (alarmState == args[1]): lastStateChangeTimeDelta = getLastStateChangeTimeDelta() secondsInCurrentState = lastStateChangeTimeDelta.total_seconds() if (secondsInCurrentState > int(args[2])): logger.info('AutoStateSet: Current State has been ' + alarmState + ' for ' + str(secondsInCurrentState) + ' seconds. Auto setting state to: ' + args[3]) setAlarmState(args[3]) else: logger.info("AutoStateSet will not set state since current state has been " + alarmState + ' for only ' + str(secondsInCurrentState) + ' seconds') else: logger.info("AutoStateSet will not set state since current state is " + alarmState) return 0
from controlpanel import getBaseUrl import cgi, cgitb cgitb.enable() exitdelay = "" desiredstate = "" already = "" arguments = cgi.FieldStorage() if "exitdelay" in arguments: exitdelay = arguments["exitdelay"].value if "desiredstate" in arguments: desiredstate = arguments["desiredstate"].value if "already" in arguments: already = arguments["already"].value currentAlarmState = getCurrentAlarmState() print 'Content-Type: text/html' print # HTTP says you have to have a blank line between headers and content print '<html>' print ' <head>' print ' <title>Current state is ' + currentAlarmState + '</title>' print ' </head>' print ' <body>' print ' <h1> Current state is ' + currentAlarmState + '</h1>' if desiredstate != currentAlarmState: if exitdelay and desiredstate: print ' <h6> Setting state to ' + desiredstate + ' after exit delay of ' + exitdelay + ' seconds</h6>' print ' <h6> State has been ' + getCurrentAlarmState() + ' for ' + convert_timedelta_str(getLastStateChangeTimeDelta()) + ' since ' + str(getLastStateChangeTime()) + '</h6>' print ' <button onClick="window.location=\'' + getBaseUrl() + '/raspwave/controlpanel.py\'" style="font: bold 60px Arial">Back to Control Panel</button><br><br>' print ' </body>' print '</html>'
#!/usr/bin/python -u # @author rouble matta import sys sys.path.append('/etc/raspwave/pylib') from SecurityUtils import getCurrentAlarmState import cgi, cgitb cgitb.enable() if __name__ == '__main__': print 'Content-Type: text/html' print '' print getCurrentAlarmState()
#!/usr/bin/python -u # @author rouble matta import sys sys.path.append('/etc/raspwave/pylib') from SecurityUtils import getCurrentAlarmState,getDesiredAlarmState import cgi, cgitb cgitb.enable() if __name__ == '__main__': print 'Content-Type: text/html' print '' print getCurrentAlarmState() + " " + getDesiredAlarmState()
#!/usr/bin/env python # @author rouble matta import sys sys.path.append('/etc/raspwave/pylib') from SecurityUtils import getCurrentAlarmState,isPanic,getLastStateChangeTime,getLastPanicTime,getLastAlertTime,getPreviousAlarmState,getDesiredAlarmState,getDesiredAlarmStateDelay,getAlertPanicTime,getGuiUpdateTime,isPersistent from LoggerUtils import setupSecurityLogger import cgi, cgitb from controlpanel import getBaseUrl cgitb.enable() logger = setupSecurityLogger() alarmState = getCurrentAlarmState() alarmPanic = isPanic() report = "" report += "Alarm State: " + alarmState + "\n" report += "Alarm Panic: " + str(alarmPanic) + "\n" report += "Persistence: " + str(isPersistent()) + "\n" report += "Last Panic time: " + str(getLastPanicTime()) + "\n" report += "Last Alert time: " + str(getLastAlertTime()) + "\n" report += "Last State Change time: " + str(getLastStateChangeTime()) + "\n" report += "Previous State: " + str(getPreviousAlarmState()) + "\n" report += "Desired State: " + str(getDesiredAlarmState()) + "\n" report += "Desired State Delay: " + str(getDesiredAlarmStateDelay()) + "\n" report += "Alert will become panic at: " + str(getAlertPanicTime()) + "\n" report += "GUI needs to be updated last at: " + str(getGuiUpdateTime()) + "\n\n" print 'Content-Type: text/html'
return protocol + "://" + hostnameOrIp + ":" + port if __name__ == '__main__': print 'Content-Type: text/html' print # HTTP says you have to have a blank line between headers and content print '<!DOCTYPE html>' print '<html>' print ' <head>' print ' <title> Raspwave Alarm Control Panel </title>' print ' </head>' # print ' <body onload=\'launchRedraw(\"page\", false)\'>' print ' <body>' print ' <div id="main">' print ' <p id="message">' currentAlarmState = getCurrentAlarmState() desiredAlarmState = getDesiredAlarmState() if currentAlarmState != desiredAlarmState: desiredAlarmStateDelay = getDesiredAlarmStateDelay() print 'Desired alarm state ' + desiredAlarmState + ' will be set after exit delay of ' + convert_timedelta_str( getDesiredAlarmStateDelayAsTime() - datetime.datetime.now()) + ' at ' + desiredAlarmStateDelay print ' </p>' print ' <p id="message2">' alertPanicTimeDelta = getAlertPanicTimeDelta() if alertPanicTimeDelta.total_seconds() < 0: print 'Alarm system has been tripped! Siren will fire at ' + str( getAlertPanicTime()) print ' </p>' print ' <form>' print ' <h3> Alarm State </h3>'
from controlpanel import getBaseUrl import cgi, cgitb cgitb.enable() exitdelay = "" desiredstate = "" already = "" arguments = cgi.FieldStorage() if "exitdelay" in arguments: exitdelay = arguments["exitdelay"].value if "desiredstate" in arguments: desiredstate = arguments["desiredstate"].value if "already" in arguments: already = arguments["already"].value currentAlarmState = getCurrentAlarmState() print 'Content-Type: text/html' print # HTTP says you have to have a blank line between headers and content print '<html>' print ' <head>' print ' <title>Current state is ' + currentAlarmState + '</title>' print ' </head>' print ' <body>' print ' <h1> Current state is ' + currentAlarmState + '</h1>' if desiredstate != currentAlarmState: if exitdelay and desiredstate: print ' <h6> Setting state to ' + desiredstate + ' after exit delay of ' + exitdelay + ' seconds</h6>' print ' <h6> State has been ' + getCurrentAlarmState( ) + ' for ' + convert_timedelta_str( getLastStateChangeTimeDelta()) + ' since ' + str( getLastStateChangeTime()) + '</h6>'
#!/usr/bin/python -u # @author rouble matta import sys sys.path.append('/etc/raspwave/pylib') from SecurityUtils import getCurrentAlarmState, getDesiredAlarmState import cgi, cgitb cgitb.enable() if __name__ == '__main__': print 'Content-Type: text/html' print '' print getCurrentAlarmState() + " " + getDesiredAlarmState()