X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fplugins%2FCloudWatch%2Fconnection.py;h=5853ae9ba2db773fb431c4ea41c6e0e1b1ee624e;hb=e80db311a29dc8562dc84ae3336af167bac2ec5b;hp=547c45404da736c65feb25e9d210646dd2b891f3;hpb=c7397b95dbaeebd7d872779eec809daed9e487cc;p=osm%2FMON.git diff --git a/osm_mon/plugins/CloudWatch/connection.py b/osm_mon/plugins/CloudWatch/connection.py index 547c454..5853ae9 100644 --- a/osm_mon/plugins/CloudWatch/connection.py +++ b/osm_mon/plugins/CloudWatch/connection.py @@ -26,7 +26,6 @@ Connecting with AWS services --CloudWatch/EC2 using Required keys __author__ = "Wajeeha Hamid" __date__ = "18-September-2017" -import sys import os try: @@ -35,7 +34,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,17 +43,24 @@ 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""" #----------------------------------------------------------------------------------------------------------------------------- def setEnvironment(self): + try: + """Credentials for connecting to AWS-CloudWatch""" + #Reads from the environment variables + self.AWS_KEY = os.environ.get("AWS_ACCESS_KEY_ID") + self.AWS_SECRET = os.environ.get("AWS_SECRET_ACCESS_KEY") + self.AWS_REGION = os.environ.get("AWS_EC2_REGION","us-west-2") - """Credentials for connecting to AWS-CloudWatch""" - self.AWS_KEY = os.environ.get("AWS_ACCESS_KEY_ID") - self.AWS_SECRET = os.environ.get("AWS_SECRET_ACCESS_KEY") - self.AWS_REGION = os.environ.get("AWS_EC2_REGION","us-west-2") - #TOPIC = 'YOUR_TOPIC' + #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)) #----------------------------------------------------------------------------------------------------------------------------- def connection_instance(self): try: @@ -67,8 +73,7 @@ class Connection(): #EC2 Connection self.ec2_conn = boto.ec2.connect_to_region(self.AWS_REGION, aws_access_key_id=self.AWS_KEY, - aws_secret_access_key=self.AWS_SECRET) - + aws_secret_access_key=self.AWS_SECRET) """ TODO : Required to add actions against alarms when needed """ #self.sns = connect_to_region(self.AWS_REGION)