Your question is Parse Logs for Error Reporting. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Daimler Truck North America's Detroit Connect telemetry services emit pipe-delimited log lines. Write a function that parses the logs, aggregates ERROR entries by service and error code, and reports only groups meeting a minimum occurrence count.
Implement aggregate_error_logs(logs, min_count). Each string in logs has this format:
timestamp|host|service|level|code|message
Return a list of dictionaries. Each dictionary must contain:
service: the service namecode: the error codecount: the number of matching ERROR entrieshosts: sorted unique hosts that produced the errorInclude only groups where count >= min_count. Sort the result by descending count, then ascending service, then ascending code. Inputs contain valid records with exactly six fields, and messages may contain additional pipe characters after the fifth separator.
def aggregate_error_logs(logs, min_count):