X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcore%2Fmessage_bus%2Fcommon_consumer.py;h=8f595b02a00f615f255a64e597957dbb2ec91444;hb=695d92c3f4f18d14bb18f8f0d4618c3eb5f2390e;hp=25aee43a48ddf9295f7ee9b769be79f9cdb93da7;hpb=e4be37f562f1d0c394d1ccdd0238202ec8f6f949;p=osm%2FMON.git diff --git a/osm_mon/core/message_bus/common_consumer.py b/osm_mon/core/message_bus/common_consumer.py index 25aee43..8f595b0 100755 --- a/osm_mon/core/message_bus/common_consumer.py +++ b/osm_mon/core/message_bus/common_consumer.py @@ -23,6 +23,7 @@ import json import logging import os import sys + import yaml logging.basicConfig(stream=sys.stdout, @@ -31,6 +32,7 @@ logging.basicConfig(stream=sys.stdout, level=logging.INFO) log = logging.getLogger(__name__) + sys.path.append(os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..'))) from kafka import KafkaConsumer @@ -78,14 +80,13 @@ aws_access_credentials = AccessCredentials() vrops_rcvr = plugin_receiver.PluginReceiver() -def get_vim_type(msg): +def get_vim_type(vim_uuid): """Get the vim type that is required by the message.""" try: - vim_uuid = json.loads(msg.value)["vim_uuid"].lower() credentials = database_manager.get_credentials(vim_uuid) return credentials.type except Exception as exc: - log.warn("vim_type is not configured correctly; %s", exc) + log.exception("Error getting vim_type: ") return None @@ -100,12 +101,12 @@ for message in common_consumer: try: try: values = json.loads(message.value) - except: + except ValueError: values = yaml.safe_load(message.value) # Check the message topic if message.topic == "metric_request": # Check the vim desired by the message - vim_type = get_vim_type(message) + vim_type = get_vim_type(values['vim_uuid']) if vim_type == "openstack": log.info("This message is for the OpenStack plugin.") @@ -125,7 +126,7 @@ for message in common_consumer: elif message.topic == "alarm_request": # Check the vim desired by the message - vim_type = get_vim_type(message) + vim_type = get_vim_type(values['vim_uuid']) if vim_type == "openstack": log.info("This message is for the OpenStack plugin.") openstack_alarms.alarming(message) @@ -152,7 +153,7 @@ for message in common_consumer: # TODO: Remove in the near future when all plugins support vim_uuid. Modify tests accordingly. elif message.topic == "access_credentials": # Check the vim desired by the message - vim_type = get_vim_type(message) + vim_type = get_vim_type(values['vim_uuid']) if vim_type == "aws": log.info("This message is for the CloudWatch plugin.")