Skip to content

list_insights_metric_data

list_insights_metric_data(
    event_source: EventSource,
    event_name: EventName,
    insight_type: InsightType,
    *,
    config_overrides: Optional[CloudTrailClientConfig] = None,
    trail_name: Optional[String] = None,
    error_code: Optional[ErrorCode] = None,
    start_time: Optional[Date] = None,
    end_time: Optional[Date] = None,
    period: Optional[InsightsMetricPeriod] = None,
    data_type: Optional[InsightsMetricDataType] = None,
    max_results: Optional[InsightsMetricMaxResults] = None,
    next_token: Optional[InsightsMetricNextToken] = None,
) -> ListInsightsMetricDataResponse

Returns Insights metrics data for trails that have enabled Insights. The request must include the EventSource, EventName, and InsightType parameters.

If the InsightType is set to ApiErrorRateInsight, the request must also include the ErrorCode parameter.

The following are the available time periods for ListInsightsMetricData. Each cutoff is inclusive.

  • Data points with a period of 60 seconds (1-minute) are available for 15 days.

  • Data points with a period of 300 seconds (5-minute) are available for 63 days.

  • Data points with a period of 3600 seconds (1 hour) are available for 90 days.

To use ListInsightsMetricData operation, you must have the following permissions:

  • If ListInsightsMetricData is invoked with TrailName parameter, access to the ListInsightsMetricData API operation is linked to the cloudtrail:LookupEvents action and cloudtrail:ListInsightsData. To use this operation, you must have permissions to perform the cloudtrail:LookupEvents and cloudtrail:ListInsightsData action on the specific trail.

  • If ListInsightsMetricData is invoked without TrailName parameter, access to the ListInsightsMetricData API operation is linked to the cloudtrail:LookupEvents action only. To use this operation, you must have permissions to perform the cloudtrail:LookupEvents action.

For data event Insights on organization trails, only the management account and delegated administrator accounts can call ListInsightsMetricData. For these callers, the API returns Insights metrics only for the caller's own account. Member accounts cannot call this API on organization trails.

Parameters:

  • trail_name (Optional[String], default: None ) –

    The Amazon Resource Name(ARN) or name of the trail for which you want to retrieve Insights metrics data. This parameter should only be provided to fetch Insights metrics data generated on trails logging data events. This parameter is not required for Insights metric data generated on trails logging management events.

  • event_source (EventSource) –

    The Amazon Web Services service to which the request was made, such as iam.amazonaws.com or s3.amazonaws.com.

  • event_name (EventName) –

    The name of the event, typically the Amazon Web Services API on which unusual levels of activity were recorded.

  • insight_type (InsightType) –

    The type of CloudTrail Insights event, which is either ApiCallRateInsight or ApiErrorRateInsight. The ApiCallRateInsight Insights type analyzes write-only management API calls that are aggregated per minute against a baseline API call volume. The ApiErrorRateInsight Insights type analyzes management API calls that result in error codes.

  • error_code (Optional[ErrorCode], default: None ) –

    Conditionally required if the InsightType parameter is set to ApiErrorRateInsight.

    If returning metrics for the ApiErrorRateInsight Insights type, this is the error to retrieve data for. For example, AccessDenied.

  • start_time (Optional[Date], default: None ) –

    Specifies, in UTC, the start time for time-series data. The value specified is inclusive; results include data points with the specified time stamp.

    The default is 90 days before the time of request.

  • end_time (Optional[Date], default: None ) –

    Specifies, in UTC, the end time for time-series data. The value specified is exclusive; results include data points up to the specified time stamp.

    The default is the time of request.

  • period (Optional[InsightsMetricPeriod], default: None ) –

    Granularity of data to retrieve, in seconds. Valid values are 60, 300, and 3600. If you specify any other value, you will get an error. The default is 3600 seconds.

  • data_type (Optional[InsightsMetricDataType], default: None ) –

    Type of data points to return. Valid values are NonZeroData and FillWithZeros. The default is NonZeroData.

  • max_results (Optional[InsightsMetricMaxResults], default: None ) –

    The maximum number of data points to return. Valid values are integers from 1 to 21600. The default value is 21600.

  • next_token (Optional[InsightsMetricNextToken], default: None ) –

    Returned if all datapoints can't be returned in a single call. For example, due to reaching MaxResults.

    Add this parameter to the request to continue retrieving results starting from the last evaluated point.

Raises:

  • InvalidParameterException –

    The request includes a parameter that is not valid.

  • InvalidTrailNameException –

    This exception is thrown when the provided trail name is not valid. Trail names must meet the following requirements:

    • Contain only ASCII letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), or dashes (-)

    • Start with a letter or number, and end with a letter or number

    • Be between 3 and 128 characters

    • Have no adjacent periods, underscores or dashes. Names like my-_namespace and my--namespace are not valid.

    • Not be in IP address format (for example, 192.168.5.4)

  • OperationNotPermittedException –

    This exception is thrown when the requested operation is not permitted.

  • UnsupportedOperationException –

    This exception is thrown when the requested operation is not supported.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_cloudtrail/_services/cloud_trail.py
def list_insights_metric_data(
    self,
    event_source: "capo_cloudtrail.types.event_source.EventSource",
    event_name: "capo_cloudtrail.types.event_name.EventName",
    insight_type: "capo_cloudtrail.types.insight_type.InsightType",
    *,
    config_overrides: Optional[CloudTrailClientConfig] = None,
    trail_name: Optional["capo_cloudtrail.types.string.String"] = None,
    error_code: Optional["capo_cloudtrail.types.error_code.ErrorCode"] = None,
    start_time: Optional["capo_cloudtrail.types.date.Date"] = None,
    end_time: Optional["capo_cloudtrail.types.date.Date"] = None,
    period: Optional[
        "capo_cloudtrail.types.insights_metric_period.InsightsMetricPeriod"
    ] = None,
    data_type: Optional[
        "capo_cloudtrail.types.insights_metric_data_type.InsightsMetricDataType"
    ] = None,
    max_results: Optional[
        "capo_cloudtrail.types.insights_metric_max_results.InsightsMetricMaxResults"
    ] = None,
    next_token: Optional[
        "capo_cloudtrail.types.insights_metric_next_token.InsightsMetricNextToken"
    ] = None,
) -> "capo_cloudtrail.types.list_insights_metric_data_response.ListInsightsMetricDataResponse":
    """<p>Returns Insights metrics data for trails that have enabled Insights. The request must include the <code>EventSource</code>, <code>EventName</code>, and <code>InsightType</code> parameters.</p> <p>If the <code>InsightType</code> is set to <code>ApiErrorRateInsight</code>, the request must also include the <code>ErrorCode</code> parameter.</p> <p>The following are the available time periods for <code>ListInsightsMetricData</code>. Each cutoff is inclusive.</p> <ul> <li> <p>Data points with a period of 60 seconds (1-minute) are available for 15 days.</p> </li> <li> <p>Data points with a period of 300 seconds (5-minute) are available for 63 days.</p> </li> <li> <p>Data points with a period of 3600 seconds (1 hour) are available for 90 days.</p> </li> </ul> <p>To use <code>ListInsightsMetricData</code> operation, you must have the following permissions:</p> <ul> <li> <p>If <code>ListInsightsMetricData</code> is invoked with <code>TrailName</code> parameter, access to the <code>ListInsightsMetricData</code> API operation is linked to the <code>cloudtrail:LookupEvents</code> action and <code>cloudtrail:ListInsightsData</code>. To use this operation, you must have permissions to perform the <code>cloudtrail:LookupEvents</code> and <code>cloudtrail:ListInsightsData</code> action on the specific trail.</p> </li> <li> <p>If <code>ListInsightsMetricData</code> is invoked without <code>TrailName</code> parameter, access to the <code>ListInsightsMetricData</code> API operation is linked to the <code>cloudtrail:LookupEvents</code> action only. To use this operation, you must have permissions to perform the <code>cloudtrail:LookupEvents</code> action.</p> </li> </ul> <note> <p>For data event Insights on organization trails, only the management account and delegated administrator accounts can call <code>ListInsightsMetricData</code>. For these callers, the API returns Insights metrics only for the caller's own account. Member accounts cannot call this API on organization trails.</p> </note>

    Args:
        trail_name: <p>The Amazon Resource Name(ARN) or name of the trail for which you want to retrieve Insights metrics data. This parameter should only be provided to fetch Insights metrics data generated on trails logging data events. This parameter is not required for Insights metric data generated on trails logging management events.</p>
        event_source: <p>The Amazon Web Services service to which the request was made, such as <code>iam.amazonaws.com</code> or <code>s3.amazonaws.com</code>.</p>
        event_name: <p>The name of the event, typically the Amazon Web Services API on which unusual levels of activity were recorded.</p>
        insight_type: <p>The type of CloudTrail Insights event, which is either <code>ApiCallRateInsight</code> or <code>ApiErrorRateInsight</code>. The <code>ApiCallRateInsight</code> Insights type analyzes write-only management API calls that are aggregated per minute against a baseline API call volume. The <code>ApiErrorRateInsight</code> Insights type analyzes management API calls that result in error codes.</p>
        error_code: <p>Conditionally required if the <code>InsightType</code> parameter is set to <code>ApiErrorRateInsight</code>.</p> <p>If returning metrics for the <code>ApiErrorRateInsight</code> Insights type, this is the error to retrieve data for. For example, <code>AccessDenied</code>.</p>
        start_time: <p>Specifies, in UTC, the start time for time-series data. The value specified is inclusive; results include data points with the specified time stamp.</p> <p>The default is 90 days before the time of request.</p>
        end_time: <p>Specifies, in UTC, the end time for time-series data. The value specified is exclusive; results include data points up to the specified time stamp.</p> <p>The default is the time of request.</p>
        period: <p>Granularity of data to retrieve, in seconds. Valid values are <code>60</code>, <code>300</code>, and <code>3600</code>. If you specify any other value, you will get an error. The default is 3600 seconds.</p>
        data_type: <p>Type of data points to return. Valid values are <code>NonZeroData</code> and <code>FillWithZeros</code>. The default is <code>NonZeroData</code>.</p>
        max_results: <p>The maximum number of data points to return. Valid values are integers from 1 to 21600. The default value is 21600.</p>
        next_token: <p>Returned if all datapoints can't be returned in a single call. For example, due to reaching <code>MaxResults</code>.</p> <p>Add this parameter to the request to continue retrieving results starting from the last evaluated point.</p>

    Raises:
        capo_cloudtrail.errors.invalid_parameter_exception.InvalidParameterException: <p>The request includes a parameter that is not valid.</p>
        capo_cloudtrail.errors.invalid_trail_name_exception.InvalidTrailNameException: <p>This exception is thrown when the provided trail name is not valid. Trail names must meet the following requirements:</p> <ul> <li> <p>Contain only ASCII letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), or dashes (-)</p> </li> <li> <p>Start with a letter or number, and end with a letter or number</p> </li> <li> <p>Be between 3 and 128 characters</p> </li> <li> <p>Have no adjacent periods, underscores or dashes. Names like <code>my-_namespace</code> and <code>my--namespace</code> are not valid.</p> </li> <li> <p>Not be in IP address format (for example, 192.168.5.4)</p> </li> </ul>
        capo_cloudtrail.errors.operation_not_permitted_exception.OperationNotPermittedException: <p>This exception is thrown when the requested operation is not permitted.</p>
        capo_cloudtrail.errors.unsupported_operation_exception.UnsupportedOperationException: <p>This exception is thrown when the requested operation is not supported.</p>
        capo_cloudtrail.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudtrail.types.list_insights_metric_data_request.ListInsightsMetricDataRequest]",
    ) -> OperationResponse[
        "capo_cloudtrail.types.list_insights_metric_data_response.ListInsightsMetricDataResponse"
    ]:
        import capo_cloudtrail._operations.cloud_trail_20131101.list_insights_metric_data

        output, http_response = (
            capo_cloudtrail._operations.cloud_trail_20131101.list_insights_metric_data.list_insights_metric_data(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ListInsightsMetricData")
    )
    input_: capo_cloudtrail.types.list_insights_metric_data_request.ListInsightsMetricDataRequest = {
        "event_source": event_source,
        "event_name": event_name,
        "insight_type": insight_type,
    }
    if trail_name is not None:
        input_["trail_name"] = trail_name
    if error_code is not None:
        input_["error_code"] = error_code
    if start_time is not None:
        input_["start_time"] = start_time
    if end_time is not None:
        input_["end_time"] = end_time
    if period is not None:
        input_["period"] = period
    if data_type is not None:
        input_["data_type"] = data_type
    if max_results is not None:
        input_["max_results"] = max_results
    if next_token is not None:
        input_["next_token"] = next_token

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output