Validator fixes
# pylint: disable=line-too-long
# pylint: disable=pointless-string-statement
# pylint: disable=deprecated-lambda
-# pylint: disable=bad-builtin
# pylint: disable=bare-except
from ConfigParser import SafeConfigParser
import argparse
-from openshift_tools.monitoring.metric_sender import MetricSender
import urllib2
-import yaml
import boto3
+from openshift_tools.monitoring.metric_sender import MetricSender
# number instances behind elb
elb_no_instances = []
@@ -84,8 +82,8 @@ def get_elb_names(elb_descriptions):
''' Get ELB names '''
elbs_discovered = []
- for elb_desc_count in range(len(elb_descriptions['LoadBalancerDescriptions'])):
- elbs_discovered.append(elb_descriptions['LoadBalancerDescriptions'][elb_desc_count]['LoadBalancerName'])
+ for _, lb in enumerate(elb_descriptions['LoadBalancerDescriptions']):
+ elbs_discovered.append(lb['LoadBalancerName'])
return elbs_discovered
@@ -119,9 +117,9 @@ def elb_health_check(client, elbs_discovered):
''' Check health of each node found behind each ELB '''
# Iterate through raw health checks of each instance behind each ELB
- for i in range(len(elbs_discovered)):
+ for i, item in enumerate(elbs_discovered):
elb_health_checks_raw = client.describe_instance_health(
- LoadBalancerName=elbs_discovered[i]
+ LoadBalancerName=item
)
# Get https response
@@ -133,15 +131,15 @@ def elb_health_check(client, elbs_discovered):
# Check count of instances behind each ELB. Alert on 0 count.
elb_instance_count(elb_instance_response_states, elbs_discovered[i])
+ elb_name = elbs_discovered[i]
# Iterate through each instances health/state behind the ELB
for elb_instance_response_state in elb_instance_response_states:
- elb_name = elbs_discovered[i]
elb_instance_name = elb_instance_response_state['InstanceId']
elb_instance_state = elb_instance_response_state['State']
# Check http response
if elb_response_http != 200:
- print("A potential error occurred. HTTP Response: %s" % elb_response_http)
+ print "A potential error occurred. HTTP Response: %s" % elb_response_http
elb_instance_health(elb_instance_state, elb_instance_name, elb_name)
@@ -174,15 +172,15 @@ def main():
### Metric Checks
if len(elb_no_instances) != 0:
- for elb in range(len(elb_no_instances)):
- elb_instances_unhealthy.append(elb_no_instances[elb])
- print("ELB: %s has no instances behind it. Please investigate." % elb_no_instances[elb])
+ for _, elb in enumerate(elb_no_instances):
+ elb_instances_unhealthy.append(elb)
+ print "ELB: %s has no instances behind it. Please investigate." % elb
### Unhealthy count check
elb_instances_unhealthy_metric = len(elb_instances_unhealthy)
if elb_instances_unhealthy_metric != 0:
- for unhealthy in range(elb_instances_unhealthy_metric):
- print(elb_instances_unhealthy[unhealthy])
+ for _, unhealthy in enumerate(elb_instances_unhealthy):
+ print unhealthy
# ''' Now that we know if this instance is missing, feed zabbix '''
mts = MetricSender(verbose=args.verbose, debug=args.debug)
