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: prithiv.mohan@intel.com or adrian.hoban@intel.com
24 This is a kafka consumer app that reads the messages from the message bus for
25 alarms and metrics responses.
29 __author__
= "Prithiv Mohan"
30 __date__
= "06/Sep/2017"
33 from kafka
import KafkaConsumer
34 from kafka
.errors
import KafkaError
40 def logging_handler(filename
, mode
='a+', encoding
=None):
41 if not os
.path
.exists(filename
):
42 open(filename
, 'a').close()
43 return logging
.FileHandler(filename
, mode
)
49 'format': '%(asctime)s %(levelname)s %(name)s %(message)s'
54 '()': logging_handler
,
56 'formatter': 'default',
57 'filename': '/var/log/osm_mon.log',
73 logging
.config
.dictConfig(log_config
)
74 logger
= logging
.getLogger('kafka')
76 if "BROKER_URI" in os
.environ
:
77 broker
= os
.getenv("BROKER_URI")
79 broker
= "localhost:9092"
81 alarm_consumer
= KafkaConsumer('alarm_response', 'osm_mon', bootstrap_servers
= broker
)
82 metric_consumer
= KafkaConsumer('metric_response', 'osm_mon', bootstrap_servers
= broker
)
84 for message
in alarm_consumer
:
86 for message
in metric_consumer
:
91 alarm_consumer
.subscribe('alarm_response')
92 metric_consumer
.subscribe('metric_response')