o
    rMf/                     @   sp   d dl m Z  d dlmZ d dlmZ d dlmZ d dlmZ G dd deZ	G dd	 d	e
ZG d
d de
ZdS )    )datetime)ListElement)	Dimension)json)sixc                   @   s&   e Zd ZdddZdd Zdd ZdS )	MetricAlarmsNc                 C   s   t |  || _dS )z0
        Parses a list of MetricAlarms.
        N)list__init__
connectionselfr
    r   [/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/boto/ec2/cloudwatch/alarm.pyr	      s   

zMetricAlarms.__init__c                 C   s"   |dkrt |}| | |S d S )Nmember)MetricAlarmappend)r   nameattrsr
   metric_alarmr   r   r   startElement&   s
   
zMetricAlarms.startElementc                 C      d S Nr   r   r   valuer
   r   r   r   
endElement,      zMetricAlarms.endElementr   )__name__
__module____qualname__r	   r   r   r   r   r   r   r      s    
r   c                   @   s   e Zd ZdZdZdZdddddZed	d
 e	eD Z
						d'ddZdd Zdd Zdd Zd(ddZdd Zdd Zdd Z		d)ddZd(dd Zd(d!d"Zd(d#d$Zd%d& ZdS )*r   OKALARMINSUFFICIENT_DATAGreaterThanOrEqualToThresholdGreaterThanThresholdLessThanThresholdLessThanOrEqualToThreshold)z>=><z<=c                 c   s    | ]	\}}||fV  qd S r   r   ).0kvr   r   r   	<genexpr><   s    zMetricAlarm.<genexpr>N c                 C   s   || _ || _|| _|| _|| _|durt|| _nd| _| j|| _	|dur-t
|| _nd| _|	dur:t
|	| _nd| _d| _d| _d| _|| _|| _d| _d| _|
| _|| _|| _|| _dS )a
  
        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.
                          Valid values: SampleCount|Average|Sum|Minimum|Maximum

        :type comparison: str
        :param comparison: Comparison used to compare statistic with threshold.
                           Valid values: >= | > | < | <=

        :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 the specified
                       statistic is applied.

        :type evaluation_periods: int
        :param evaluation_periods: 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: dict
        :param dimensions: A dictionary of dimension key/values where
                           the key is the dimension name and the value
                           is either a scalar value or an iterator
                           of values to be associated with that
                           dimension.
                           Example: {
                               'InstanceId': ['i-0123456', 'i-0123457'],
                               'LoadBalancerName': 'test-lb'
                           }

        :type alarm_actions: list of strs
        :param alarm_actions: A list of the ARNs of the actions to take in
                              ALARM state

        :type insufficient_data_actions: list of strs
        :param insufficient_data_actions: A list of the ARNs of the actions to
                                          take in INSUFFICIENT_DATA state

        :type ok_actions: list of strs
        :param ok_actions: A list of the ARNs of the actions to take in OK state
        N)r   r
   metric	namespace	statisticfloat	threshold_cmp_mapget
comparisonintperiodevaluation_periodsactions_enabled	alarm_arnlast_updateddescription
dimensionsstate_reasonstate_valueunitalarm_actionsinsufficient_data_actions
ok_actions)r   r
   r   r-   r.   r/   r4   r1   r6   r7   r?   r;   r<   r@   rA   rB   r   r   r   r	   >   s4   K
zMetricAlarm.__init__c                 C   s   d| j | j| j| j| jf S )NzMetricAlarm:%s[%s(%s) %s %s])r   r-   r/   r4   r1   r   r   r   r   __repr__   s
   
zMetricAlarm.__repr__c                 C   s^   |dkrt  | _| jS |dkrt  | _| jS |dkr!t  | _| jS |dkr,t | _| jS 	 d S )NAlarmActionsInsufficientDataActions	OKActions
Dimensions)r   r@   rA   rB   r   r<   r   r   r   r
   r   r   r   r      s   zMetricAlarm.startElementc                 C   s6  |dkr	|| _ d S |dkr|| _d S |dkr|| _d S |dkr$|| _d S |dkr-|| _d S |dkr<t| d| j|  d S |dkrGt|| _d S |d	krP|| _	d S |d
krY|| _
d S |dkrdt|| _d S |dkrm|| _d S |dkrv|| _d S |dkr|| _d S |dkrt|| _d S |dkr|| _d S t| || d S )NActionsEnabledAlarmArn"AlarmConfigurationUpdatedTimestampAlarmDescription	AlarmNameComparisonOperatorr4   EvaluationPeriods
MetricName	NamespacePeriodStateReason
StateValue	Statistic	ThresholdUnit)r8   r9   r:   r;   r   setattr_rev_cmp_mapr5   r7   r-   r.   r6   r=   r>   r/   r0   r1   r?   r   r   r   r   r      s>   










zMetricAlarm.endElementc                 C   s   | j | j|||S )a$   Temporarily sets the state of an alarm.

        :type value: str
        :param value: OK | ALARM | INSUFFICIENT_DATA

        :type reason: str
        :param reason: Reason alarm set (human readable).

        :type data: str
        :param data: Reason data (will be jsonified).
        )r
   set_alarm_stater   )r   r   reasondatar   r   r   	set_state   s   zMetricAlarm.set_statec                 C   s   | j | S r   )r
   update_alarmrC   r   r   r   update   s   zMetricAlarm.updatec                 C      | j | jgS r   )r
   enable_alarm_actionsr   rC   r   r   r   enable_actions      zMetricAlarm.enable_actionsc                 C   ra   r   )r
   disable_alarm_actionsr   rC   r   r   r   disable_actions   rd   zMetricAlarm.disable_actionsc                 C   s   | j | j|||||S r   )r
   describe_alarm_historyr   )r   
start_dateend_datemax_recordshistory_item_type
next_tokenr   r   r   describe_history   s
   zMetricAlarm.describe_historyc                 C      |sdS d| _ | j| dS )a&  
        Adds an alarm action, represented as an SNS topic, to this alarm.
        What do do when alarm is triggered.

        :type action_arn: str
        :param action_arn: SNS topics to which notification should be
                           sent if the alarm goes to state ALARM.
        Ntrue)r8   r@   r   r   
action_arnr   r   r   add_alarm_action      	zMetricAlarm.add_alarm_actionc                 C   rn   )aR  
        Adds an insufficient_data action, represented as an SNS topic, to
        this alarm. What to do when the insufficient_data state is reached.

        :type action_arn: str
        :param action_arn: SNS topics to which notification should be
                           sent if the alarm goes to state INSUFFICIENT_DATA.
        Nro   )r8   rA   r   rp   r   r   r   add_insufficient_data_action  rs   z(MetricAlarm.add_insufficient_data_actionc                 C   rn   )a4  
        Adds an ok action, represented as an SNS topic, to this alarm. What
        to do when the ok state is reached.

        :type action_arn: str
        :param action_arn: SNS topics to which notification should be
                           sent if the alarm goes to state INSUFFICIENT_DATA.
        Nro   )r8   rB   r   rp   r   r   r   add_ok_action  rs   zMetricAlarm.add_ok_actionc                 C   s   | j | jg d S r   )r
   delete_alarmsr   rC   r   r   r   delete'     zMetricAlarm.delete)NNNNNNNNNNr,   NNNNr   )NNNNN)r   r   r   r   r    r!   r2   dictr   	iteritemsrZ   r	   rD   r   r   r^   r`   rc   rf   rm   rr   rt   ru   rw   r   r   r   r   r   0   s>    
i
"



r   c                   @   s.   e Zd Zd
ddZdd Zdd Zdd	 ZdS )AlarmHistoryItemNc                 C   s
   || _ d S r   )r
   r   r   r   r   r	   ,  s   
zAlarmHistoryItem.__init__c                 C   s   d| j | j| jf S )NzAlarmHistory:%s[%s at %s])r   summary	timestamprC   r   r   r   rD   /  rx   zAlarmHistoryItem.__repr__c                 C   r   r   r   rI   r   r   r   r   2  r   zAlarmHistoryItem.startElementc                 C   s   |dkr	|| _ d S |dkrt|| _d S |dkr|| _d S |dkr'|| _d S |dkrGz
t|d| _W d S  t	yF   t|d| _Y d S w d S )NrN   HistoryDataHistoryItemTypeHistorySummary	Timestampz%Y-%m-%dT%H:%M:%S.%fZz%Y-%m-%dT%H:%M:%SZ)
r   r   loadsr]   tem_typer|   r   strptimer}   
ValueErrorr   r   r   r   r   5  s"   


zAlarmHistoryItem.endElementr   )r   r   r   r	   rD   r   r   r   r   r   r   r{   +  s
    
r{   N)r   boto.ec2.cloudwatch.listelementr   boto.ec2.cloudwatch.dimensionr   boto.compatr   r   r   r   objectr   r{   r   r   r   r   <module>   s    |