connectionRetries += 1 logging.critical( "[%s]: Connecting to server failed. Try again in 5 seconds." % fileName) time.sleep(5) # when connected => generate watchdog object to monitor the # server connection logging.info("[%s]: Starting watchdog thread." % fileName) watchdog = ConnectionWatchdog(globalData.serverComm, globalData.pingInterval, globalData.smtpAlert) # set thread to daemon # => threads terminates when main thread terminates watchdog.daemon = True watchdog.start() # initialize all alerts logging.info("[%s] Initializing alerts." % fileName) for alert in globalData.alerts: alert.initialize() logging.info("[%s]: Client started." % fileName) # generate receiver to handle incoming data (for example status updates) # (note: we will not return from the receiver unless the client is terminated) receiver = Receiver(globalData.serverComm) receiver.run()
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.initialize() sensorAlert = ManagerObjSensorAlert() sensorAlert.state = 1 sensorAlert.timeReceived = int(time.time()) errorCode = alertObj._send_message(subject, message, sensorAlert) # Process response. if errorCode == ErrorCodes.NO_ERROR: logging.info("[%s]: Message successfully transmitted." % fileName) elif errorCode == ErrorCodes.DATABASE_ERROR: logging.error( "[%s]: Database error on server side. Please try again later." % fileName) elif errorCode == ErrorCodes.AUTH_ERROR: