- try:
- cfg = Config.instance()
- # Check state and severity
-
- severity = 'critical'
- if 'severity' in values:
- severity = values['severity'].lower()
-
- if severity == "indeterminate":
- alarm_state = "insufficient data"
- if alarm_state is None:
- alarm_state = "ok"
-
- statistic = values['statistic'].lower()
-
- granularity = '300'
- if 'granularity' in values:
- granularity = values['granularity']
-
- resource_type = 'generic'
- if 'resource_type' in values:
- resource_type = values['resource_type'].lower()
-
- # Try to configure the payload for the update/create request
- # Can only update: threshold, operation, statistic and
- # the severity of the alarm
- rule = {'threshold': values['threshold_value'],
- 'comparison_operator': values['operation'].lower(),
- 'metric': METRIC_MAPPINGS[metric_name],
- 'resource_id': resource_id,
- 'resource_type': resource_type,
- 'aggregation_method': STATISTICS[statistic],
- 'granularity': granularity, }
- payload = json.dumps({'state': alarm_state,
- 'name': alarm_name,
- 'severity': SEVERITIES[severity],
- 'type': 'gnocchi_resources_threshold',
- 'gnocchi_resources_threshold_rule': rule,
- 'alarm_actions': [cfg.OS_NOTIFIER_URI], })
- return payload
- except KeyError as exc:
- log.warn("Alarm is not configured correctly: %s", exc)
- return None
+ cfg = Config.instance()
+ # Check state and severity
+
+ severity = 'critical'
+ if 'severity' in values:
+ severity = values['severity'].lower()
+
+ if severity == "indeterminate":
+ alarm_state = "insufficient data"
+ if alarm_state is None:
+ alarm_state = "ok"
+
+ statistic = values['statistic'].lower()
+
+ granularity = cfg.OS_DEFAULT_GRANULARITY
+ if 'granularity' in values:
+ granularity = values['granularity']
+
+ resource_type = 'generic'
+ if 'resource_type' in values:
+ resource_type = values['resource_type'].lower()
+
+ # Try to configure the payload for the update/create request
+ # Can only update: threshold, operation, statistic and
+ # the severity of the alarm
+ rule = {'threshold': values['threshold_value'],
+ 'comparison_operator': values['operation'].lower(),
+ 'metric': METRIC_MAPPINGS[metric_name],
+ 'resource_id': resource_id,
+ 'resource_type': resource_type,
+ 'aggregation_method': STATISTICS[statistic],
+ 'granularity': granularity, }
+ payload = json.dumps({'state': alarm_state,
+ 'name': alarm_name,
+ 'severity': SEVERITIES[severity],
+ 'type': 'gnocchi_resources_threshold',
+ 'gnocchi_resources_threshold_rule': rule,
+ 'alarm_actions': [cfg.OS_NOTIFIER_URI], }, sort_keys=True)
+ return payload