def main(argv=sys.argv): global logger, settings, ca, ri, aws_access, aws_secret, thekey if len(argv) != 2: usage(argv) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) logger = logging.getLogger('scripts') aws_access = settings.get('aws.access') or None aws_secret = settings.get('aws.secret') or None aws_region = settings.get('aws.region') or None arn = settings.get('alarm.arn') period = settings.get('alarm.period') or '300' evalperiods = settings.get('alarm.evalperiods') or '1' cpu_threshold = settings.get('alarm.cpu.threshold') or '60.0' es_user = settings.get('es.user') es_pass = settings.get('es.pass') if not aws_region: print "ERROR: Settings missing 'aws.region' value, please define the region and try again." return ec2_conn = ec2.connect_to_region(aws_region, aws_access_key_id=aws_access, aws_secret_access_key=aws_secret) cw_conn = cw.connect_to_region(aws_region, aws_access_key_id=aws_access, aws_secret_access_key=aws_secret) cluster_info = compiled_cluster_info(ec2_conn, es_user, es_pass) for groupname, nodes in cluster_info.items(): for nodename, info in nodes.items(): instance_id = info['ec2instance_id'] alarm_name = "%s-maxcpu-%s" % (groupname, instance_id) dakwargs = { 'name': alarm_name, 'metric': 'CPUUtilization', 'namespace': 'AWS/EC2', 'statistic': 'Maximum', 'comparison': '>', 'threshold': cpu_threshold, 'period': period, 'evaluation_periods': evalperiods, 'description': 'CPU alarm for instance %s in cluster %s' % (nodename, groupname), 'dimensions': {'InstanceId':instance_id}, 'alarm_actions': [arn] } alarm = cw.alarm.MetricAlarm(**dakwargs) # creates OR updates the alarm. cw_conn.create_alarm(alarm) logger.info('Created/updated alarm \'%s\' for cluster %s, instance %s', alarm_name, groupname, instance_id)
def main(argv=sys.argv): global logger, settings, ca, ri, aws_access, aws_secret, thekey if len(argv) != 2: usage(argv) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) logger = logging.getLogger('scripts') es_user = settings['es.user'] if not es_user: print "es.user config value required" return es_pasw = settings['es.pass'] if not es_pasw: print "es.pasw config value required" return awsaccess = settings['aws.access'] awssecret = settings['aws.secret'] conneast = ec2.connect_to_region('us-east-1', aws_access_key_id=awsaccess, aws_secret_access_key=awssecret) ccieast = es.compiled_cluster_info(conneast, es_user, es_pasw) fd = open(settings['reports.dir'] + '/east_es_cluster_info.json', 'w') fd.write(str(json.dumps(ccieast))) connwest = ec2.connect_to_region('us-west-1', aws_access_key_id=awsaccess, aws_secret_access_key=awssecret) cciwest = es.compiled_cluster_info(connwest, es_user, es_pasw) fd = open(settings['reports.dir'] + '/west_es_cluster_info.json', 'w') fd.write(str(json.dumps(cciwest)))