@@ -0,0 +1,2139 @@
+#!/usr/bin/env python%0Afrom __future__ import absolute_import%0Afrom __future__ import unicode_literals%0A%0Aimport argparse%0Aimport sys%0A%0Afrom paasta_tools.autoscaling.autoscaling_cluster_lib import get_sfr%0Afrom paasta_tools.autoscaling.autoscaling_cluster_lib import get_sfr_slaves%0Afrom paasta_tools.autoscaling.autoscaling_cluster_lib import get_spot_fleet_instances%0Afrom paasta_tools.mesos_tools import get_mesos_master%0Afrom paasta_tools.utils import load_system_paasta_config%0A%0A%0Adef check_registration(threshold_percentage):%0A    mesos_state = get_mesos_master().state%0A    autoscaling_resources = load_system_paasta_config().get_cluster_autoscaling_resources()%0A    for resource in autoscaling_resources.values():%0A        if resource%5B'type'%5D == 'aws_spot_fleet_request':%0A            resource%5B'sfr'%5D = get_sfr(resource%5B'id'%5D, region=resource%5B'region'%5D)%0A            instances = get_spot_fleet_instances(resource%5B'id'%5D, region=resource%5B'region'%5D)%0A            resource%5B'sfr'%5D%5B'ActiveInstances'%5D = instances%0A            slaves = get_sfr_slaves(resource, mesos_state)%0A            if len(instances) == 0:%0A                continue%0A            else:%0A                percent_registered = float(float(len(slaves)) / float(len(instances))) * 100%0A                if percent_registered %3C float(threshold_percentage):%0A                    print %22CRIT: Only found %7B0%7D%25 of instances in %7B1%7D registered in mesos. %22%5C%0A                          %22Please check for puppet or AMI baking problems!%22.format(percent_registered,%0A                                                                                   resource%5B'id'%5D)%0A                    return False%0A    print %22OK: Found more than %7B0%7D%25 of instances registered for all paasta resources in this %22%5C%0A          %22superregion%22.format(threshold_percentage)%0A    return True%0A%0A%0Adef main():%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument(%22-t%22, %22--threshold%22, help=%22percentage threshold for registered instances%22,%0A                        default=%2275%22)%0A    threshold = parser.parse_args().threshold%0A    if check_registration(threshold):%0A        sys.exit(0)%0A    sys.exit(2)%0A%0A%0Aif __name__ == %22__main__%22:%0A    main()%0A

Check AWS instances register in mesos