99from localstack .aws .api .cloudwatch import (
1010 AccountId ,
1111 ActionPrefix ,
12+ AlarmHistoryItem ,
1213 AlarmName ,
1314 AlarmNamePrefix ,
1415 AlarmNames ,
@@ -760,7 +761,7 @@ def _update_state(
760761 self ,
761762 context : RequestContext ,
762763 alarm : LocalStackAlarm ,
763- state_value : str ,
764+ state_value : StateValue ,
764765 state_reason : str ,
765766 state_reason_data : dict = None ,
766767 ):
@@ -780,18 +781,17 @@ def _update_state(
780781 "stateReasonData" : state_reason_data ,
781782 },
782783 }
783- store .histories .append (
784- {
785- "Timestamp" : timestamp_millis (alarm .alarm ["StateUpdatedTimestamp" ]),
786- "HistoryItemType" : HistoryItemType .StateUpdate ,
787- "AlarmName" : alarm .alarm ["AlarmName" ],
788- "HistoryData" : json .dumps (history_data ),
789- "HistorySummary" : f"Alarm updated from { old_state } to { state_value } " ,
790- "AlarmType" : "MetricAlarm"
791- if isinstance (alarm , LocalStackMetricAlarm )
792- else "CompositeAlarm" ,
793- }
784+ alarm_history_item = AlarmHistoryItem (
785+ Timestamp = alarm .alarm ["StateUpdatedTimestamp" ],
786+ HistoryItemType = HistoryItemType .StateUpdate ,
787+ AlarmName = alarm .alarm ["AlarmName" ],
788+ HistoryData = json .dumps (history_data ),
789+ HistorySummary = f"Alarm updated from { old_state } to { state_value } " ,
790+ AlarmType = "MetricAlarm"
791+ if isinstance (alarm , LocalStackMetricAlarm )
792+ else "CompositeAlarm" ,
794793 )
794+ store .histories .append (alarm_history_item )
795795 alarm .alarm ["StateValue" ] = state_value
796796 alarm .alarm ["StateReason" ] = state_reason
797797 if state_reason_data :
@@ -837,15 +837,10 @@ def describe_alarm_history(
837837 if alarm_name :
838838 history = [h for h in history if h ["AlarmName" ] == alarm_name ]
839839
840- def _get_timestamp (input : dict ):
841- if timestamp_string := input .get ("Timestamp" ):
842- return datetime .datetime .fromisoformat (timestamp_string )
843- return None
844-
845840 if start_date :
846- history = [h for h in history if (date := _get_timestamp ( h )) and date >= start_date ]
841+ history = [h for h in history if (date := h . get ( "Timestamp" )) and date >= start_date ]
847842 if end_date :
848- history = [h for h in history if (date := _get_timestamp ( h )) and date <= end_date ]
843+ history = [h for h in history if (date := h . get ( "Timestamp" )) and date <= end_date ]
849844 return DescribeAlarmHistoryOutput (AlarmHistoryItems = history )
850845
851846 def _evaluate_composite_alarms (self , context : RequestContext , triggering_alarm ):
0 commit comments