aa9521542b637f85c9a42abc3866f47d20559a44
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."""
27 from core
.message_bus
.producer
import KafkaProducer
29 from plugins
.OpenStack
.Aodh
.alarming
import Alarming
30 from plugins
.OpenStack
.response
import OpenStack_Response
31 from plugins
.OpenStack
.settings
import Config
33 __author__
= "Helena McGough"
36 "average_memory_usage_above_threshold",
41 "net_packets_dropped",
42 "packets_in_above_threshold",
43 "packets_out_above_threshold",
44 "cpu_utilization_above_threshold"]
47 def register_notifier():
48 """Run the notifier instance."""
49 config
= Config
.instance()
50 instance
= Notifier(config
=config
)
55 class Notifier(object):
56 """Alarm Notification class."""
58 def __init__(self
, config
):
59 """Initialize alarm notifier."""
60 log
.info("Initialize the notifier for the SO.")
62 self
._response
= OpenStack_Response()
63 self
._producer
= KafkaProducer("alarm_response")
64 self
._alarming
= Alarming()
67 """Configure the alarm notifier."""
68 log
.info("Configure the notifier instance.")
69 self
._config
.read_environ("aodh")
72 """Send alarm notifications responses to the SO."""
73 log
.info("Checking for alarm notifications")
74 auth_token
, endpoint
= self
._alarming
.authenticate()
77 alarm_list
= self
._alarming
.list_alarms(endpoint
, auth_token
)
78 for alarm
in json
.loads(alarm_list
):
79 alarm_id
= alarm
['alarm_id']
80 alarm_name
= alarm
['name']
81 # Send a notification response to the SO on alarm trigger
82 if alarm_name
in ALARM_NAMES
:
83 alarm_state
= self
._alarming
.get_alarm_state(
84 endpoint
, auth_token
, alarm_id
)
85 if alarm_state
== "alarm":
86 # Generate and send an alarm notification response
88 a_date
= alarm
['state_timestamp'].replace("T", " ")
89 rule
= alarm
['gnocchi_resources_threshold_rule']
90 resp_message
= self
._response
.generate_response(
91 'notify_alarm', a_id
=alarm_id
,
92 r_id
=rule
['resource_id'],
93 sev
=alarm
['severity'], date
=a_date
,
94 state
=alarm_state
, vim_type
="OpenStack")
95 self
._producer
.notify_alarm(
96 'notify_alarm', resp_message
, 'alarm_response')
97 except Exception as exc
:
98 log
.warn("Failed to send notify response:%s", exc
)