Updated logging for CloudWatch plugin 24/5824/1
authorjavaid <usman.javaid@xflowresearch.com>
Wed, 24 Jan 2018 05:17:55 +0000 (10:17 +0500)
committerjavaid <usman.javaid@xflowresearch.com>
Wed, 24 Jan 2018 05:17:55 +0000 (10:17 +0500)
Change-Id: I8daf6a41a1805fc6b58866e30f5a4627e2186300
Signed-off-by: javaid <usman.javaid@xflowresearch.com>
osm_mon/plugins/CloudWatch/access_credentials.py
osm_mon/plugins/CloudWatch/connection.py
osm_mon/plugins/CloudWatch/metric_alarms.py
osm_mon/plugins/CloudWatch/metrics.py
osm_mon/plugins/CloudWatch/plugin_alarm.py
osm_mon/plugins/CloudWatch/plugin_metric.py

index 75083dd..3774858 100644 (file)
@@ -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))
+
index 609f6aa..023071f 100644 (file)
@@ -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)) 
index 8d38e2f..d8b3715 100644 (file)
@@ -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
index f3a2144..5c6c976 100644 (file)
@@ -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():
 
index 5888771..c8ca955 100644 (file)
@@ -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): 
index 8c897d8..b6508a5 100644 (file)
@@ -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']