X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=plugins%2FOpenStack%2FAodh%2Fnotifier.py;h=3487daae9587c756e976cb1260e706ab47b22239;hb=d13405d13f4572de6dd11668b0d1a6723d6f4762;hp=2068f037975737e3f1c771a9c86847908e2856de;hpb=1d3567053b868400b801c9758ab8d3bc69740d1a;p=osm%2FMON.git diff --git a/plugins/OpenStack/Aodh/notifier.py b/plugins/OpenStack/Aodh/notifier.py index 2068f03..3487daa 100644 --- a/plugins/OpenStack/Aodh/notifier.py +++ b/plugins/OpenStack/Aodh/notifier.py @@ -24,49 +24,69 @@ import json import logging as log +try: + import aodhclient +except ImportError: + log.warn("Failed to import the aodhclient") + + from core.message_bus.producer import KafkaProducer +from plugins.OpenStack.Aodh.alarming import Alarming from plugins.OpenStack.response import OpenStack_Response -from plugins.OpenStack.singleton import Singleton +from plugins.OpenStack.settings import Config __author__ = "Helena McGough" ALARM_NAMES = [ - "Average_Memory_Usage_Above_Threshold", - "Read_Latency_Above_Threshold", - "Write_Latency_Above_Threshold", - "DISK_READ_OPS", - "DISK_WRITE_OPS", - "DISK_READ_BYTES", - "DISK_WRITE_BYTES", - "Net_Packets_Dropped", - "Packets_in_Above_Threshold", - "Packets_out_Above_Threshold", - "CPU_Utilization_Above_Threshold"] - - -@Singleton + "average_memory_usage_above_threshold", + "disk_read_ops", + "disk_write_ops", + "disk_read_bytes", + "disk_write_bytes", + "net_packets_dropped", + "packets_in_above_threshold", + "packets_out_above_threshold", + "cpu_utilization_above_threshold"] + + +def register_notifier(): + """Run the notifier instance.""" + config = Config.instance() + instance = Notifier(config=config) + instance.config() + instance.notify() + + class Notifier(object): """Alarm Notification class.""" - def __init__(self): + def __init__(self, config): """Initialize alarm notifier.""" + log.info("Initialize the notifier for the SO.") + self._config = config self._response = OpenStack_Response() - self._producer = KafkaProducer("alarm_response") + self._alarming = Alarming() - def notify(self, alarming): + def config(self): + """Configure the alarm notifier.""" + log.info("Configure the notifier instance.") + self._config.read_environ("aodh") + + def notify(self): """Send alarm notifications responses to the SO.""" - auth_token, endpoint = alarming.authenticate(None) + log.info("Checking for alarm notifications") + auth_token, endpoint = self._alarming.authenticate() while(1): - alarm_list = json.loads(alarming.list_alarms(endpoint, auth_token)) - for alarm in alarm_list: + alarm_list = self._alarming.list_alarms(endpoint, auth_token) + for alarm in json.loads(alarm_list): alarm_id = alarm['alarm_id'] alarm_name = alarm['name'] # Send a notification response to the SO on alarm trigger if alarm_name in ALARM_NAMES: - alarm_state = alarming.get_alarm_state( + alarm_state = self._alarming.get_alarm_state( endpoint, auth_token, alarm_id) if alarm_state == "alarm": # Generate and send an alarm notification response @@ -82,3 +102,6 @@ class Notifier(object): 'notify_alarm', resp_message, 'alarm_response') except Exception as exc: log.warn("Failed to send notify response:%s", exc) + +if aodhclient: + register_notifier()