def updateAlarms(self, alarms): # Set up our alarms... for name, atts in alarms.items(): # We don't pass in the alarm_actions attributes into the constructor try: alarm_actions = [ self.actions[a] for a in atts.pop('alarm', []) ] insufficient_data_actions = [ self.actions[a] for a in atts.pop('insufficient_data', []) ] ok_actions = [self.actions[a] for a in atts.pop('ok', [])] except KeyError as e: raise EmitterException('Unknown action %s' % repr(e)) # Set some defaults: atts['statistic'] = atts.get('statistic', 'Average') atts['period'] = atts.get('period', 60) atts['evaluation_periods'] = atts.get('evaluation_periods', 1) # For each of the dimensions... try: atts['dimensions']['InstanceId'] = self.dims['InstanceId'] atts['namespace'] = self.namespace except KeyError: pass a = MetricAlarm(name=self.dims['InstanceId'] + "-" + name, **atts) a.alarm_actions = alarm_actions a.insufficient_data_actions = ListElement( insufficient_data_actions) a.ok_actions = ListElement(ok_actions) self.conn.update_alarm(a)
def startElement(self, name, attrs, connection): if name == 'AlarmActions': self.alarm_actions = ListElement() return self.alarm_actions elif name == 'InsufficientDataActions': self.insufficient_data_actions = ListElement() return self.insufficient_data_actions elif name == 'OKActions': self.ok_actions = ListElement() return self.ok_actions else: pass
def __init__(self, connection=None, name=None, metric=None, namespace=None, statistic=None, comparison=None, threshold=None, period=None, evaluation_periods=None): """ Creates a new Alarm. :type name: str :param name: Name of alarm. :type metric: str :param metric: Name of alarm's associated metric. :type namespace: str :param namespace: The namespace for the alarm's metric. :type statistic: str :param statistic: The statistic to apply to the alarm's associated metric. Can be one of 'SampleCount', 'Average', 'Sum', 'Minimum', 'Maximum' :type comparison: str :param comparison: Comparison used to compare statistic with threshold. Can be one of '>=', '>', '<', '<=' :type threshold: float :param threshold: The value against which the specified statistic is compared. :type period: int :param period: The period in seconds over which teh specified statistic is applied. :type evaluation_periods: int :param evaluation_period: The number of periods over which data is compared to the specified threshold """ self.name = name self.connection = connection self.metric = metric self.namespace = namespace self.statistic = statistic self.threshold = float(threshold) if threshold is not None else None self.comparison = self._cmp_map.get(comparison) self.period = int(period) if period is not None else None self.evaluation_periods = int(evaluation_periods) if evaluation_periods is not None else None self.actions_enabled = None self.alarm_arn = None self.last_updated = None self.description = '' self.dimensions = [] self.insufficient_data_actions = [] self.ok_actions = [] self.state_reason = None self.state_value = None self.unit = None alarm_action = [] self.alarm_actions = ListElement(alarm_action)
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=[]): """ Creates a new Alarm. :type name: str :param name: Name of alarm. :type metric: str :param metric: Name of alarm's associated metric. :type namespace: str :param namespace: The namespace for the alarm's metric. :type statistic: str :param statistic: The statistic to apply to the alarm's associated metric. Can be one of 'SampleCount', 'Average', 'Sum', 'Minimum', 'Maximum' :type comparison: str :param comparison: Comparison used to compare statistic with threshold. Can be one of '>=', '>', '<', '<=' :type threshold: float :param threshold: The value against which the specified statistic is compared. :type period: int :param period: The period in seconds over which teh specified statistic is applied. :type evaluation_periods: int :param evaluation_period: The number of periods over which data is compared to the specified threshold :type unit: str :param unit: Allowed Values are: Seconds, Microseconds, Milliseconds, Bytes, Kilobytes, Megabytes, Gigabytes, Terabytes, Bits, Kilobits, Megabits, Gigabits, Terabits, Percent, Count, Bytes/Second, Kilobytes/Second, Megabytes/Second, Gigabytes/Second, Terabytes/Second, Bits/Second, Kilobits/Second, Megabits/Second, Gigabits/Second, Terabits/Second, Count/Second, None :type description: str :param description: Description of MetricAlarm :type dimensions list of dicts :param description: Dimensions of alarm, such as: [{'InstanceId':'i-0123456,i-0123457'}] """ self.name = name self.connection = connection self.metric = metric self.namespace = namespace self.statistic = statistic self.threshold = float(threshold) if threshold is not None else None self.comparison = self._cmp_map.get(comparison) self.period = int(period) if period is not None else None self.evaluation_periods = int(evaluation_periods) if evaluation_periods is not None else None self.actions_enabled = None self.alarm_arn = None self.last_updated = None self.description = description self.dimensions = dimensions self.insufficient_data_actions = [] self.ok_actions = [] self.state_reason = None self.state_value = None self.unit = unit alarm_action = [] self.alarm_actions = ListElement(alarm_action)