Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions node-client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)));
Expand Down
26 changes: 25 additions & 1 deletion python-api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# -------------------------------------------------------

def parse_logs(filepath):
criticals = []
errors = []
warnings = []
infos = []
Expand All @@ -26,17 +27,21 @@ 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)
elif "INFO" in line:
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,
}
Expand Down Expand Up @@ -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"])
3 changes: 3 additions & 0 deletions python-api/server.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading