intial commit
هذا الالتزام موجود في:
41
q5-mithal-monitor/monitor.sh
Normal file
41
q5-mithal-monitor/monitor.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# monitor.sh
|
||||
|
||||
TARGET="mithal.space"
|
||||
URL="https://$TARGET"
|
||||
SEARCH_URL="$URL/?q=test" # Adjust query parameter based on the actual search endpoint
|
||||
if [ -d "/usr/share/nginx/html" ]; then
|
||||
DATA_FILE="/usr/share/nginx/html/data.csv"
|
||||
else
|
||||
DATA_FILE="./data.csv"
|
||||
fi
|
||||
|
||||
|
||||
# Initialize CSV with headers if it doesn't exist
|
||||
if [ ! -f "$DATA_FILE" ]; then
|
||||
echo "timestamp,status,latency,ssl_days,dns_time,search_time" > "$DATA_FILE"
|
||||
fi
|
||||
|
||||
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
# 1. Uptime, Latency, and DNS Resolution
|
||||
HTTP_RESPONSE=$(curl -o /dev/null -s -w "%{http_code},%{time_total},%{time_namelookup}" "$URL")
|
||||
STATUS=$(echo "$HTTP_RESPONSE" | cut -d',' -f1)
|
||||
LATENCY=$(echo "$HTTP_RESPONSE" | cut -d',' -f2)
|
||||
DNS_TIME=$(echo "$HTTP_RESPONSE" | cut -d',' -f3)
|
||||
|
||||
# 2. Search Response Time
|
||||
SEARCH_TIME=$(curl -o /dev/null -s -w "%{time_total}" "$SEARCH_URL")
|
||||
|
||||
# 3. SSL Expiration
|
||||
EXP_DATE=$(echo | openssl s_client -servername "$TARGET" -connect "$TARGET:443" 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2)
|
||||
if [ -n "$EXP_DATE" ]; then
|
||||
EXP_EPOCH=$(date -d "$EXP_DATE" +%s)
|
||||
CURRENT_EPOCH=$(date +%s)
|
||||
SSL_DAYS=$(( (EXP_EPOCH - CURRENT_EPOCH) / 86400 ))
|
||||
else
|
||||
SSL_DAYS=0
|
||||
fi
|
||||
|
||||
# Append to CSV
|
||||
echo "$TIMESTAMP,$STATUS,$LATENCY,$SSL_DAYS,$DNS_TIME,$SEARCH_TIME" >> "$DATA_FILE"
|
||||
المرجع في مشكلة جديدة
حظر مستخدم