# Parse alertr.de account settings. tempConf = configRoot.find("alerts") alertrUsername = str(tempConf.attrib["username"]) alertrPassword = str(tempConf.attrib["password"]) # parse all alerts for item in configRoot.find("alerts").iterfind("alert"): alert = PushAlert(globalData) # Read the push notification settings. alert.username = alertrUsername alert.password = alertrPassword alert.channel = str(item.find("push").attrib["channel"]) alert.encSecret = str(item.find("push").attrib["secret"]) alert.subject = str(item.find("push").attrib["subject"]) alert.templateFile = make_path( str(item.find("push").attrib["templateFile"])) # check if the template file exists if not os.path.isfile(alert.templateFile): raise ValueError("Message template file '%s' does not exist." % alert.templateFile) # these options are needed by the server to # differentiate between the registered alerts alert.id = int(item.find("general").attrib["id"]) alert.description = str(item.find("general").attrib["description"]) alert.alertLevels = list()
# Parse alertr.de account settings. tempConf = configRoot.find("alerts") alertrUsername = str(tempConf.attrib["username"]) alertrPassword = str(tempConf.attrib["password"]) # parse all alerts for item in configRoot.find("alerts").iterfind("alert"): alert = PushAlert(globalData) # Read the push notification settings. alert.username = alertrUsername alert.password = alertrPassword alert.channel = str(item.find("push").attrib["channel"]) alert.encSecret = str(item.find("push").attrib["secret"]) alert.subject = str(item.find("push").attrib["subject"]) alert.templateFile = makePath( str(item.find("push").attrib["templateFile"])) # check if the template file exists if not os.path.isfile(alert.templateFile): raise ValueError("Message template file '%s' does not exist." % alert.templateFile) # these options are needed by the server to # differentiate between the registered alerts alert.id = int(item.find("general").attrib["id"]) alert.description = str(item.find("general").attrib["description"]) alert.alertLevels = list()
globalData.pushRetryTimeout = 5 globalData.pushRetries = 1 subject = "Test message for alert with id %d" % alert["id"] message = "This is a test message for the alert:\n\n" \ + "Id: %d\nDescription: %s\n\nCheers,\nalertR" \ % (alert["id"], alert["description"]) # Initialize alert object. alertObj = PushAlert(globalData) alertObj.id = alert["id"] alertObj.description = alert["description"] alertObj.username = alert["username"] alertObj.password = alert["password"] alertObj.channel = alert["channel"] alertObj.encSecret = alert["encSecret"] alertObj.templateFile = alert["templateFile"] alertObj.alertLevels = list() alertObj.subject = subject alertObj.initializeAlert() sensorAlert = SensorAlert() sensorAlert.state = 1 sensorAlert.timeReceived = int(time.time()) errorCode = alertObj._sendMessage(subject, message, sensorAlert) # Process response. if errorCode == ErrorCodes.NO_ERROR: logging.info("[%s]: Message successfully transmitted." % fileName) elif errorCode == ErrorCodes.DATABASE_ERROR: