def update_ec2_alarms(verbose=0):
    alarm_keys = AlarmsManager.get_alarm_keys()

    for alarm_key in alarm_keys:
        alarm_group = AlarmsManager.get_alarm_group(alarm_key)

        tag_key = alarm_group.get('TagKey')
        tag_value = alarm_group.get('TagValue')

        AWSCredentialsManager.load_saved_environment_state()
        if alarm_group.get('AWSProfile'):
            AWSCredentialsManager.load_aws_profile(alarm_group['AWSProfile'])

        ec2_tags = get_all_ec2_tags(tag_key)

        for instance_id, key in ec2_tags.items():
            if key != alarm_key:
                continue

            if verbose:
                click.echo('\nUpdating instance {} tagged with {}: {}'.format(
                    instance_id, tag_key, tag_value))

            alarms = alarm_group.get('Alarms', [])
            for alarm in alarms:
                if verbose:
                    click.echo('Updating {} alarm on instance {}'.format(
                        alarm['MetricName'], instance_id))

                if alarm['MetricName'] in plugin_alarms:
                    alarm = plugin_alarms.get(
                        alarm['MetricName']).get_updated_alarm_kwargs(
                            identifier=instance_id, **alarm)

                set_cloudwatch_alarm(instance_id, **alarm)
Esempio n. 2
0
def update_ec2_alarms(verbose=0):
    plugin_alarms = load_plugins()
    alarm_keys = AlarmsManager.get_alarm_keys()

    for alarm_key in alarm_keys:
        alarm_group = AlarmsManager.get_alarm_group(alarm_key)

        tag_key = alarm_group.get('TagKey')
        tag_value = alarm_group.get('TagValue')

        AWSCredentialsManager.load_saved_environment_state()
        if alarm_group.get('AWSProfile'):
            AWSCredentialsManager.load_aws_profile(alarm_group['AWSProfile'])

        ec2_tags = get_all_ec2_tags(tag_key)

        for instance_id, key in ec2_tags.items():
            if key != alarm_key:
                continue

            if verbose:
                click.echo('\nUpdating instance {} tagged with {}: {}'
                           .format(instance_id, tag_key, tag_value))

            alarms = alarm_group.get('Alarms', [])
            for alarm in alarms:
                if verbose:
                    click.echo('Updating {} alarm on instance {}'
                               .format(alarm['MetricName'], instance_id))

                if alarm['MetricName'] in plugin_alarms:
                    alarm = plugin_alarms.get(alarm['MetricName']).get_updated_alarm_kwargs(
                        identifier=instance_id,
                        **alarm
                    )

                set_cloudwatch_alarm(instance_id, **alarm)
    def test_get_alarm_keys(self):
        AlarmsManager.add_alarm_group(**self.alarm_group)

        self.assertEqual(list(AlarmsManager.get_alarm_keys()),
                         ['fake-key:fake-value'])
Esempio n. 4
0
    def test_get_alarm_keys(self):
        AlarmsManager.add_alarm_group(**self.alarm_group)

        self.assertEqual(list(AlarmsManager.get_alarm_keys()),
                         ['fake-key:fake-value'])