1 # Copyright 2017 Intel Research and Development Ireland Limited
2 # *************************************************************
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Intel Corporation
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: helena.mcgough@intel.com or adrian.hoban@intel.com
22 """Notifier class for alarm notification response."""
30 log
.warn("Failed to import the aodhclient")
33 from core
.message_bus
.producer
import KafkaProducer
35 from plugins
.OpenStack
.Aodh
.alarming
import Alarming
36 from plugins
.OpenStack
.response
import OpenStack_Response
37 from plugins
.OpenStack
.settings
import Config
39 __author__
= "Helena McGough"
42 "average_memory_usage_above_threshold",
47 "net_packets_dropped",
48 "packets_in_above_threshold",
49 "packets_out_above_threshold",
50 "cpu_utilization_above_threshold"]
53 def register_notifier():
54 """Run the notifier instance."""
55 config
= Config
.instance()
56 instance
= Notifier(config
=config
)
61 class Notifier(object):
62 """Alarm Notification class."""
64 def __init__(self
, config
):
65 """Initialize alarm notifier."""
66 log
.info("Initialize the notifier for the SO.")
68 self
._response
= OpenStack_Response()
69 self
._producer
= KafkaProducer("alarm_response")
70 self
._alarming
= Alarming()
73 """Configure the alarm notifier."""
74 log
.info("Configure the notifier instance.")
75 self
._config
.read_environ("aodh")
78 """Send alarm notifications responses to the SO."""
79 log
.info("Checking for alarm notifications")
80 auth_token
, endpoint
= self
._alarming
.authenticate()
83 alarm_list
= self
._alarming
.list_alarms(endpoint
, auth_token
)
84 for alarm
in json
.loads(alarm_list
):
85 alarm_id
= alarm
['alarm_id']
86 alarm_name
= alarm
['name']
87 # Send a notification response to the SO on alarm trigger
88 if alarm_name
in ALARM_NAMES
:
89 alarm_state
= self
._alarming
.get_alarm_state(
90 endpoint
, auth_token
, alarm_id
)
91 if alarm_state
== "alarm":
92 # Generate and send an alarm notification response
94 a_date
= alarm
['state_timestamp'].replace("T", " ")
95 rule
= alarm
['gnocchi_resources_threshold_rule']
96 resp_message
= self
._response
.generate_response(
97 'notify_alarm', a_id
=alarm_id
,
98 r_id
=rule
['resource_id'],
99 sev
=alarm
['severity'], date
=a_date
,
100 state
=alarm_state
, vim_type
="OpenStack")
101 self
._producer
.notify_alarm(
102 'notify_alarm', resp_message
, 'alarm_response')
103 except Exception as exc
:
104 log
.warn("Failed to send notify response:%s", exc
)