diff --git a/alerts.py b/alerts.py --- a/alerts.py +++ b/alerts.py @@ -12,6 +12,34 @@ class AlertManager: self.mail_server = config.get("alerts", "mail_server") self.username = config.get("alerts", "username") self.password = config.get("alerts", "password") + + self.alerts = [] + load_alerts(config) + + def load_alerts(self, config): + + for section in self.config.sections(): + if "alert" in section: + type = self.config.get(section, "type") + if type == "output_feedback": + name = self.config.get(section, "name") + output_module = self.config.get(section, "output_module") + output = self.config.get(section, "output") + input_module = self.config.get(section, "input_module") + input = self.config.get(section, "input") + on_threshold = self.config.get(section, "on_threshold") + off_threshold = self.config.get(section, "off_threshold") + deadband = self.config.get(section, "deadband") + self.alerts.append(OutputFeedbackAlert(name, output_module, output, input_module, input, on_threshold, off_threshold, deadband)) + elif type == "measurement": + name = self.config.get(section, "name") + input_module = self.config.get(section, "input_module") + input = self.config.get(section, "input") + high_threshold = self.config.get(section, "high_threshold") + low_threshold = self.config.get(section, "low_threshold") + deadband = self.config.get(section, "deadband") + self.alerts.append(MeasurementAlert(name, input_module, input, high_threshold, low_threshold, deadband)) + def send_alert(self, message): @@ -26,3 +54,33 @@ class AlertManager: server.login(self.username, self.password) server.send_message(msg) server.quit() + + def evaluate_alerts(self): + for alert in self.alerts: + alert.evalutate() + +class Alert(metaclass=ABCMeta): + + def __init__(self, name): + self.name = name + + @abstractmethod + def evalutate(self): + pass + +class OutputFeedbackAlert(Alert): + + def __init__(self, name, output_module, output, input_module, input, on_threshold, off_threshold, deadband): + super(Alert, self).__init__(name) + + def evalutate(self): + print(self.name) + +class MeasurementAlert(Alert): + + def __init__(self, name, input_module, input, high_threshold, low_threshold, deadband): + super(Alert, self).__init__(name) + + def evalutate(self): + print(self.name) +