コード例 #1
0
#!/usr/bin/env python

import datetime
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)
コード例 #2
0
ファイル: EmailAlertAlways.py プロジェクト: roubles/raspwave2
#!/usr/bin/env python
# @author rouble matta

import sys
from RobotUtils import sendEmail
from SecurityUtils import getCurrentAlarmState
from ConfUtils import getNodeName,getMailto,isDoorWindowOrMotion
from Notification import *
from NotificationHandler import getNotificationFromNodeById,getNodeReport
from Utils import getTimeElapsed_HHMMSS
from SensorUtils import getSensorState
from LoggerUtils import setupRobotLogger

logger = setupRobotLogger()
mailto = getMailto()

# Always send an email, regardless of armed state
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):
    if not isDoorWindowOrMotion(args[2]):
        return 1