X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fplugins%2FCloudWatch%2Fplugin_metric.py;h=dc687db2472b7f67e6c8c3128ea574f39ca016fc;hb=9608081aa7b0ff8823ddbcd1144948ee0369160e;hp=6b9598fdf946a8d2fbb2f2fbf90cbd1f321300c7;hpb=8e226a68916159e07cf515634bc373e1e16eef5b;p=osm%2FMON.git diff --git a/osm_mon/plugins/CloudWatch/plugin_metric.py b/osm_mon/plugins/CloudWatch/plugin_metric.py index 6b9598f..dc687db 100644 --- a/osm_mon/plugins/CloudWatch/plugin_metric.py +++ b/osm_mon/plugins/CloudWatch/plugin_metric.py @@ -22,37 +22,22 @@ ''' AWS-Plugin implements all the methods of MON to interact with AWS using the BOTO client ''' +from osm_mon.core.message_bus.producer import KafkaProducer +from osm_mon.plugins.CloudWatch.metrics import Metrics __author__ = "Wajeeha Hamid" __date__ = "18-September-2017" -import sys import json -from connection import Connection -from metric_alarms import MetricAlarm -from metrics import Metrics -sys.path.append("../../core/message_bus") -from producer import KafkaProducer -import logging as log +import logging + +log = logging.getLogger(__name__) class plugin_metrics(): """Receives Alarm info from MetricAlarm and connects with the consumer/producer """ def __init__ (self): - self.conn = Connection() self.metric = Metrics() self.producer = KafkaProducer('') - self.connection() -#--------------------------------------------------------------------------------------------------------------------------- - def connection(self): - try: - """Connecting instances with CloudWatch""" - self.conn.setEnvironment() - self.conn = self.conn.connection_instance() - self.cloudwatch_conn = self.conn['cloudwatch_connection'] - self.ec2_conn = self.conn['ec2_connection'] - - except Exception as e: - log.error("Failed to Connect with AWS %s: " + str(e)) #--------------------------------------------------------------------------------------------------------------------------- def create_metric_request(self,metric_info): '''Comaptible API using normalized parameters''' @@ -81,18 +66,13 @@ class plugin_metrics(): return data_resp #--------------------------------------------------------------------------------------------------------------------------- - def metric_calls(self,message): - '''Consumer will consume the message from SO, - 1) parse the message and trigger the methods ac - cording to keys and topics provided in request. - - 2) The response from plugin is saved in json format. - - 3) The producer object then calls the producer response - methods to send the response back to message bus - ''' + def metric_calls(self,message,aws_conn): + """Gets the message from the common consumer""" try: + self.cloudwatch_conn = aws_conn['cloudwatch_connection'] + self.ec2_conn = aws_conn['ec2_connection'] + metric_info = json.loads(message.value) metric_response = dict() @@ -104,8 +84,8 @@ class plugin_metrics(): log.info("Action required against: %s" % (message.topic)) if message.key == "create_metric_request": - if self.check_resource(metric_info['metric_create']['resource_uuid']) == True: - metric_resp = self.create_metric_request(metric_info['metric_create']) #alarm_info = message.value + if self.check_resource(metric_info['metric_create_request']['resource_uuid']) == True: + metric_resp = self.create_metric_request(metric_info['metric_create_request']) #alarm_info = message.value metric_response['schema_version'] = metric_info['schema_version'] metric_response['schema_type'] = "create_metric_response" metric_response['metric_create_response'] = metric_resp @@ -117,8 +97,8 @@ class plugin_metrics(): return metric_response elif message.key == "update_metric_request": - if self.check_resource(metric_info['metric_create']['resource_uuid']) == True: - update_resp = self.update_metric_request(metric_info['metric_create']) + if self.check_resource(metric_info['metric_create_request']['resource_uuid']) == True: + update_resp = self.update_metric_request(metric_info['metric_create_request']) metric_response['schema_version'] = metric_info['schema_version'] metric_response['schema_type'] = "update_metric_response" metric_response['metric_update_response'] = update_resp