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
.response
import OpenStack_Response
30 from plugins
.OpenStack
.singleton
import Singleton
32 __author__
= "Helena McGough"
35 "Average_Memory_Usage_Above_Threshold",
36 "Read_Latency_Above_Threshold",
37 "Write_Latency_Above_Threshold",
42 "Net_Packets_Dropped",
43 "Packets_in_Above_Threshold",
44 "Packets_out_Above_Threshold",
45 "CPU_Utilization_Above_Threshold"]
49 class Notifier(object):
50 """Alarm Notification class."""
53 """Initialize alarm notifier."""
54 self
._response
= OpenStack_Response()
56 self
._producer
= KafkaProducer("alarm_response")
58 def notify(self
, alarming
):
59 """Send alarm notifications responses to the SO."""
60 auth_token
, endpoint
= alarming
.authenticate(None)
63 alarm_list
= json
.loads(alarming
.list_alarms(endpoint
, auth_token
))
64 for alarm
in alarm_list
:
65 alarm_id
= alarm
['alarm_id']
66 alarm_name
= alarm
['name']
67 # Send a notification response to the SO on alarm trigger
68 if alarm_name
in ALARM_NAMES
:
69 alarm_state
= alarming
.get_alarm_state(
70 endpoint
, auth_token
, alarm_id
)
71 if alarm_state
== "alarm":
72 # Generate and send an alarm notification response
74 a_date
= alarm
['state_timestamp'].replace("T", " ")
75 rule
= alarm
['gnocchi_resources_threshold_rule']
76 resp_message
= self
._response
.generate_response(
77 'notify_alarm', a_id
=alarm_id
,
78 r_id
=rule
['resource_id'],
79 sev
=alarm
['severity'], date
=a_date
,
80 state
=alarm_state
, vim_type
="OpenStack")
81 self
._producer
.notify_alarm(
82 'notify_alarm', resp_message
, 'alarm_response')
83 except Exception as exc
:
84 log
.warn("Failed to send notify response:%s", exc
)