def validate_alarm(alarm): project = v2_utils.get_auth_project( alarm.project_id if alarm.project_id != wtypes.Unset else None) for id in alarm.combination_rule.alarm_ids: alarms = list(pecan.request.alarm_storage_conn.get_alarms( alarm_id=id, project=project)) if not alarms: raise base.AlarmNotFound(id, project)
def validate_alarm(cls, alarm): super(AggregationMetricByResourcesLookupRule, cls).validate_alarm(alarm) rule = alarm.gnocchi_aggregation_by_resources_threshold_rule # check the query string is a valid json try: query = jsonutils.loads(rule.query) except ValueError: raise wsme.exc.InvalidInput('rule/query', rule.query) # Scope the alarm to the project id if needed auth_project = v2_utils.get_auth_project(alarm.project_id) if auth_project: rule.query = jsonutils.dumps({ "and": [{ "=": { "created_by_project_id": auth_project } }, query] }) # Delegate the query validation to gnocchi ks_client = keystone_client.get_client() request = { 'url': "%s/v1/aggregation/resource/%s/metric/%s" % (cfg.CONF.alarms.gnocchi_url, rule.resource_type, rule.metric), 'headers': { 'Content-Type': "application/json", 'X-Auth-Token': ks_client.auth_token }, 'params': { 'aggregation': rule.aggregation_method }, 'data': rule.query, } try: r = requests.post(**request) except requests.ConnectionError as e: raise GnocchiUnavailable(e) if r.status_code // 200 != 1: raise base.ClientSideError(r.content, status_code=r.status_code)
def validate_alarm(cls, alarm): super(AggregationMetricByResourcesLookupRule, cls).validate_alarm(alarm) rule = alarm.gnocchi_aggregation_by_resources_threshold_rule # check the query string is a valid json try: query = jsonutils.loads(rule.query) except ValueError: raise wsme.exc.InvalidInput('rule/query', rule.query) # Scope the alarm to the project id if needed auth_project = v2_utils.get_auth_project(alarm.project_id) if auth_project: rule.query = jsonutils.dumps({ "and": [{"=": {"created_by_project_id": auth_project}}, query]}) # Delegate the query validation to gnocchi ks_client = keystone_client.get_client() request = { 'url': "%s/v1/aggregation/resource/%s/metric/%s" % ( cfg.CONF.alarms.gnocchi_url, rule.resource_type, rule.metric), 'headers': {'Content-Type': "application/json", 'X-Auth-Token': ks_client.auth_token}, 'params': {'aggregation': rule.aggregation_method}, 'data': rule.query, } try: r = requests.post(**request) except requests.ConnectionError as e: raise GnocchiUnavailable(e) if r.status_code // 200 != 1: raise base.ClientSideError(r.content, status_code=r.status_code)