From efa5d907c9ecda0e478ff2168ecd0fecace170a6 Mon Sep 17 00:00:00 2001 From: ahmedgamalyousef Date: Wed, 1 Oct 2025 00:05:36 +0300 Subject: [PATCH] Updating Files --- fruit_api.log | 3 + log_monitor.sh | 48 ++++---- test_api.sh | 80 ++++++------- test_results.log | 285 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 346 insertions(+), 70 deletions(-) diff --git a/fruit_api.log b/fruit_api.log index ed2ffc7..193c34b 100644 --- a/fruit_api.log +++ b/fruit_api.log @@ -332,3 +332,6 @@ 2025-09-30 23:08:22,398 - INFO - REQUEST: GET /docs - From 127.0.0.1 2025-09-30 23:08:22,399 - INFO - RESPONSE: GET /docs - Status 404 2025-09-30 23:08:22,399 - INFO - 127.0.0.1 - - [30/Sep/2025 23:08:22] "GET /docs HTTP/1.1" 404 - +2025-09-30 23:59:59 - METHOD:GET - ENDPOINT:/fruits - STATUS:500 - ERROR: db not connected +2025-09-30 23:59:59 - METHOD:GET - ENDPOINT:/fruits - STATUS:400 - ERROR: db not connected +2025-09-30 23:59:59 - METHOD:GET - ENDPOINT:/fruits - STATUS:400 - ERROR: db not connected diff --git a/log_monitor.sh b/log_monitor.sh index 8d92e6b..c55732c 100755 --- a/log_monitor.sh +++ b/log_monitor.sh @@ -1,26 +1,32 @@ -#!/usr/bin/env bash - +#!/usr/bin/bash LOG_FILE="fruit_api.log" +# ALERT_URL="https://gahymah.systems.com" -if [[ ! -f "$LOG_FILE" ]]; then - echo "❌ Log file $LOG_FILE not found!" - exit 1 -fi +tail -Fn0 "$LOG_FILE" | while read line; do + if echo "$line" | grep -qiE "STATUS:(4[0-9]{2}|5[0-9]{2})|failed|timeout|error|exception"; then + echo "🚨 Error detected: $line" -echo "📊 Fruit API Logs Report (last 2 hours) - $(date)" -echo "--------------------------------------------------" + IP=$(hostname -I | awk '{print $1}') + CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2"%"}') + RAM=$(free -m | awk '/Mem:/ {print $4"MB"}') + DISK=$(df -h / | awk 'NR==2 {print $4}') -# Get timestamps from last 2 hours -time_filter=$(date --date='2 hours ago' +"%Y-%m-%d %H") + payload=$(cat <