MetricAlarm.update() sends internal comparison instead of AWS comparison operator #1311

glance- opened this Issue Feb 8, 2013 · 2 comments


None yet
4 participants

glance- commented Feb 8, 2013

al = cw_conn.describe_alarms(alarm_names=['autogroup-HighCPU'])[0]
print al.comparison
al.threshold += 1

Results in:

    <Message>1 validation error detected: Value '&gt;' at 'comparisonOperator' failed to satisfy constraint: Member must satisfy enum value set: [GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold, GreaterThanOrEqualToThreshold]</Message>

A but-ugly way of solving this is:

--- i/boto/ec2/cloudwatch/
+++ w/boto/ec2/cloudwatch/
@@ -512,7 +512,7 @@ class CloudWatchConnection(AWSQueryConnection):
                     'MetricName': alarm.metric,
                     'Namespace': alarm.namespace,
                     'Statistic': alarm.statistic,
-                    'ComparisonOperator': alarm.comparison,
+                    'ComparisonOperator': alarm._cmp_map.get(alarm.comparison),
                     'Threshold': alarm.threshold,
                     'EvaluationPeriods': alarm.evaluation_periods,
                     'Period': alarm.period,

garnaat was assigned Feb 21, 2013

spedl commented Mar 20, 2013

The solution you posted is actually exactly what the MetricAlarm init method does:

class MetricAlarm(object):
def __init__(self, connection=None, name=None, metric=None,
                 namespace=None, statistic=None, comparison=None,
                 threshold=None, period=None, evaluation_periods=None,
                 unit=None, description='', dimensions=None,
                 alarm_actions=None, insufficient_data_actions=None,
... = name
    self.comparison = self._cmp_map.get(comparison)

However, in this case, the line in question causes the update method to fail because the comparison operator is replaced with the text. If the change you propose is included and the code in the MetricAlarm init method is also changed to:

    self.comparison = comparison

Then I think everything will work as expected. At least it does for me when calling alarm.update() or connection.create_alarm(alarm) where alarm is a MetricAlarm object.

@kamalgill kamalgill added a commit to eucalyptus/eucaconsole that referenced this issue Jan 17, 2014

@kamalgill kamalgill Workaround for boto issue 1311 - boto/boto#1311 2d49543

jbiel commented Oct 13, 2014

+1 - this worked for me. update() and create_alarm() (with passing existing alarm) do not work without this patch. Maybe I'm doing something horribly wrong?

Edit: I've updated our code that calls the above methods to do the following rather than patching the mentioned files (we can't make everyone depend on a patched version of boto.)

alarm = MetricAlarm()
alarm.comparison = alarm._cmp_map.get(alarm.comparison)
--- or ---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment