Preserve Namespace and MetricName when creating cloudwatch alarm.
This commit is contained in:
parent
ae938223d4
commit
a37838b638
@ -10,10 +10,12 @@ class Dimension(object):
|
|||||||
|
|
||||||
|
|
||||||
class FakeAlarm(object):
|
class FakeAlarm(object):
|
||||||
def __init__(self, name, comparison_operator, evaluation_periods, period,
|
def __init__(self, name, namespace, metric_name, comparison_operator, evaluation_periods,
|
||||||
threshold, statistic, description, dimensions, alarm_actions,
|
period, threshold, statistic, description, dimensions, alarm_actions,
|
||||||
ok_actions, insufficient_data_actions, unit):
|
ok_actions, insufficient_data_actions, unit):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.namespace = namespace
|
||||||
|
self.metric_name = metric_name
|
||||||
self.comparison_operator = comparison_operator
|
self.comparison_operator = comparison_operator
|
||||||
self.evaluation_periods = evaluation_periods
|
self.evaluation_periods = evaluation_periods
|
||||||
self.period = period
|
self.period = period
|
||||||
@ -43,10 +45,10 @@ class CloudWatchBackend(BaseBackend):
|
|||||||
self.alarms = {}
|
self.alarms = {}
|
||||||
self.metric_data = []
|
self.metric_data = []
|
||||||
|
|
||||||
def put_metric_alarm(self, name, comparison_operator, evaluation_periods,
|
def put_metric_alarm(self, name, namespace, metric_name, comparison_operator, evaluation_periods,
|
||||||
period, threshold, statistic, description, dimensions,
|
period, threshold, statistic, description, dimensions,
|
||||||
alarm_actions, ok_actions, insufficient_data_actions, unit):
|
alarm_actions, ok_actions, insufficient_data_actions, unit):
|
||||||
alarm = FakeAlarm(name, comparison_operator, evaluation_periods, period,
|
alarm = FakeAlarm(name, namespace, metric_name, comparison_operator, evaluation_periods, period,
|
||||||
threshold, statistic, description, dimensions, alarm_actions,
|
threshold, statistic, description, dimensions, alarm_actions,
|
||||||
ok_actions, insufficient_data_actions, unit)
|
ok_actions, insufficient_data_actions, unit)
|
||||||
self.alarms[name] = alarm
|
self.alarms[name] = alarm
|
||||||
|
@ -7,6 +7,8 @@ class CloudWatchResponse(BaseResponse):
|
|||||||
|
|
||||||
def put_metric_alarm(self):
|
def put_metric_alarm(self):
|
||||||
name = self._get_param('AlarmName')
|
name = self._get_param('AlarmName')
|
||||||
|
namespace = self._get_param('Namespace')
|
||||||
|
metric_name = self._get_param('MetricName')
|
||||||
comparison_operator = self._get_param('ComparisonOperator')
|
comparison_operator = self._get_param('ComparisonOperator')
|
||||||
evaluation_periods = self._get_param('EvaluationPeriods')
|
evaluation_periods = self._get_param('EvaluationPeriods')
|
||||||
period = self._get_param('Period')
|
period = self._get_param('Period')
|
||||||
@ -19,7 +21,8 @@ class CloudWatchResponse(BaseResponse):
|
|||||||
insufficient_data_actions = self._get_multi_param("InsufficientDataActions.member")
|
insufficient_data_actions = self._get_multi_param("InsufficientDataActions.member")
|
||||||
unit = self._get_param('Unit')
|
unit = self._get_param('Unit')
|
||||||
cloudwatch_backend = cloudwatch_backends[self.region]
|
cloudwatch_backend = cloudwatch_backends[self.region]
|
||||||
alarm = cloudwatch_backend.put_metric_alarm(name, comparison_operator,
|
alarm = cloudwatch_backend.put_metric_alarm(name, namespace, metric_name,
|
||||||
|
comparison_operator,
|
||||||
evaluation_periods, period,
|
evaluation_periods, period,
|
||||||
threshold, statistic,
|
threshold, statistic,
|
||||||
description, dimensions,
|
description, dimensions,
|
||||||
|
2
setup.py
2
setup.py
@ -20,7 +20,7 @@ extras_require = {
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='moto',
|
name='moto',
|
||||||
version='0.4.25',
|
version='0.4.26',
|
||||||
description='A library that allows your python tests to easily'
|
description='A library that allows your python tests to easily'
|
||||||
' mock out the boto library',
|
' mock out the boto library',
|
||||||
author='Steve Pulec',
|
author='Steve Pulec',
|
||||||
|
@ -8,6 +8,8 @@ def alarm_fixture(name="tester", action=None):
|
|||||||
action = action or ['arn:alarm']
|
action = action or ['arn:alarm']
|
||||||
return MetricAlarm(
|
return MetricAlarm(
|
||||||
name=name,
|
name=name,
|
||||||
|
namespace="{0}_namespace".format(name),
|
||||||
|
metric="{0}_metric".format(name),
|
||||||
comparison='>=',
|
comparison='>=',
|
||||||
threshold=2.0,
|
threshold=2.0,
|
||||||
period=60,
|
period=60,
|
||||||
@ -32,6 +34,8 @@ def test_create_alarm():
|
|||||||
alarms.should.have.length_of(1)
|
alarms.should.have.length_of(1)
|
||||||
alarm = alarms[0]
|
alarm = alarms[0]
|
||||||
alarm.name.should.equal('tester')
|
alarm.name.should.equal('tester')
|
||||||
|
alarm.namespace.should.equal('tester_namespace')
|
||||||
|
alarm.metric.should.equal('tester_metric')
|
||||||
alarm.comparison.should.equal('>=')
|
alarm.comparison.should.equal('>=')
|
||||||
alarm.threshold.should.equal(2.0)
|
alarm.threshold.should.equal(2.0)
|
||||||
alarm.period.should.equal(60)
|
alarm.period.should.equal(60)
|
||||||
|
Loading…
Reference in New Issue
Block a user