def label_values(self):
     if self.scope == QuotaScope.ACCOUNT:
         return {'account': get_account_id(self.boto_session)}
     elif self.scope == QuotaScope.REGION:
         return {
             'account': get_account_id(self.boto_session),
             'region': self.boto_session.region_name
         }
     elif self.scope == QuotaScope.INSTANCE:
         return {
             'account': get_account_id(self.boto_session),
             'region': self.boto_session.region_name,
             'instance': self.instance_id
         }
    def label_values(self):
        label_values = {
            'quota': self.key,
            'account': get_account_id(self.boto_session)
        }

        if self.scope in (QuotaScope.REGION, QuotaScope.INSTANCE):
            label_values['region'] = self.boto_session.region_name

        if self.scope == QuotaScope.INSTANCE:
            label_values['instance'] = self.instance_id

        return label_values
Beispiel #3
0
    def run_checks(self):
        fails = 0
        errors = 0
        warnings = 0

        for chk in self.checks:
            try:
                current = chk.current
            except Exception as e:
                logger.debug(e, exc_info=True)
                current = None

            try:
                maximum = chk.maximum
            except Exception as e:
                logger.debug(e, exc_info=True)
                maximum = None

            if chk.scope == QuotaScope.ACCOUNT:
                scope = get_account_id(self.session)
            elif chk.scope == QuotaScope.REGION:
                scope = f'{get_account_id(self.session)}/{self.session.region_name}'
            elif chk.scope == QuotaScope.INSTANCE:
                scope = f'{get_account_id(self.session)}/{self.session.region_name}/{chk.instance_id}'

            result = self.__report(chk.description, scope, current, maximum)

            if result == Runner.ReportResult.WARNING:
                warnings += 1
            elif result == Runner.ReportResult.ERROR:
                errors += 1
            elif result == Runner.ReportResult.FAIL:
                fails += 1

        if (self.fail_on_warning and warnings > 0) or errors > 0 or fails > 0:
            sys.exit(1)
Beispiel #4
0
    def run_checks(self):
        errors = 0
        warnings = 0

        for chk in self.checks:
            current = chk.current
            maximum = chk.maximum

            if chk.scope == QuotaScope.ACCOUNT:
                scope = get_account_id(self.session)
            elif chk.scope == QuotaScope.REGION:
                scope = f'{get_account_id(self.session)}/{self.session.region_name}'
            elif chk.scope == QuotaScope.INSTANCE:
                scope = f'{get_account_id(self.session)}/{self.session.region_name}/{chk.instance_id}'

            result = self.__report(chk.description, scope, current, maximum)

            if result == Runner.ReportResult.WARNING:
                warnings += 1
            elif result == Runner.ReportResult.ERROR:
                errors += 1

        if (self.fail_on_warning and warnings > 0) or errors > 0:
            sys.exit(1)
 def default_labels(self):
     return {
         'account': get_account_id(self.session),
         'region': self.session.region_name
     }