From: javaid Date: Wed, 24 Jan 2018 05:17:55 +0000 (+0500) Subject: Updated logging for CloudWatch plugin X-Git-Tag: v4.0.0~36 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F24%2F5824%2F1;p=osm%2FMON.git Updated logging for CloudWatch plugin Change-Id: I8daf6a41a1805fc6b58866e30f5a4627e2186300 Signed-off-by: javaid --- diff --git a/osm_mon/plugins/CloudWatch/access_credentials.py b/osm_mon/plugins/CloudWatch/access_credentials.py index 75083dd..3774858 100644 --- a/osm_mon/plugins/CloudWatch/access_credentials.py +++ b/osm_mon/plugins/CloudWatch/access_credentials.py @@ -31,14 +31,14 @@ import sys import json import logging -logging.basicConfig(filename='MON_plugins.log', - format='%(asctime)s %(message)s', - datefmt='%m/%d/%Y %I:%M:%S %p', filemode='a', - level=logging.INFO) log = logging.getLogger(__name__) class AccessCredentials(): + def logtest(self): + log.info("Access credentials sourced for CloudWatch MON plugin") + + def access_credential_calls(self,message): try: message = json.loads(message.value)['access_config'] @@ -64,3 +64,4 @@ class AccessCredentials(): except Exception as e: log.error("Access credentials not provided correctly: %s", str(e)) + diff --git a/osm_mon/plugins/CloudWatch/connection.py b/osm_mon/plugins/CloudWatch/connection.py index 609f6aa..023071f 100644 --- a/osm_mon/plugins/CloudWatch/connection.py +++ b/osm_mon/plugins/CloudWatch/connection.py @@ -35,7 +35,7 @@ try: import boto.vpc import boto.ec2.cloudwatch import boto.ec2.connection - import logging as log + import logging from boto.ec2.cloudwatch.alarm import MetricAlarm from boto.ec2.cloudwatch.dimension import Dimension from boto.sns import connect_to_region @@ -44,6 +44,7 @@ try: except: exit("Boto not avialable. Try activating your virtualenv OR `pip install boto`") +log = logging.getLogger(__name__) class Connection(): """Connection Establishement with AWS -- VPC/EC2/CloudWatch""" @@ -57,7 +58,7 @@ class Connection(): self.AWS_REGION = os.environ.get("AWS_EC2_REGION","us-west-2") #TODO Read from the cloudwatch_credentials.txt file - + return self.connection_instance() except Exception as e: log.error("AWS Credentials not configured, Try setting the access credentials first %s: ",str(e)) diff --git a/osm_mon/plugins/CloudWatch/metric_alarms.py b/osm_mon/plugins/CloudWatch/metric_alarms.py index 8d38e2f..d8b3715 100644 --- a/osm_mon/plugins/CloudWatch/metric_alarms.py +++ b/osm_mon/plugins/CloudWatch/metric_alarms.py @@ -30,11 +30,12 @@ import re import datetime import random import json -import logging as log +import logging from random import randint from operator import itemgetter from connection import Connection +log = logging.getLogger(__name__) try: import boto diff --git a/osm_mon/plugins/CloudWatch/metrics.py b/osm_mon/plugins/CloudWatch/metrics.py index f3a2144..5c6c976 100644 --- a/osm_mon/plugins/CloudWatch/metrics.py +++ b/osm_mon/plugins/CloudWatch/metrics.py @@ -29,7 +29,7 @@ __date__ = "18-Sept-2017" import sys import datetime import json -import logging as log +import logging try: import boto @@ -40,7 +40,7 @@ try: except: exit("Boto not avialable. Try activating your virtualenv OR `pip install boto`") - +log = logging.getLogger(__name__) class Metrics(): diff --git a/osm_mon/plugins/CloudWatch/plugin_alarm.py b/osm_mon/plugins/CloudWatch/plugin_alarm.py index 5888771..c8ca955 100644 --- a/osm_mon/plugins/CloudWatch/plugin_alarm.py +++ b/osm_mon/plugins/CloudWatch/plugin_alarm.py @@ -28,7 +28,7 @@ __date__ = "18-September-2017" import sys import json -import logging as log +import logging from jsmin import jsmin from connection import Connection from metric_alarms import MetricAlarm @@ -36,6 +36,8 @@ from metrics import Metrics sys.path.append("../../core/message_bus") from producer import KafkaProducer +log = logging.getLogger(__name__) + class plugin_alarms(): """Receives Alarm info from MetricAlarm and connects with the consumer/producer""" def __init__ (self): diff --git a/osm_mon/plugins/CloudWatch/plugin_metric.py b/osm_mon/plugins/CloudWatch/plugin_metric.py index 8c897d8..b6508a5 100644 --- a/osm_mon/plugins/CloudWatch/plugin_metric.py +++ b/osm_mon/plugins/CloudWatch/plugin_metric.py @@ -33,7 +33,9 @@ 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 """ @@ -69,15 +71,7 @@ class plugin_metrics(): #--------------------------------------------------------------------------------------------------------------------------- def metric_calls(self,message,aws_conn): - '''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 - ''' + """Gets the message from the common consumer""" try: self.cloudwatch_conn = aws_conn['cloudwatch_connection']