Updates (AWS Plugin) code with common producer/consumer
[osm/MON.git] / osm_mon / core / message_bus / common_consumer
index bb8ce0c..7221d0c 100755 (executable)
@@ -25,6 +25,7 @@ import sys
 import os
 
 sys.path.append("/root/MON")
+sys.path.append("../../plugins/CloudWatch")
 
 logging.basicConfig(filename='MON_plugins.log',
                     format='%(asctime)s %(message)s',
@@ -39,13 +40,14 @@ from osm_mon.plugins.OpenStack.Aodh import alarming
 from osm_mon.plugins.OpenStack.common import Common
 from osm_mon.plugins.OpenStack.Gnocchi import metrics
 
+from plugin_alarm import plugin_alarms
+from plugin_metric import plugin_metrics
 
 # Initialize servers
 server = {'server': 'localhost:9092'}
 
 # Initialize consumers for alarms and metrics
-common_consumer = KafkaConsumer(group_id='osm_mon',
-                                bootstrap_servers=server['server'])
+common_consumer = KafkaConsumer(bootstrap_servers=server['server'])
 
 # Create OpenStack alarming and metric instances
 auth_token = None
@@ -53,6 +55,9 @@ openstack_auth = Common()
 openstack_metrics = metrics.Metrics()
 openstack_alarms = alarming.Alarming()
 
+# Create CloudWatch alarm and metric instances
+cloudwatch_alarms = plugin_alarms()
+cloudwatch_metrics = plugin_metrics()
 
 def get_vim_type(message):
     """Get the vim type that is required by the message."""
@@ -73,18 +78,20 @@ try:
         if message.topic == "metric_request":
             # Check the vim desired by the message
             vim_type = get_vim_type(message)
+            
             if vim_type == "openstack":
                 log.info("This message is for the OpenStack plugin.")
                 openstack_metrics.metric_calls(
                     message, openstack_auth, auth_token)
 
-            elif vim_type == "cloudwatch":
+            elif vim_type == "aws":
+                cloudwatch_metrics.metric_calls(message)
                 log.info("This message is for the CloudWatch plugin.")
 
             elif vim_type == "vrops":
                 log.info("This message is for the vROPs plugin.")
 
-            else:
+            else:   
                 log.debug("vim_type is misconfigured or unsupported; %s",
                           vim_type)
 
@@ -95,7 +102,8 @@ try:
                 log.info("This message is for the OpenStack plugin.")
                 openstack_alarms.alarming(message, openstack_auth, auth_token)
 
-            elif vim_type == "cloudwatch":
+            elif vim_type == "aws":
+                cloudwatch_alarms.alarm_calls(message)
                 log.info("This message is for the CloudWatch plugin.")
 
             elif vim_type == "vrops":
@@ -112,7 +120,8 @@ try:
                 log.info("This message is for the OpenStack plugin.")
                 auth_token = openstack_auth._authenticate(message=message)
 
-            elif vim_type == "cloudwatch":
+            elif vim_type == "aws":
+                #TODO Access credentials later
                 log.info("This message is for the CloudWatch plugin.")
 
             elif vim_type == "vrops":