Compare commits
10
Commits
c06012685f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4beaaa78a5 | ||
|
|
d86b3359ac | ||
|
|
ca20300809 | ||
|
|
b2d47a4cc5 | ||
|
|
f941e1eab7 | ||
|
|
05ec2913c5 | ||
|
|
7dd09572da | ||
|
|
dfd270bb29 | ||
|
|
442b2ff660 | ||
|
|
362a5071ca |
@@ -60,7 +60,7 @@ Dieses Projekt implementiert ein flexibles und robustes VPN-Überwachungsskript,
|
||||
chmod +x functions/*.sh
|
||||
```
|
||||
|
||||
4. Passe die `config.conf` Datei an:
|
||||
4. Kopiere `config.conf.sample` zu `config.conf` und passe die Datei an:
|
||||
- Definiere Netzwerkinterface, Schwellenwerte, Datenbankeinstellungen, SSH-Details und Logdateipfad.
|
||||
|
||||
5. (Optional) Füge die Logrotation hinzu:
|
||||
@@ -167,8 +167,8 @@ Das Skript behandelt potenzielle Fehler folgendermaßen:
|
||||
## **Autoren**
|
||||
|
||||
- **Dein Name**
|
||||
E-Mail: [[email protected]](mailto:[email protected])
|
||||
GitHub: [DeinGitHub](https://github.com/DeinGitHub)
|
||||
E-Mail: [[email protected]](mailto:[email protected])
|
||||
GitHub: [no](https://git.admins.tech/no)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ THRESHOLD_INBOUND=0.5
|
||||
THRESHOLD_OUTBOUND=0.5
|
||||
|
||||
# Messparameter
|
||||
MEASUREMENT_COUNT=10
|
||||
MEASUREMENT_COUNT=15
|
||||
INTERVAL=6
|
||||
|
||||
# SQL-Datenbankverbindung
|
||||
@@ -20,7 +20,8 @@ DB_NAME="database"
|
||||
# SSH-Verbindung
|
||||
SSH_KEY="/path/to/private_key"
|
||||
SSH_USER="user"
|
||||
SSH_HOST="remote_host"
|
||||
SSH_HOST="127.0.0.1"
|
||||
SSH_PORT="22"
|
||||
|
||||
# Neuzustartender Dienst
|
||||
SERVICE_NAME="ipsec.service"
|
||||
@@ -25,7 +25,9 @@ function check_network_traffic() {
|
||||
if (( $(echo "$avg_inbound < $THRESHOLD_INBOUND" | bc -l) )) || (( $(echo "$avg_outbound < $THRESHOLD_OUTBOUND" | bc -l) )); then
|
||||
log_critical "Network traffic below thresholds. Avg In: $avg_inbound KB/s, Avg Out: $avg_outbound KB/s."
|
||||
restart_service
|
||||
exit 2 # Exit with error status if thresholds are not met
|
||||
else
|
||||
log_info "Network traffic is above thresholds. Avg In: $avg_inbound KB/s, Avg Out: $avg_outbound KB/s."
|
||||
log_info "Network traffic is above thresholds. Avg In: $avg_inbound KB/s, Avg Out: $avg_outbound KB/s. Nothing to do."
|
||||
exit 0 # Exit with success status
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -8,17 +8,18 @@ function restart_service() {
|
||||
|
||||
log_info "Attempting to restart service $SERVICE_NAME on $SSH_HOST."
|
||||
|
||||
ssh -i $SSH_KEY $SSH_USER@$SSH_HOST "sudo systemctl restart $SERVICE_NAME"
|
||||
ssh -i $SSH_KEY -p $SSH_PORT $SSH_USER@$SSH_HOST "sudo -n /usr/bin/systemctl restart $SERVICE_NAME"
|
||||
if [ $? -ne 0 ]; then
|
||||
log_error "Failed to restart service $SERVICE_NAME on $SSH_HOST."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
ssh -i $SSH_KEY $SSH_USER@$SSH_HOST "sudo ipsec statusall | grep -i '1 up, 0 connecting'"
|
||||
ssh -i $SSH_KEY -p $SSH_PORT $SSH_USER@$SSH_HOST "sudo -n ipsec statusall | grep -i 'Security Associations (1 up, 0 connecting):'"
|
||||
if [ $? -ne 0 ]; then
|
||||
log_critical "Service $SERVICE_NAME not running after restart."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
log_info "Service $SERVICE_NAME successfully restarted and verified."
|
||||
}
|
||||
return 0 # Erfolg
|
||||
}
|
||||
+33
-12
@@ -1,25 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
function check_sql_activity() {
|
||||
# Abruf des letzten Auftrag-Zeitpunkts
|
||||
last_order_time=$(mysql -u $DB_USER -p$DB_PASSWORD -D $DB_NAME -sse \
|
||||
"SELECT MAX(create_time) FROM ticket WHERE customer_user_id = 'LIDLWebservice';")
|
||||
|
||||
# Abruf des letzten Log-Zeitpunkts
|
||||
last_bsi_log_time=$(mysql -u $DB_USER -p$DB_PASSWORD -D $DB_NAME -sse \
|
||||
"SELECT MAX(create_time) FROM gi_debugger_entry WHERE webservice_id = 13;")
|
||||
"SELECT MAX(create_time) FROM gi_debugger_entry WHERE webservice_id = 13;") # Webservice-ID Variiert nach System, 13 Prod, 19 Test
|
||||
|
||||
if [[ -z "$last_order_time" || -z "$last_bsi_log_time" ]]; then
|
||||
log_error "SQL query failed or returned no data."
|
||||
exit 2
|
||||
# Überprüfen, ob einer der Werte leer ist
|
||||
if [[ -z "$last_order_time" ]]; then
|
||||
log_error "No last order found for LIDLWebservice."
|
||||
last_order_epoch=0 # Standardwert für Vergleich
|
||||
else
|
||||
log_info "Last order by LIDLWebservice created at: $last_order_time"
|
||||
last_order_epoch=$(date -d "$last_order_time" +%s)
|
||||
fi
|
||||
|
||||
now=$(date +%s)
|
||||
last_order_epoch=$(date -d "$last_order_time" +%s)
|
||||
last_bsi_epoch=$(date -d "$last_bsi_log_time" +%s)
|
||||
|
||||
if (( (now - last_order_epoch) > 3600 && (now - last_bsi_epoch) > 7200 )); then
|
||||
log_critical "SQL activity check failed. No activity in expected timeframes."
|
||||
restart_service
|
||||
if [[ -z "$last_bsi_log_time" ]]; then
|
||||
log_error "No last log entry found for Webservice-ID 13."
|
||||
last_bsi_epoch=0 # Standardwert für Vergleich
|
||||
else
|
||||
log_info "SQL activity is within acceptable limits."
|
||||
log_info "Last log entry by Webservice-ID 13 at: $last_bsi_log_time"
|
||||
last_bsi_epoch=$(date -d "$last_bsi_log_time" +%s)
|
||||
fi
|
||||
|
||||
# Aktuelle Zeit abrufen
|
||||
now=$(date +%s)
|
||||
|
||||
# Anpassung der Logik: Auftrag > 120 Minuten prüfen, ob Log > 60 Minuten alt
|
||||
if (( (now - last_order_epoch) > 7200 )); then
|
||||
if (( (now - last_bsi_epoch) > 3600 )); then
|
||||
log_critical "SQL activity check failed. Last order older than 120 minutes, and last log older than 60 minutes."
|
||||
restart_service
|
||||
exit 2 # Fehler, Dienst wurde neu gestartet
|
||||
else
|
||||
log_info "Last order is older than 120 minutes, but Webservice log is within acceptable limits."
|
||||
exit 0 # Erfolg
|
||||
fi
|
||||
else
|
||||
log_info "Last order is within acceptable limits. No further checks required."
|
||||
exit 0 # Erfolg
|
||||
fi
|
||||
}
|
||||
|
||||
+11
-8
@@ -1,15 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Source Konfigurations- und Modul-Dateien
|
||||
source config.conf
|
||||
source functions/logging.sh
|
||||
source functions/network_check.sh
|
||||
source functions/sql_check.sh
|
||||
source functions/restart_service.sh
|
||||
BASE_DIR="/opt/scripts/vpn-con-checker"
|
||||
|
||||
source "$BASE_DIR/config.conf"
|
||||
source "$BASE_DIR/functions/logging.sh"
|
||||
source "$BASE_DIR/functions/network_check.sh"
|
||||
source "$BASE_DIR/functions/sql_check.sh"
|
||||
source "$BASE_DIR/functions/restart_service.sh"
|
||||
|
||||
# Funktion zur Prüfung der Arbeitszeit
|
||||
function is_within_business_hours() {
|
||||
current_hour=$(date +%H)
|
||||
current_hour=$((10#$current_hour))
|
||||
if (( current_hour >= 7 && current_hour < 18 )); then
|
||||
return 0 # True
|
||||
else
|
||||
@@ -17,7 +18,6 @@ function is_within_business_hours() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Hauptlogik
|
||||
function main() {
|
||||
log_info "Starting VPN monitoring script."
|
||||
|
||||
@@ -28,6 +28,9 @@ function main() {
|
||||
log_info "Outside business hours. Running SQL activity check."
|
||||
check_sql_activity
|
||||
fi
|
||||
|
||||
log_info "VPN monitoring script completed successfully."
|
||||
exit 0
|
||||
}
|
||||
|
||||
main
|
||||
|
||||
Reference in New Issue
Block a user