|
|
@ -53,8 +53,8 @@ options:
|
|
|
|
- Determines how the threshold value is compared
|
|
|
|
- Determines how the threshold value is compared
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
options: ['<=','<','>','>=']
|
|
|
|
options: ['<=','<','>','>=']
|
|
|
|
threshold:
|
|
|
|
threshold:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Sets the min/max bound for triggering the alarm
|
|
|
|
- Sets the min/max bound for triggering the alarm
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
period:
|
|
|
|
period:
|
|
|
@ -65,7 +65,7 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The number of times in which the metric is evaluated before final calculation
|
|
|
|
- The number of times in which the metric is evaluated before final calculation
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
unit:
|
|
|
|
unit:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The threshold's unit of measurement
|
|
|
|
- The threshold's unit of measurement
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
@ -79,7 +79,7 @@ options:
|
|
|
|
- Describes to what the alarm is applied
|
|
|
|
- Describes to what the alarm is applied
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
alarm_actions:
|
|
|
|
alarm_actions:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- A list of the names action(s) taken when the alarm is in the 'alarm' status
|
|
|
|
- A list of the names action(s) taken when the alarm is in the 'alarm' status
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
insufficient_data_actions:
|
|
|
|
insufficient_data_actions:
|
|
|
@ -129,7 +129,7 @@ except ImportError:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_metric_alarm(connection, module):
|
|
|
|
def create_metric_alarm(connection, module):
|
|
|
|
|
|
|
|
|
|
|
|
name = module.params.get('name')
|
|
|
|
name = module.params.get('name')
|
|
|
|
metric = module.params.get('metric')
|
|
|
|
metric = module.params.get('metric')
|
|
|
|
namespace = module.params.get('namespace')
|
|
|
|
namespace = module.params.get('namespace')
|
|
|
@ -146,12 +146,12 @@ def create_metric_alarm(connection, module):
|
|
|
|
ok_actions = module.params.get('ok_actions')
|
|
|
|
ok_actions = module.params.get('ok_actions')
|
|
|
|
|
|
|
|
|
|
|
|
alarms = connection.describe_alarms(alarm_names=[name])
|
|
|
|
alarms = connection.describe_alarms(alarm_names=[name])
|
|
|
|
|
|
|
|
|
|
|
|
if not alarms:
|
|
|
|
if not alarms:
|
|
|
|
|
|
|
|
|
|
|
|
alm = MetricAlarm(
|
|
|
|
alm = MetricAlarm(
|
|
|
|
name=name,
|
|
|
|
name=name,
|
|
|
|
metric=metric,
|
|
|
|
metric=metric,
|
|
|
|
namespace=namespace,
|
|
|
|
namespace=namespace,
|
|
|
|
statistic=statistic,
|
|
|
|
statistic=statistic,
|
|
|
|
comparison=comparison,
|
|
|
|
comparison=comparison,
|
|
|
@ -165,9 +165,10 @@ def create_metric_alarm(connection, module):
|
|
|
|
insufficient_data_actions=insufficient_data_actions,
|
|
|
|
insufficient_data_actions=insufficient_data_actions,
|
|
|
|
ok_actions=ok_actions
|
|
|
|
ok_actions=ok_actions
|
|
|
|
)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
connection.create_alarm(alm)
|
|
|
|
connection.create_alarm(alm)
|
|
|
|
module.exit_json(changed=True)
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
alarms = connection.describe_alarms(alarm_names=[name])
|
|
|
|
except BotoServerError, e:
|
|
|
|
except BotoServerError, e:
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
|
|
|
|
|
|
|
@ -186,33 +187,51 @@ def create_metric_alarm(connection, module):
|
|
|
|
|
|
|
|
|
|
|
|
dim1 = module.params.get('dimensions')
|
|
|
|
dim1 = module.params.get('dimensions')
|
|
|
|
dim2 = alarm.dimensions
|
|
|
|
dim2 = alarm.dimensions
|
|
|
|
|
|
|
|
|
|
|
|
for keys in dim1:
|
|
|
|
for keys in dim1:
|
|
|
|
if not isinstance(dim1[keys], list):
|
|
|
|
if not isinstance(dim1[keys], list):
|
|
|
|
dim1[keys] = [dim1[keys]]
|
|
|
|
dim1[keys] = [dim1[keys]]
|
|
|
|
if dim1[keys] != dim2[keys]:
|
|
|
|
if dim1[keys] != dim2[keys]:
|
|
|
|
changed=True
|
|
|
|
changed=True
|
|
|
|
setattr(alarm, 'dimensions', dim1)
|
|
|
|
setattr(alarm, 'dimensions', dim1)
|
|
|
|
|
|
|
|
|
|
|
|
for attr in ('alarm_actions','insufficient_data_actions','ok_actions'):
|
|
|
|
for attr in ('alarm_actions','insufficient_data_actions','ok_actions'):
|
|
|
|
action = module.params.get(attr) or []
|
|
|
|
action = module.params.get(attr) or []
|
|
|
|
if getattr(alarm, attr) != action:
|
|
|
|
if getattr(alarm, attr) != action:
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|
setattr(alarm, attr, module.params.get(attr))
|
|
|
|
setattr(alarm, attr, module.params.get(attr))
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if changed:
|
|
|
|
if changed:
|
|
|
|
connection.create_alarm(alarm)
|
|
|
|
connection.create_alarm(alarm)
|
|
|
|
module.exit_json(changed=changed)
|
|
|
|
|
|
|
|
except BotoServerError, e:
|
|
|
|
except BotoServerError, e:
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
module.fail_json(msg=str(e))
|
|
|
|
|
|
|
|
result = alarms[0]
|
|
|
|
|
|
|
|
module.exit_json(changed=changed, name=result.name,
|
|
|
|
|
|
|
|
actions_enabled=result.actions_enabled,
|
|
|
|
|
|
|
|
alarm_actions=result.alarm_actions,
|
|
|
|
|
|
|
|
alarm_arn=result.alarm_arn,
|
|
|
|
|
|
|
|
comparison=result.comparison,
|
|
|
|
|
|
|
|
description=result.description,
|
|
|
|
|
|
|
|
dimensions=result.dimensions,
|
|
|
|
|
|
|
|
evaluation_periods=result.evaluation_periods,
|
|
|
|
|
|
|
|
insufficient_data_actions=result.insufficient_data_actions,
|
|
|
|
|
|
|
|
last_updated=result.last_updated,
|
|
|
|
|
|
|
|
metric=result.metric,
|
|
|
|
|
|
|
|
namespace=result.namespace,
|
|
|
|
|
|
|
|
ok_actions=result.ok_actions,
|
|
|
|
|
|
|
|
period=result.period,
|
|
|
|
|
|
|
|
state_reason=result.state_reason,
|
|
|
|
|
|
|
|
state_value=result.state_value,
|
|
|
|
|
|
|
|
statistic=result.statistic,
|
|
|
|
|
|
|
|
threshold=result.threshold,
|
|
|
|
|
|
|
|
unit=result.unit)
|
|
|
|
|
|
|
|
|
|
|
|
def delete_metric_alarm(connection, module):
|
|
|
|
def delete_metric_alarm(connection, module):
|
|
|
|
name = module.params.get('name')
|
|
|
|
name = module.params.get('name')
|
|
|
|
|
|
|
|
|
|
|
|
alarms = connection.describe_alarms(alarm_names=[name])
|
|
|
|
alarms = connection.describe_alarms(alarm_names=[name])
|
|
|
|
|
|
|
|
|
|
|
|
if alarms:
|
|
|
|
if alarms:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
connection.delete_alarms([name])
|
|
|
|
connection.delete_alarms([name])
|
|
|
|