Created
September 19, 2023 18:15
-
-
Save plasmagrenade/c325a7f2ff6a965f1b985a267fd6ded7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| import csv | |
| import re | |
| from collections import defaultdict | |
| from datetime import datetime | |
| RULES = { | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: DynamoDB System Error Monitor on env:.*,tablename:(.*)': 'DynamoDB error on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: Failed Data Science event Monitor on env:.*,functionname:(.*)': 'Failed DS event on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: Failed Data Science event Monitor on env:.*,functionname:(.*)': 'Failed DS event on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: Flow Status Update Lambda Error Monitor on env:production': 'flow-status-update error', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: Lambda Function Duration Threshold Monitor on env:.*,functionname:(.*)': 'Lambda timeout on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: Lambda Function Timed Out Monitor on env:.*,functionname:(.*)': 'Lambda timeout on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: Lambda Function Error Monitor: .* on env:.*,functionname:(.*)': 'Lambda error on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: SQS DLQ Threshold Monitor on env:production,queuename:(.*)': 'DLQ threshold on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: SQS Messages Too Old Anomaly Monitor on env:production,queuename:(.*)': 'SQS message age anomaly on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[borrower\-flow\]: Step Function Executions Failed Monitor on env:production.*statemachine:(.*)': 'SFN failure on {groups[0]}', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Api::Servicing::PaymentPlans::MultipassPaymentPlansController#list_payment_plans: 5xx_high_error_rate': 'list_payment_plans high 5xx error rate', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Api::Servicing::PaymentPlans::MultipassPaymentPlansController#list_payment_plans: no_2xx_requests': 'list_payment_plans no 2xx requests', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Api::Servicing::Plans::MultipassPlansController#list_plans: 5xx_high_error_rate': 'list_plans high 5xx error rate', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Api::Servicing::Plans::MultipassPlansController#list_plans: no_2xx_requests': 'list_plans no 2xx requests', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Api::Servicing::Plans::MultipassPlansController#retrieve_plan_eligibility: 5xx_high_error_rate': 'retrieve_plan_eligibility high 5xx error rate', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Api::Servicing::Plans::MultipassPlansController#retrieve_plan_eligibility: no_2xx_requests': 'retrieve_plan_eligibility no 2xx requests', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: capital MailDeliveryTask Age Detector \(_team_servicing_experience\)': 'Stale MDT', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Fincen314a Unprocessed Files Detector': 'Fincen314a unprocessed files', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Stale AddPayerRequests': 'Stale AddPayerRequests', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Stale daily settlements count Detector.*': 'Stale daily settlements count', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Stale Forgiveness Payments': 'Stale Forgiveness Payments', | |
| r'\[SQUARE\]\[credit\-servicing\-experience\]\[capital\-metrics\]: Unverified plan payer SLELs': 'Unverified plan payer SLELs', | |
| r'ActiveRecord::ConnectionNotEstablished: Can\'t connect to MySQL server on .*': 'Can\'t connect to MySQL server', | |
| r'ActiveRecord::ConnectionNotEstablished: MySQL client is not connected': 'MySQL client disconnected', | |
| r'ActiveRecord::Deadlocked: Mysql2::Error: Deadlock found when trying to get lock; try restarting transaction: .*': 'MySQL deadlock', | |
| r'ActiveRecord::LockWaitTimeout: Mysql2::Error::TimeoutError: Lock wait timeout exceeded; try restarting transaction: .*': 'MySQL lock wait timeout', | |
| r'ActiveRecord::QueryCanceled: Mysql2::Error: Query execution was interrupted: SQL REDACTED': 'MySQL query execution interrupted', | |
| r'ActiveRecord::RecordInvalid: Validation failed: Local entries should be at least 2, Entries should be exactly 2': 'Local entries validation failed', | |
| r'ActiveRecord::RecordInvalid: Validation failed: Remaining after amount cents must be greater than or equal to 0': 'Remaining after amounts cents validation failed', | |
| r'Sq::Protos::RpcClient::SakeError: .*::(.*) .*': 'SakeError from {groups[0]}', | |
| r'RuntimeError: Encountered [0-9]* errors while processing pending add payer request:.*': 'AddPayerRequest error', | |
| r'Sq::Connector::ServiceUnavailableError: Got HTTP 503 from production.(.*).gns.square': '503 from {groups[0]}', | |
| } | |
| def main(): | |
| counts = defaultdict(int) | |
| totalcount = 0 | |
| with open("/Users/brenton/Downloads/export (3).csv") as incidentsfile: | |
| reader = csv.reader(incidentsfile) | |
| next(reader) | |
| for row in reader: | |
| title = row[1] | |
| title = transform(title) | |
| counts[title] += 1 | |
| totalcount += 1 | |
| sorted_records = sorted(counts.items(), key=lambda x:x[1]) | |
| counts = sorted_records | |
| for row in counts: | |
| title, count = row | |
| print(f"{count}\t{title}") | |
| print(totalcount) | |
| with open("./output.csv", "w") as outputfile: | |
| writer = csv.writer(outputfile) | |
| for title, count in sorted_records: | |
| writer.writerow([title, count]) | |
| def transform(title): | |
| for regex, result_template in RULES.items(): | |
| match = re.search(regex, title) | |
| if match != None: | |
| return result_template.format(groups=match.groups()) | |
| return title | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment