diff --git a/moto/cloudwatch/models.py b/moto/cloudwatch/models.py index 6b7587a9..d7f76daf 100644 --- a/moto/cloudwatch/models.py +++ b/moto/cloudwatch/models.py @@ -10,10 +10,12 @@ class Dimension(object): class FakeAlarm(object): - def __init__(self, name, comparison_operator, evaluation_periods, period, - threshold, statistic, description, dimensions, alarm_actions, + def __init__(self, name, namespace, metric_name, comparison_operator, evaluation_periods, + period, threshold, statistic, description, dimensions, alarm_actions, ok_actions, insufficient_data_actions, unit): self.name = name + self.namespace = namespace + self.metric_name = metric_name self.comparison_operator = comparison_operator self.evaluation_periods = evaluation_periods self.period = period @@ -43,10 +45,10 @@ class CloudWatchBackend(BaseBackend): self.alarms = {} 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, 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, ok_actions, insufficient_data_actions, unit) self.alarms[name] = alarm diff --git a/moto/cloudwatch/responses.py b/moto/cloudwatch/responses.py index 5fd95bba..0d2cfacf 100644 --- a/moto/cloudwatch/responses.py +++ b/moto/cloudwatch/responses.py @@ -7,6 +7,8 @@ class CloudWatchResponse(BaseResponse): def put_metric_alarm(self): name = self._get_param('AlarmName') + namespace = self._get_param('Namespace') + metric_name = self._get_param('MetricName') comparison_operator = self._get_param('ComparisonOperator') evaluation_periods = self._get_param('EvaluationPeriods') period = self._get_param('Period') @@ -19,7 +21,8 @@ class CloudWatchResponse(BaseResponse): insufficient_data_actions = self._get_multi_param("InsufficientDataActions.member") unit = self._get_param('Unit') 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, threshold, statistic, description, dimensions, diff --git a/setup.py b/setup.py index f94df9dc..e079dbac 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ extras_require = { setup( name='moto', - version='0.4.25', + version='0.4.26', description='A library that allows your python tests to easily' ' mock out the boto library', author='Steve Pulec', diff --git a/tests/test_cloudwatch/test_cloudwatch.py b/tests/test_cloudwatch/test_cloudwatch.py index 388871fd..7354241f 100644 --- a/tests/test_cloudwatch/test_cloudwatch.py +++ b/tests/test_cloudwatch/test_cloudwatch.py @@ -8,6 +8,8 @@ def alarm_fixture(name="tester", action=None): action = action or ['arn:alarm'] return MetricAlarm( name=name, + namespace="{0}_namespace".format(name), + metric="{0}_metric".format(name), comparison='>=', threshold=2.0, period=60, @@ -32,6 +34,8 @@ def test_create_alarm(): alarms.should.have.length_of(1) alarm = alarms[0] alarm.name.should.equal('tester') + alarm.namespace.should.equal('tester_namespace') + alarm.metric.should.equal('tester_metric') alarm.comparison.should.equal('>=') alarm.threshold.should.equal(2.0) alarm.period.should.equal(60)