def update_state(self, reason, reason_data, state_value): # History type, that then decides what the rest of the items are, can be one of ConfigurationUpdate | StateUpdate | Action self.history.append(( "StateUpdate", self.state_reason, self.state_reason_data, self.state_value, self.state_updated_timestamp, )) self.state_reason = reason self.state_reason_data = reason_data self.state_value = state_value self.state_updated_timestamp = iso_8601_datetime_with_nanoseconds( datetime.now(tz=tzutc()))
def __init__( self, region_name, name, namespace, metric_name, metric_data_queries, comparison_operator, evaluation_periods, datapoints_to_alarm, period, threshold, statistic, extended_statistic, description, dimensions, alarm_actions, ok_actions, insufficient_data_actions, unit, actions_enabled, treat_missing_data, evaluate_low_sample_count_percentile, threshold_metric_id, rule=None, ): self.region_name = region_name self.name = name self.alarm_arn = make_arn_for_alarm(region_name, get_account_id(), name) self.namespace = namespace self.metric_name = metric_name self.metric_data_queries = metric_data_queries self.comparison_operator = comparison_operator self.evaluation_periods = evaluation_periods self.datapoints_to_alarm = datapoints_to_alarm self.period = period self.threshold = threshold self.statistic = statistic self.extended_statistic = extended_statistic self.description = description self.dimensions = [ Dimension(dimension["name"], dimension["value"]) for dimension in dimensions ] self.actions_enabled = True if actions_enabled is None else actions_enabled self.alarm_actions = alarm_actions self.ok_actions = ok_actions self.insufficient_data_actions = insufficient_data_actions self.unit = unit self.configuration_updated_timestamp = iso_8601_datetime_with_nanoseconds( datetime.now(tz=tzutc()) ) self.treat_missing_data = treat_missing_data self.evaluate_low_sample_count_percentile = evaluate_low_sample_count_percentile self.threshold_metric_id = threshold_metric_id self.history = [] self.state_reason = "Unchecked: Initial alarm creation" self.state_reason_data = "{}" self.state_value = "OK" self.state_updated_timestamp = iso_8601_datetime_with_nanoseconds( datetime.now(tz=tzutc()) ) # only used for composite alarms self.rule = rule