o ckF[_@sdZddlmZmZmZmZddlmZddlm Z ddl m Z m Z m Z ddlmZddlmZmZmZddlmZdd lZed iZd d Zd dZGdddeZd S)zc This module provides an interface to the Elastic Compute Cloud (EC2) CloudWatch service from AWS. )jsonmapsixzip)AWSQueryConnection)Metric) MetricAlarm MetricAlarmsAlarmHistoryItem) Datapoint) RegionInfo get_regions load_regions)connectN cloudwatchcCs tdtdS)z Get all available regions for the CloudWatch service. :rtype: list :return: A list of :class:`boto.RegionInfo` instances r)connection_cls)r CloudWatchConnectionrr>/usr/lib/python3/dist-packages/boto/ec2/cloudwatch/__init__.pyregions&s rcKstd|fdti|S)aI Given a valid region name, return a :class:`boto.ec2.cloudwatch.CloudWatchConnection`. :param str region_name: The name of the region to connect to. :rtype: :class:`boto.ec2.CloudWatchConnection` or ``None`` :return: A connection to the given region, or None if an invalid region name is given rr)rr) region_name kw_paramsrrrconnect_to_region0s rcs eZdZejdddZejdddZejdddZ   d,fd d Z ddZ ddZ ddZ  d-ddZ  d.ddZ  d/ddZ  d-ddZ   d0ddZ    d0ddZ  d/d d!Zd"d#ZeZeZd$d%Z d1d&d'Zd(d)Zd*d+ZZS)2rBotocloudwatch_versionz 2010-08-01cloudwatch_region_namez us-east-1cloudwatch_region_endpointz"monitoring.us-east-1.amazonaws.comNTr/cs`| s t||j|j} | |_|jjdkrd}tt|j|||||||||jj| | | | ||ddS)z Init method to create a new connection to EC2 Monitoring Service. B{Note:} The host argument is overridden by the host specified in the boto configuration file. z eu-west-1F)validate_certs profile_nameN) r DefaultRegionNameDefaultRegionEndpointregionnamesuperr__init__endpoint)selfaws_access_key_idaws_secret_access_key is_secureportproxy proxy_port proxy_user proxy_passdebughttps_connection_factoryr"pathsecurity_tokenrr __class__rrr%Hs"    zCloudWatchConnection.__init__cCsdgS)Nzhmac-v4r)r'rrr_required_auth_capabilitygsz.CloudWatchConnection._required_auth_capabilitycCsd}d}|D]=}||}|r5t|tjr|g}|D]}||d||df<||d||df<|d7}qq||d||df<|d7}qdS)NzDimensions.memberrz %s.%d.Namez %s.%d.Value) isinstancer string_types)r' dimensionparamsprefixidim_name dim_valuevaluerrrbuild_dimension_paramjs   z*CloudWatchConnection.build_dimension_paramc Cst|tjr |g}t|D]2\}}|d}t|tr9t|D]\}}||||df<|dur7||||df<qq ||||<q dS)Nr7NameValue)r8rr9 enumeratedict iteritems) r'r;itemslabelindexitemr=kvrrrbuild_list_paramszs  z&CloudWatchConnection.build_list_paramscs||||||f}ttdd|fdd} ttt| |D]l\} \} } } }}}d| i}|r6||d<|r<| |d<|rD||||rk|d|d <|d |d <|d |d <|d|d<|durjd}tj|n |durt| |d<nt dt |D]\}}||d| d|f<q}q dS)NcSst|tr t|SdS)Nr7)r8listlenarrrsz7CloudWatchConnection.build_put_params..cs0t|trt|krtd|S|gS)Nz3Must specify equal number of elements; expected %d.)r8rNrO ExceptionrPlengthrraslists    z5CloudWatchConnection.build_put_params..aslist MetricName TimestampUnitmaximumzStatisticValues.MaximumminimumzStatisticValues.Minimum samplecountzStatisticValues.SampleCountsumzStatisticValues.SumzRYou supplied a value and statistics for a metric.Posting statistics and not value.rCz*Must specify a value or statistics to put.zMetricData.member.%d.%sr7) maxrrDr isoformatrAbotologwarnrSrrF)r'r;r#r@ timestampunit dimensions statisticsargsrVrInrLudst metric_datamsgkeyvalrrTrbuild_put_paramss6 &        z%CloudWatchConnection.build_put_paramsc CsV|||||d} || |d|r||| |r!|| d<|d| dtfgS)a Get time-series data for one or more statistics of a given metric. :type period: integer :param period: The granularity, in seconds, of the returned datapoints. Period must be at least 60 seconds and must be a multiple of 60. The default value is 60. :type start_time: datetime :param start_time: The time stamp to use for determining the first datapoint to return. The value specified is inclusive; results include datapoints with the time stamp specified. :type end_time: datetime :param end_time: The time stamp to use for determining the last datapoint to return. The value specified is exclusive; results will include datapoints up to the time stamp specified. :type metric_name: string :param metric_name: The metric name. :type namespace: string :param namespace: The metric's namespace. :type statistics: list :param statistics: A list of statistics names Valid values: Average | Sum | SampleCount | Maximum | Minimum :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. :type unit: string :param unit: The unit for the metric. Value 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 :rtype: list )PeriodrW Namespace StartTimeEndTimezStatistics.member.%drYGetMetricStatisticsmember)r_rMrAget_listr ) r'period start_timeend_time metric_name namespacerfrerdr;rrrget_metric_statisticss4 z*CloudWatchConnection.get_metric_statisticscCsLi}|r||d<|r||||r||d<|r||d<|d|dtfgS)a Returns a list of the valid metrics for which there is recorded data available. :type next_token: str :param next_token: A maximum of 500 metrics will be returned at one time. If more results are available, the ResultSet returned will contain a non-Null next_token attribute. Passing that token as a parameter to list_metrics will retrieve the next page of metrics. :type dimensions: dict :param dimensions: A dictionary containing name/value pairs that will be used to filter the results. The key in the dictionary is the name of a Dimension. The value in the dictionary is either a scalar value of that Dimension name that you want to filter on or None if you want all metrics with that Dimension name. To be included in the result a metric must contain all specified dimensions, although the metric may contain additional dimensions beyond the requested metrics. The Dimension names, and values must be strings between 1 and 250 characters long. A maximum of 10 dimensions are allowed. :type metric_name: str :param metric_name: The name of the Metric to filter against. If None, all Metric names will be returned. :type namespace: str :param namespace: A Metric namespace to filter against (e.g. AWS/EC2). If None, Metrics from all namespaces will be returned. NextTokenrWrs ListMetricsrw)rArxr)r' next_tokenrer|r}r;rrr list_metricss" z!CloudWatchConnection.list_metricsc Cs0d|i}|j|||||||d|jd|ddS)a Publishes metric data points to Amazon CloudWatch. Amazon Cloudwatch associates the data points with the specified metric. If the specified metric does not exist, Amazon CloudWatch creates the metric. If a list is specified for some, but not all, of the arguments, the remaining arguments are repeated a corresponding number of times. :type namespace: str :param namespace: The namespace of the metric. :type name: str or list :param name: The name of the metric. :type value: float or list :param value: The value for the metric. :type timestamp: datetime or list :param timestamp: The time stamp used for the metric. If not specified, the default value is set to the time the metric data was received. :type unit: string or list :param unit: The unit of the metric. Valid Values: 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 dimensions: dict :param dimensions: Add extra name value pairs to associate with the metric, i.e.: {'name1': value1, 'name2': (value2, value3)} :type statistics: dict or list :param statistics: Use a statistic set instead of a value, for example:: {'maximum': 30, 'minimum': 1, 'samplecount': 100, 'sum': 10000} rs)r@rcrdrerf PutMetricDataPOST)verb)rq get_status) r'r}r#r@rcrdrerfr;rrrput_metric_datas * z$CloudWatchConnection.put_metric_datac Cs|i}|r||d<|r||d<n |r|||d|r||d<|r$||d<|r*||d<|d|dtfg}|d } |j| _| S) a Retrieves alarms with the specified names. If no name is specified, all alarms for the user are returned. Alarms can be retrieved by using only a prefix for the alarm name, the alarm state, or a prefix for any action. :type action_prefix: string :param action_prefix: The action name prefix. :type alarm_name_prefix: string :param alarm_name_prefix: The alarm name prefix. AlarmNames cannot be specified if this parameter is specified. :type alarm_names: list :param alarm_names: A list of alarm names to retrieve information for. :type max_records: int :param max_records: The maximum number of alarm descriptions to retrieve. :type state_value: string :param state_value: The state value to be used in matching alarms. :type next_token: string :param next_token: The token returned by a previous call to indicate that there is more data. :rtype list ActionPrefixAlarmNamePrefixAlarmNames.member.%s MaxRecordsr StateValueDescribeAlarmsr r)rMrxr r) r' action_prefixalarm_name_prefix alarm_names max_records state_valuerr;resultretrrrdescribe_alarmsOs&  z$CloudWatchConnection.describe_alarmscCshi}|r||d<|r||d<|r||d<|r||d<|r$||d<|r*||d<|d|dtfgS) a Retrieves history for the specified alarm. Filter alarms by date range or item type. If an alarm name is not specified, Amazon CloudWatch returns histories for all of the owner's alarms. Amazon CloudWatch retains the history of deleted alarms for a period of six weeks. If an alarm has been deleted, its history can still be queried. :type alarm_name: string :param alarm_name: The name of the alarm. :type start_date: datetime :param start_date: The starting date to retrieve alarm history. :type end_date: datetime :param end_date: The starting date to retrieve alarm history. :type history_item_type: string :param history_item_type: The type of alarm histories to retreive (ConfigurationUpdate | StateUpdate | Action) :type max_records: int :param max_records: The maximum number of alarm descriptions to retrieve. :type next_token: string :param next_token: The token returned by a previous call to indicate that there is more data. :rtype list AlarmName StartDateEndDateHistoryItemTyperrDescribeAlarmHistoryrw)r_rxr )r' alarm_name start_dateend_daterhistory_item_typerr;rrrdescribe_alarm_historys $  z+CloudWatchConnection.describe_alarm_historycCsR||d}|r ||d<|r||d<|r||||r||d<|d|dtfgS)a  Retrieves all alarms for a single metric. Specify a statistic, period, or unit to filter the set of alarms further. :type metric_name: string :param metric_name: The name of the metric. :type namespace: string :param namespace: The namespace of the metric. :type period: int :param period: The period in seconds over which the statistic is applied. :type statistic: string :param statistic: The statistic for the metric. :type dimensions: dict :param dimensions: A dictionary containing name/value pairs that will be used to filter the results. The key in the dictionary is the name of a Dimension. The value in the dictionary is either a scalar value of that Dimension name that you want to filter on, a list of values to filter on or None if you want all metrics with that Dimension name. :type unit: string :rtype list )rWrsrr StatisticrYDescribeAlarmsForMetricrw)rArxr)r'r|r}ry statisticrerdr;rrrdescribe_alarms_for_metrics  z/CloudWatchConnection.describe_alarms_for_metricc Cs|j|j|j|j|j|j|j|jd}|jdur|j|d<|j r(| ||j d|j r0|j |d<|j r:| |j ||jrE| ||jd|jrP| ||jd|jrX|j|d<||_|d |S) a Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric. Optionally, this operation can associate one or more Amazon Simple Notification Service resources with the alarm. When this operation creates an alarm, the alarm state is immediately set to INSUFFICIENT_DATA. The alarm is evaluated and its StateValue is set appropriately. Any actions associated with the StateValue is then executed. When updating an existing alarm, its StateValue is left unchanged. :type alarm: boto.ec2.cloudwatch.alarm.MetricAlarm :param alarm: MetricAlarm object. )rrWrsrComparisonOperator ThresholdEvaluationPeriodsrrNActionsEnabledzAlarmActions.member.%sAlarmDescriptionz!InsufficientDataActions.member.%szOKActions.member.%srYPutMetricAlarm)r#metricr}r comparison thresholdevaluation_periodsryactions_enabled alarm_actionsrM descriptionrerAinsufficient_data_actions ok_actionsrd connectionr)r'alarmr;rrrput_metric_alarms>       z%CloudWatchConnection.put_metric_alarmcCi}|||d|d|S)z Deletes all specified alarms. In the event of an error, no alarms are deleted. :type alarms: list :param alarms: List of alarm names. r DeleteAlarmsrMr)r'alarmsr;rrr delete_alarmss z"CloudWatchConnection.delete_alarmscCs*|||d}|rt||d<|d|S)a Temporarily sets the state of an alarm. When the updated StateValue differs from the previous value, the action configured for the appropriate state is invoked. This is not a permanent change. The next periodic alarm check (in about a minute) will set the alarm to its actual state. :type alarm_name: string :param alarm_name: Descriptive name for alarm. :type state_reason: string :param state_reason: Human readable reason. :type state_value: string :param state_value: OK | ALARM | INSUFFICIENT_DATA :type state_reason_data: string :param state_reason_data: Reason string (will be jsonified). )r StateReasonrStateReasonData SetAlarmState)rdumpsr)r'r state_reasonrstate_reason_datar;rrrset_alarm_state s z$CloudWatchConnection.set_alarm_statecCr)z Enables actions for the specified alarms. :type alarms: list :param alarms: List of alarm names. rEnableAlarmActionsrr'rr;rrrenable_alarm_actions= z)CloudWatchConnection.enable_alarm_actionscCr)z Disables actions for the specified alarms. :type alarms: list :param alarms: List of alarm names. rDisableAlarmActionsrrrrrdisable_alarm_actionsHrz*CloudWatchConnection.disable_alarm_actions)NNTNNNNNrNNrNTN)NNNNN)NN)NNNN)NNNNNN)N)__name__ __module__ __qualname__r`configget APIVersionr r!r%r6rArMrqr~rrrrrr create_alarm update_alarmrrrr __classcell__rrr4rr?sd   * A . 0 4 4 --  r)__doc__ boto.compatrrrrboto.connectionrboto.ec2.cloudwatch.metricrboto.ec2.cloudwatch.alarmrr r boto.ec2.cloudwatch.datapointr boto.regioninfor r rrr`r RegionDatarrrrrrrs