d3fdfd50f9051162250bcebb5603e7a1c2ad8f74
1 # -*- coding: utf-8 -*-
3 # Copyright 2018 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact: bdiaz@whitestack.com or glavado@whitestack.com
25 import multiprocessing
30 from osm_mon
.core
.config
import Config
31 from osm_mon
.core
.database
import Alarm
32 from osm_mon
.core
.message_bus_client
import MessageBusClient
33 from osm_mon
.core
.response
import ResponseBuilder
34 from osm_mon
.evaluator
.service
import EvaluatorService
, AlarmStatus
36 log
= logging
.getLogger(__name__
)
41 def __init__(self
, config
: Config
, loop
=None):
44 loop
= asyncio
.get_event_loop()
46 self
.service
= EvaluatorService(config
)
47 self
.msg_bus
= MessageBusClient(config
)
49 def evaluate_forever(self
):
50 log
.debug('evaluate_forever')
54 time
.sleep(int(self
.conf
.get('evaluator', 'interval')))
55 except peewee
.PeeweeException
:
56 log
.exception("Database error evaluating alarms: ")
59 log
.exception("Error evaluating alarms")
63 alarms_tuples
= self
.service
.evaluate_alarms()
64 for alarm
, status
in alarms_tuples
:
65 p
= multiprocessing
.Process(target
=self
.notify_alarm
,
69 def notify_alarm(self
, alarm
: Alarm
, status
: AlarmStatus
):
70 log
.debug("notify_alarm")
71 resp_message
= self
._build
_alarm
_response
(alarm
, status
)
72 log
.info("Sent alarm notification: %s", resp_message
)
73 self
.loop
.run_until_complete(self
.msg_bus
.aiowrite('alarm_response', 'notify_alarm', resp_message
))
75 def _build_alarm_response(self
, alarm
: Alarm
, status
: AlarmStatus
):
76 response
= ResponseBuilder()
77 now
= time
.strftime("%d-%m-%Y") + " " + time
.strftime("%X")
78 return response
.generate_response(
81 vdu_name
=alarm
.vdur_name
,
82 vnf_member_index
=alarm
.vnf_member_index
,
84 metric_name
=alarm
.monitoring_param
,
85 operation
=alarm
.operation
,
86 threshold_value
=alarm
.threshold
,