def panic(nodeId=None, info=None, siren=True): with panicLock: logger.info("Panic called.") timeDelta = getLastPanicTimeDelta() if timeDelta.total_seconds() <= ignoreRePanicWithinSeconds: logger.info("Last panic was " + convert_timedelta_str(timeDelta) + " ago. Ignoring.") return setLastPanicTime() setPanic(True) # for now, just send an email. subject = "Alarm! Alarm! Alarm!" body = "Siren sounded at: " + getNowStr() + ".\n" if info is not None: body += info body += "\n\n" if nodeId is not None: body += getNodeReport(nodeId) body += "\n\n" if siren is True: soundSirens() pass logger.info(body) sendEmail(mailto, subject, body) sendEmail(panicMailto, subject, info)
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 unpanic(nodeId=None, info=None): with panicLock: logger.info("unPanic called.") if isPanic(): setPanic(False) subject = "Unpanic! Alarm silenced!" body = "Alarm silenced at: " + str(datetime.datetime.now()) + ".\n" if info is not None: body += info if nodeId is not None: body += getNodeReport(nodeId) body += "\n\n" silenceSirens() logger.info(body) sendEmail(mailto, subject, body) sendEmail(panicMailto, subject, info) else: logger.info("Not panicing. Nothing to do.")
def unpanic (nodeId = None, info = None): with panicLock: logger.info("unPanic called.") if isPanic(): setPanic(False) subject = "Unpanic! Alarm silenced!" body = "Alarm silenced at: " + str(datetime.datetime.now()) + ".\n" if info is not None: body += info if nodeId is not None: body += getNodeReport(nodeId) body += "\n\n" silenceSirens() logger.info(body) sendEmail(mailto, subject, body) sendEmail(panicMailto, subject, info) else: logger.info("Not panicing. Nothing to do.")
def panic (nodeId = None, info = None, siren = True): with panicLock: logger.info("Panic called.") timeDelta = getLastPanicTimeDelta() if timeDelta.total_seconds() <= ignoreRePanicWithinSeconds: logger.info("Last panic was " + convert_timedelta_str(timeDelta) + " ago. Ignoring.") return setLastPanicTime() setPanic(True) # for now, just send an email. subject = "Alarm! Alarm! Alarm!" body = "Siren sounded at: " + getNowStr() + ".\n" if info is not None: body += info body += "\n\n" if nodeId is not None: body += getNodeReport(nodeId) body += "\n\n" if siren is True: soundSirens() pass logger.info(body) sendEmail(mailto, subject, body) sendEmail(panicMailto, subject, info)
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 logger.info(name + " has been open for " + convert_timedelta_str(delta)) else: logger.info("Can not determine state of: " + getNodeName(node) + " since it is [" + notification.value + "]")
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: logger.info("Can not determine state of: " + getNodeName(node) + " since it is [" + notification.value + "]")
logger = setupSecurityLogger() alarmState = getCurrentAlarmState() alarmPanic = isPanic() report = "" report += "Alarm State: " + alarmState + "\n" report += "Alarm Panic: " + str(alarmPanic) + "\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\n" for node in getNodes(): report += getNodeReport(node) + "\n" 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> Detail Node Report </title>' print ' </head>' print ' <body>' print ' <h1> Detail Node Report </h1>' print ' <pre>' + report + '</pre>' 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>'
cgitb.enable() logger = setupSecurityLogger() alarmState = getCurrentAlarmState() alarmPanic = isPanic() report = "" report += "Alarm State: " + alarmState + "\n" report += "Alarm Panic: " + str(alarmPanic) + "\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\n" for node in getNodes(): report += getNodeReport(node) + "\n" 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> Detail Node Report </title>' print ' </head>' print ' <body>' print ' <h1> Detail Node Report </h1>' print ' <pre>' + report + '</pre>' 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>'
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);