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 dump(self): report = "" with self.lock: for key in self.shelf.keys(): ncb = self.shelf.get(key, None) if ncb is not None: report += "Node ID: " + nodeId + ": " + getNodeName( nodeId) + "\n" report += " Control Value: " + str(ncb.value) + "\n" report += " State: " + str(ncb.state) + "\n" report += " Battery Level: " + str( ncb.batteryValue) + "\n" report += " Last Wakeup Time: " + str( ncb.lastWakeupTime) + "\n" report += " Wakeup Interval: " + str( ncb.wakeupInterval) + "\n" report += " Control Notifications:\n" for notification in ncb.notifications: report += " " + str(notification) + "\n" report += " Battery Notifications:\n" for notification in ncb.batteryNotifications: report += " " + str(notification) + "\n" report += " Wakeup Notifications:\n" for notification in ncb.wakeupNotifications: report += " " + str(notification) + "\n" return report
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 ReportLowBatteryStatus(nodeId, current): try: batteryValue = int(current.value) except: batteryValue = 0 if (batteryValue < 30) or (batteryValue == 255) : name = getNodeName(nodeId) subject = "Low Battery! " + str(name) + "'s battery level is at " + str(current.value) + "% at " + str(current.time) body = "Current: " + str(current) + "\n\n" body += getNodeReport(nodeId) sendEmail(mailto, subject, body);
def ReportLowBatteryStatus(nodeId, current): try: batteryValue = int(current.value) except: batteryValue = 0 if (batteryValue < 30) or (batteryValue == 255): name = getNodeName(nodeId) subject = "Low Battery! " + str( name) + "'s battery level is at " + str( current.value) + "% at " + str(current.time) body = "Current: " + str(current) + "\n\n" body += getNodeReport(nodeId) sendEmail(mailto, subject, body)
def getNodeReport(self, nodeId): report = "" with self.lock: ncb = self.shelf.get(nodeId, None) if ncb is not None: report += "Node ID: " + nodeId + ": " + getNodeName(nodeId) + "\n" report += " Control Value: " + str(ncb.value) + "\n" report += " Battery Level: " + str(ncb.batteryValue) + "\n" report += " Last Wakeup Time: " + str(ncb.lastWakeupTime) + "\n" report += " Wakeup Interval: " + str(ncb.wakeupInterval) + "\n" report += " Control Notifications:\n" for notification in ncb.notifications: report += " " + str(notification) + "\n" report += " Battery Notifications:\n" for notification in ncb.batteryNotifications: report += " " + str(notification) + "\n" report += " Wakeup Notifications:\n" for notification in ncb.wakeupNotifications: report += " " + str(notification) + "\n" return report
from NotificationHandler import getEarliestNotificationOfCurrentState, getNodeReport from ConfUtils import getNodeName, getNodes, getMailto, isDoorWindowOrMotion from Utils import convert_timedelta_str from RobotUtils import sendEmail from LoggerUtils import setupCronbotLogger logger = setupCronbotLogger() mailto = getMailto() maxCloseTimeInSeconds = 28440 now = datetime.datetime.now() for node in getNodes(): if not isDoorWindowOrMotion(node): continue name = getNodeName(node) logger.info("Testing node: " + node + ":" + name) notification = getEarliestNotificationOfCurrentState(node, logger=logger) if not notification: logger.info("No notifications for node: " + name) elif (notification.value == 'False'): delta = now - notification.time logger.info(name + " has been closed for " + convert_timedelta_str(delta)) if delta.total_seconds() > maxCloseTimeInSeconds: subject = name + " has been closed for " + convert_timedelta_str( delta) sendEmail(mailto, subject, getNodeReport(node)) elif (notification.value == 'True'): delta = now - notification.time
from NotificationHandler import getEarliestNotificationOfCurrentState, getNodeReport from ConfUtils import getNodeName, getNodes, getMailto, isDoorWindowOrMotion from Utils import convert_timedelta_str from RobotUtils import sendEmail from LoggerUtils import setupCronbotLogger logger = setupCronbotLogger() mailto = getMailto() maxOpenTimeInSeconds = 240 now = datetime.datetime.now() for node in getNodes(): if not isDoorWindowOrMotion(node): continue name = getNodeName(node) logger.info("Testing node: " + node + ":" + name) notification = getEarliestNotificationOfCurrentState(node, logger=logger) if not notification: logger.info("No notifications for node: " + name) elif notification.value == "False": delta = now - notification.time logger.info(name + " has been closed for " + convert_timedelta_str(delta)) elif notification.value == "True": delta = now - notification.time logger.info(name + " has been open for " + convert_timedelta_str(delta)) if delta.total_seconds() > maxOpenTimeInSeconds: subject = name + " has been open for " + convert_timedelta_str(delta) sendEmail(mailto, subject, getNodeReport(node)) else:
from LoggerUtils import setupSecurityLogger from NotificationHandler import getNCB,NodeControlBlock,getEarliestNotificationOfCurrentState from ConfUtils import getNodes,getNodeName from Utils import getTimeElapsed_HHMMSS import cgi, cgitb from controlpanel import getBaseUrl cgitb.enable() logger = setupSecurityLogger() 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> Node Report </title>' print ' </head>' print ' <body>' print ' <h1> Node Report </h1>' for nodeId in getNodes(): ncb = getNCB(nodeId) notification = getEarliestNotificationOfCurrentState(nodeId) nodeName = getNodeName(nodeId) print '<h2>' + nodeName + '</h2>' if ncb: print '<h3>' + nodeName + ' has been ' + ncb.state + ' for ' + getTimeElapsed_HHMMSS(notification.time) + '</h3>' print '<p> Current State: ' + ncb.state + ' since ' + str(notification.time) + '</p>' print '<p> Battery Level: ' + str(ncb.batteryValue) + '</p>' 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>'
from Utils import getTimeElapsed_HHMMSS import cgi, cgitb from controlpanel import getBaseUrl cgitb.enable() logger = setupSecurityLogger() 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> Node Report </title>' print ' </head>' print ' <body>' print ' <h1> Node Report </h1>' for nodeId in getNodes(): ncb = getNCB(nodeId) notification = getEarliestNotificationOfCurrentState(nodeId) nodeName = getNodeName(nodeId) print '<h2>' + nodeName + '</h2>' if ncb: print '<h3>' + nodeName + ' has been ' + ncb.state + ' for ' + getTimeElapsed_HHMMSS( notification.time) + '</h3>' print '<p> Current State: ' + ncb.state + ' since ' + str( notification.time) + '</p>' print '<p> Battery Level: ' + str(ncb.batteryValue) + '</p>' 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>'
from NotificationHandler import getEarliestNotificationOfCurrentState,getNodeReport from ConfUtils import getNodeName,getNodes,getMailto,isDoorWindowOrMotion from Utils import convert_timedelta_str from RobotUtils import sendEmail from LoggerUtils import setupCronbotLogger logger = setupCronbotLogger() mailto = getMailto() maxOpenTimeInSeconds = 240 now = datetime.datetime.now() for node in getNodes(): if not isDoorWindowOrMotion(node): continue name = getNodeName(node) logger.info("Testing node: " + node + ":" + name) notification = getEarliestNotificationOfCurrentState(node, logger=logger) if not notification: logger.info("No notifications for node: " + name) elif (notification.value == 'False'): delta = now - notification.time logger.info(name + " has been closed for " + convert_timedelta_str(delta)) elif (notification.value == 'True'): delta = now - notification.time logger.info(name + " has been open for " + convert_timedelta_str(delta)) if delta.total_seconds() > maxOpenTimeInSeconds: subject = name + " has been open for " + convert_timedelta_str(delta) sendEmail(mailto, subject, getNodeReport(node)); else:
def ReportBatteryStatus(nodeId, current): name = getNodeName(nodeId) subject = str(name) + "'s battery level is at " + str(current.value) + "% at " + str(current.time) body = "Current: " + str(current) + "\n\n" body += getNodeReport(nodeId) sendEmail(mailto, subject, body);