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)[source]¶ Check health of one Lambda function. Print information on it to STDOUT. Return True for healthy, False if errors/failures.
Parameters: func_name (str) – Lambda function name to check Returns: whether the function had errors/failures Return type: bool
-
_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
.Parameters: Returns: Return type:
-
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
).Parameters: - filter (
str
re.RegexObject
) – lambda function name filter - region_name (str) – region name to run against
- client (
boto3.client
) – boto3 Lambda client, or None to create new
Returns: list of matching Lambda function names
Return type: - filter (
-
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.Parameters: Returns: list of log entry dicts, sorted by timestamp
Return type:
-
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
Parameters: Returns: dict of metric name to sum for the last
interval
secondsReturn type:
-
get_filtered_logs
(request_ids, interval=86400, group_name=None, always_match_re=None)[source]¶ Get CloudWatch logs for the last
interval
seconds and return only those entries with messages matchingfilter_re
.Parameters: 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