diff --git a/node-client/app.js b/node-client/app.js index 1f8a7c5..8a7ebd1 100644 --- a/node-client/app.js +++ b/node-client/app.js @@ -19,21 +19,26 @@ const CYAN = '\x1b[36m'; const RED = '\x1b[31m'; const YELLOW = '\x1b[33m'; const GREEN = '\x1b[32m'; -const WHITE = '\x1b[37m' +const WHITE = '\x1b[37m'; +const PURPLE = '\x1b[35m'; console.clear() // Second list contains key word to highlight in Red -const RED_WORDS = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions/i; +const PURPLE_WORDS = /Disk full|Azure Key Vault unreachable|Database connection pool exhausted/i; -// First list contains key word to highlight in Yellow -const LOG_LIST = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions|High memory|CPU usage|Disk space|SSL certificate/gi; +// Second list contains key word to highlight in Red +const RED_WORDS = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions/i; +// First list contains key word to highlight in Yellow +const LOG_LIST = /Azure Storage|Authentication failed|timeout|insufficient permissions|High memory|CPU usage|Disk space|SSL certificate|Disk full|Azure Key Vault unreachable|Database connection pool exhausted|Database/gi; // Function to highlight important log patterns in red or yellow function highlightLog(text) { - return text.replace(LOG_LIST, match => - RED_WORDS.test(match) ? RED + match + RESET : YELLOW + match + RESET - ); + return text.replace(LOG_LIST, match => { + if (PURPLE_WORDS.test(match)) return PURPLE + match + RESET; + if (RED_WORDS.test(match)) return RED + match + RESET; + return YELLOW + match + RESET; + }); } async function getLogs() { @@ -54,10 +59,19 @@ async function getLogs() { console.log(CYAN + '│ Version : ' + WHITE + `${config.version || 'N/A'}` + RESET); console.log(CYAN + '│ Report generated at: ' + WHITE + `${now}` + RESET); console.log(CYAN + '│' + RESET); + if (data.critical_count > 0) { + console.log(CYAN + '│ !! CRITICAL !! : ' + WHITE + `${data.critical_count}` + RESET); + } console.log(CYAN + '│ Errors detected : ' + WHITE + `${data.error_count}` + RESET); console.log(CYAN + '│ Warnings : ' + WHITE + `${data.warning_count}` + RESET); console.log(CYAN + '│ Info messages : ' + WHITE + `${data.info_count}` + RESET); console.log(CYAN + '│' + RESET); + + if (data.criticals && data.criticals.length > 0) { + console.log(CYAN + '│' + RESET + PURPLE + ' --- Critical incidents ---' + RESET); + data.criticals.forEach(crit => console.log(CYAN + '│ ' + PURPLE + '> ' + RESET + highlightLog(crit))); + } + console.log(CYAN + '│' + RESET); console.log(CYAN + '│' + RED + ' --- Error details ---' + RESET); console.log(CYAN + '│' + RESET); data.errors.forEach(err => console.log(CYAN + '│ ' + RED + '> ' + RESET + highlightLog(err))); diff --git a/python-api/app.py b/python-api/app.py index 41fa74c..b8be477 100644 --- a/python-api/app.py +++ b/python-api/app.py @@ -17,6 +17,7 @@ # ------------------------------------------------------- def parse_logs(filepath): + criticals = [] errors = [] warnings = [] infos = [] @@ -26,7 +27,9 @@ def parse_logs(filepath): line = line.strip() if not line: continue - if "ERROR" in line: + if "CRITICAL" in line: + criticals.append(line) + elif "ERROR" in line: errors.append(line) elif "WARNING" in line: warnings.append(line) @@ -34,9 +37,11 @@ def parse_logs(filepath): infos.append(line) return { + "critical_count": len(criticals), "error_count": len(errors), "warning_count": len(warnings), "info_count": len(infos), + "criticals": criticals, "errors": errors, "warnings": warnings, } @@ -64,6 +69,25 @@ def get_logs(): result = parse_logs(config["api"]["log_file"]) return jsonify(result), 200 +@app.route("/api/stats", methods=["GET"]) +def get_stats(): + + result = parse_logs(config["api"]["log_file"]) + + critical_count = result["critical_count"] + error_count = result["error_count"] + warning_count = result["warning_count"] + info_count = result["info_count"] + + total = critical_count + error_count + warning_count + info_count + + return jsonify({ + "critical_count": critical_count, + "error_count": error_count, + "warning_count": warning_count, + "info_count": info_count, + "total": total + }), 200 if __name__ == "__main__": app.run(debug=True, port=config["api"]["port"]) diff --git a/python-api/server.log b/python-api/server.log index 5eac220..d2d2378 100644 --- a/python-api/server.log +++ b/python-api/server.log @@ -15,5 +15,8 @@ 2024-01-15 08:14:03 INFO Alert sent to monitoring team via Azure Monitor 2024-01-15 08:15:00 INFO Scheduled maintenance check completed 2024-01-15 08:16:30 WARNING SSL certificate expires in 14 days for api.azuretech.fr +2024-01-15 08:18:00 CRITICAL Database connection pool exhausted — all 20 connections in use 2024-01-15 08:18:55 INFO Kubernetes pod restarted: api-deployment-7d9f8b-xkp2m +2024-01-15 08:19:30 CRITICAL Azure Key Vault unreachable — secrets cannot be retrieved 2024-01-15 08:20:00 INFO Health check passed: all 3 replicas running +2024-01-15 08:21:00 CRITICAL Disk full on /var/log — logging suspended