Compare commits

..
8 Commits
Author SHA1 Message Date
MK 4beaaa78a5 Update README 2024-12-03 12:09:45 +01:00
MK d86b3359ac update 2024-12-03 12:08:37 +01:00
MK ca20300809 fix führende Null 2024-12-03 10:36:38 +01:00
no b2d47a4cc5 fix service check 2024-11-29 20:08:15 +01:00
no f941e1eab7 update restart service 2024-11-29 15:57:42 +01:00
no 05ec2913c5 add ssh port to restart service 2024-11-29 15:17:13 +01:00
no 7dd09572da update paths 2024-11-28 15:27:58 +01:00
no dfd270bb29 improved sql 2024-11-28 14:51:11 +01:00
6 changed files with 49 additions and 28 deletions
+2 -2
View File
@@ -167,8 +167,8 @@ Das Skript behandelt potenzielle Fehler folgendermaßen:
## **Autoren** ## **Autoren**
- **Dein Name** - **Dein Name**
E-Mail: [[email protected]](mailto:[email protected]) E-Mail: [[email protected]](mailto:[email protected])
GitHub: [DeinGitHub](https://github.com/DeinGitHub) GitHub: [no](https://git.admins.tech/no)
--- ---
+3 -2
View File
@@ -9,7 +9,7 @@ THRESHOLD_INBOUND=0.5
THRESHOLD_OUTBOUND=0.5 THRESHOLD_OUTBOUND=0.5
# Messparameter # Messparameter
MEASUREMENT_COUNT=10 MEASUREMENT_COUNT=15
INTERVAL=6 INTERVAL=6
# SQL-Datenbankverbindung # SQL-Datenbankverbindung
@@ -20,7 +20,8 @@ DB_NAME="database"
# SSH-Verbindung # SSH-Verbindung
SSH_KEY="/path/to/private_key" SSH_KEY="/path/to/private_key"
SSH_USER="user" SSH_USER="user"
SSH_HOST="remote_host" SSH_HOST="127.0.0.1"
SSH_PORT="22"
# Neuzustartender Dienst # Neuzustartender Dienst
SERVICE_NAME="ipsec.service" SERVICE_NAME="ipsec.service"
+1 -1
View File
@@ -27,7 +27,7 @@ function check_network_traffic() {
restart_service restart_service
exit 2 # Exit with error status if thresholds are not met exit 2 # Exit with error status if thresholds are not met
else 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 exit 0 # Exit with success status
fi fi
} }
+2 -2
View File
@@ -8,13 +8,13 @@ function restart_service() {
log_info "Attempting to restart service $SERVICE_NAME on $SSH_HOST." 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 if [ $? -ne 0 ]; then
log_error "Failed to restart service $SERVICE_NAME on $SSH_HOST." log_error "Failed to restart service $SERVICE_NAME on $SSH_HOST."
exit 2 exit 2
fi 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 if [ $? -ne 0 ]; then
log_critical "Service $SERVICE_NAME not running after restart." log_critical "Service $SERVICE_NAME not running after restart."
exit 2 exit 2
+33 -14
View File
@@ -1,27 +1,46 @@
#!/bin/bash #!/bin/bash
function check_sql_activity() { function check_sql_activity() {
# Abruf des letzten Auftrag-Zeitpunkts
last_order_time=$(mysql -u $DB_USER -p$DB_PASSWORD -D $DB_NAME -sse \ 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';") "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 \ 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 # Überprüfen, ob einer der Werte leer ist
log_error "SQL query failed or returned no data." if [[ -z "$last_order_time" ]]; then
exit 2 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 fi
now=$(date +%s) if [[ -z "$last_bsi_log_time" ]]; then
last_order_epoch=$(date -d "$last_order_time" +%s) log_error "No last log entry found for Webservice-ID 13."
last_bsi_epoch=$(date -d "$last_bsi_log_time" +%s) last_bsi_epoch=0 # Standardwert für Vergleich
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
exit 2 # Fehler, Dienst wurde neu gestartet
else 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 exit 0 # Erfolg
fi fi
} }
+8 -7
View File
@@ -1,14 +1,16 @@
#!/bin/bash #!/bin/bash
source config.conf BASE_DIR="/opt/scripts/vpn-con-checker"
source functions/logging.sh
source functions/network_check.sh source "$BASE_DIR/config.conf"
source functions/sql_check.sh source "$BASE_DIR/functions/logging.sh"
source functions/restart_service.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() { function is_within_business_hours() {
current_hour=$(date +%H) current_hour=$(date +%H)
current_hour=$((10#$current_hour))
if (( current_hour >= 7 && current_hour < 18 )); then if (( current_hour >= 7 && current_hour < 18 )); then
return 0 # True return 0 # True
else else
@@ -16,7 +18,6 @@ function is_within_business_hours() {
fi fi
} }
# Hauptscript
function main() { function main() {
log_info "Starting VPN monitoring script." log_info "Starting VPN monitoring script."