X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcore%2Fmessage_bus%2Fcommon_consumer.py;h=97e37fae2ec2b1d35eaed7bee043280d7eb3cb57;hb=821a62e1e29bb603de56b028d92ad885f06fd68c;hp=0ba003b8c967835c1bade1ab886a48b947bbe146;hpb=ad1d76c5afc49644f7d864eee85d8e4d09a184cc;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 0ba003b..97e37fa 100755 --- a/osm_mon/core/message_bus/common_consumer.py +++ b/osm_mon/core/message_bus/common_consumer.py @@ -23,12 +23,18 @@ import json import logging import os import sys +import yaml + +import yaml +import logstash logging.basicConfig(stream=sys.stdout, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) log = logging.getLogger(__name__) +log.addHandler(logstash.TCPLogstashHandler('dockerelk_logstash_1', 5000, version=1)) + sys.path.append(os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..'))) @@ -77,14 +83,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 @@ -97,11 +102,14 @@ log.info("Listening for alarm_request and metric_request messages") for message in common_consumer: log.info("Message arrived: %s", message) try: - values = json.loads(message.value) + try: + values = json.loads(message.value) + 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.") @@ -121,7 +129,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) @@ -148,7 +156,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.")