def onAction(self, eventInfo): zone = eventInfo.getZone() gasSensor = zone.getDeviceByEvent(eventInfo) gasType = gasSensor.__class__.__name__ if gasSensor.isTriggered(): self.notifiedForGasType[gasType] = True alertMessage = 'The {} {} at {} is above normal level.'.format( zone.getName(), gasType, gasSensor.getValue()) alert = Alert.createCriticalAlert( alertMessage, None, [], gasType, self.intervalBetweenAlertsInMinutes) AlertManager.processAlert(alert) else: if gasType in self.notifiedForGasType: alertMessage = 'The {} {} is back to normal.'.format( zone.getName(), gasType) alert = Alert.createInfoAlert(alertMessage) AlertManager.processAlert(alert) del self.notifiedForGasType[gasType] return True
def alertIfRainInShortermForecast(event): forecasts = EnvCanada.retrieveHourlyForecast('Ottawa', 12) rainPeriods = [f for f in forecasts if \ 'High' == f.getPrecipationProbability() or \ 'Medium' == f.getPrecipationProbability()] if len(rainPeriods) > 0: if len(rainPeriods) == 1: subject = u"Possible precipation at {}".format( rainPeriods[0].getUserFriendlyForecastTime()) else: subject = u"Possible precipation from {} to {}".format( rainPeriods[0].getUserFriendlyForecastTime(), rainPeriods[-1].getUserFriendlyForecastTime()) body = u'Forecasts:\n' body += u"{:5} {:7} {:25} {:6} {:6}\n".format('Hour: ', 'Celsius', 'Condition', 'Prob.', 'Wind') for f in forecasts: body += unicode(f) + '\n' alert = Alert.createInfoAlert(subject, body) result = AlertManager.processAlert(alert, zm) if not result: PE.logInfo('Failed to send rain alert')
def _checkAndSendAlert(zoneManager, checkFunction, deviceTypeString, thresholdInSeconds): inactiveDevices = checkFunction(zm, thresholdInSeconds) if len(inactiveDevices) > 0: subject = "{} inactive {} devices".format( len(inactiveDevices), deviceTypeString) body = "The following devices haven't triggered "\ "in the last {} hours\r\n - ".format( thresholdInSeconds / 3600) body += "\r\n - ".join(inactiveDevices) alert = Alert.createInfoAlert(subject, body) if not AlertManager.processAdminAlert(alert): PE.logInfo('Failed to send inactive {} device alert'.format(deviceTypeString)) else: PE.logInfo("No inactive {} devices detected.".format(deviceTypeString))
def updateState(self, value, zone, zoneManager): ''' Update this object with the latest value. If the value is outside the range, an warning alert will be sent. If the value is back to the normal range, an info alert will be sent. ''' if value >= self.minValue and value <= self.maxValue: if self.sentAlert: # send an info alert that the value is back to normal self.resetStates() msg = 'The {} {} at {}{} is back to the normal range ({}% - {}%).'.format( zone.getName(), self.label, value, self.unit, self.minValue, self.maxValue) alert = Alert.createInfoAlert(msg) if self.adminAlert: AlertManager.processAdminAlert(alert) else: AlertManager.processAlert(alert) else: alertMessage = '' if value <= self.nextMinNotificationThreshold: alertMessage = 'The {} {} at {}{} is below the threshold of {}%.'.format( zone.getName(), self.label, value, self.unit, self.minValue) self.nextMinNotificationThreshold -= self.notificationStepValue elif value >= self.nextMaxNotificationThreshold: alertMessage = 'The {} {} at {}{} is above the threshold of {}%.'.format( zone.getName(), self.label, value, self.unit, self.maxValue) self.nextMaxNotificationThreshold += self.notificationStepValue if alertMessage != '': alert = Alert.createWarningAlert(alertMessage, None, [], self.module, self.intervalBetweenAlertsInMinutes) if self.adminAlert: AlertManager.processAdminAlert(alert) else: AlertManager.processAlert(alert) self.sentAlert = True