Removed logstash references from code
[osm/MON.git] / osm_mon / core / message_bus / common_consumer.py
index e79e98a..8f595b0 100755 (executable)
@@ -24,12 +24,15 @@ import logging
 import os
 import sys
 
+import yaml
+
 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__)
 
+
 sys.path.append(os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..')))
 
 from kafka import KafkaConsumer
@@ -77,12 +80,13 @@ aws_access_credentials = AccessCredentials()
 vrops_rcvr = plugin_receiver.PluginReceiver()
 
 
-def get_vim_type(message):
+def get_vim_type(vim_uuid):
     """Get the vim type that is required by the message."""
     try:
-        return json.loads(message.value)["vim_type"].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
 
 
@@ -95,11 +99,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.")
@@ -119,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)
@@ -146,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.")