manheim_c7n_tools.errorscan module¶
- class manheim_c7n_tools.errorscan.CustodianErrorReporter(config, region_name)[source]¶
Bases:
object
Scan and report on CW Metrics/Logs errors for c7n lambdas
- ALL_ERROR_FUNCTIONS = re.compile('^cloud-custodian.*')¶
- ALL_ERROR_LOG_RE = re.compile('.*(ERROR|WARNING).*')¶
- INTERVAL = 86400¶
How far to look back in logs and metrics, in seconds
- INTER_FUNC_SLEEP = 3.0¶
Amount of time (float seconds) to sleep between checking each function, to try to avoid API rate limiting.
- INVL_DESC = 'day'¶
Human-readable description of the interval
- METRIC_PERIOD = 86400¶
What period to request CloudWatch metrics for
- _check_function(func_name, never_match_re=None)[source]¶
Check health of one Lambda function. Print information on it to STDOUT. Return True for healthy, False if errors/failures.
- _get_sqs_dlq()[source]¶
Pull all messages from the SQS Dead Letter Queue. Add the failed Lambda RequestIDs to self._failed_request_ids and the SQS Reciept Handles to self._sqs_rcpts.
- class manheim_c7n_tools.errorscan.LambdaHealthChecker(func_name, region_name, logs=None, cw=None)[source]¶
Bases:
object
Class for checking Lambda func health via CloudWatch
- NO_OWNER_EMAIL_LOOKUP_WARNING = re.compile('.*(ERROR|WARNING).*unable to lookup owner email.*Please configure LDAP or org_domain')¶
- _get_cw_log_stream(group_name, stream_name, start_ts, end_ts)[source]¶
Return all log messages from the specified stream at or after
ts
.
- static find_matching_func_names(filter, region_name, client=None)[source]¶
Return a list of all Lambda functions with names that either start with
filter
(iffilter
is a string) or matchfilter
(if filter is are.RegexObject
).
- get_cloudwatch_logs(interval=86400, group_name=None)[source]¶
Get CloudWatch logs for the last
interval
seconds. The log group name defaults to/aws/lambda/{func_name}
if left at the default of None.
- get_cloudwatch_metric_sums(interval=86400, period=86400)[source]¶
Return a dict of CloudWatch Metrics for this Lambda function, summed over
interval
. Keys are metric names (“Errors”, “Throttles”, “Invocations”) and values are sums of eachperiod
-period datapoint, for the pastinterval
seconds.For further information on these metrics, see: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ lam-metricscollected.html
- get_filtered_logs(request_ids, interval=86400, group_name=None, always_match_re=None, never_match_re=None)[source]¶
Get CloudWatch logs for the last
interval
seconds and return only those entries with messages matchingfilter_re
.- Parameters
request_ids (list) – list of str request IDs to get logs for
group_name (str) – CloudWatch logs group name. If left at default of
None
, defaults to/aws/lambda/{func_name}
.interval (int) – how far back in logs to look, in seconds
always_match_re (
re
) – Regex for logs to ALWAYS returnnever_match_re (
re
) – Regex for logs to NEVER return, even if they matchalways_match_re
.
- Returns
dict of request_id to list of log entry dicts
- Return type
- req_id_re = re.compile('^(START|END|REPORT|\\S+\\s\\S+)\\s([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).*')¶
- class manheim_c7n_tools.errorscan.UTC[source]¶
Bases:
datetime.tzinfo