improved sql

This commit is contained in:
no
2024-11-28 14:51:11 +01:00
parent 442b2ff660
commit dfd270bb29
2 changed files with 34 additions and 15 deletions
+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
} }
+28 -9
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=0 # Standardwert für Vergleich
else
log_info "Last log entry by Webservice-ID 13 at: $last_bsi_log_time"
last_bsi_epoch=$(date -d "$last_bsi_log_time" +%s) last_bsi_epoch=$(date -d "$last_bsi_log_time" +%s)
fi
if (( (now - last_order_epoch) > 3600 && (now - last_bsi_epoch) > 7200 )); then # Aktuelle Zeit abrufen
log_critical "SQL activity check failed. No activity in expected timeframes." 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 restart_service
exit 2 # Fehler, Dienst wurde neu gestartet exit 2 # Fehler, Dienst wurde neu gestartet
else else
log_info "SQL activity is within acceptable limits." 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
} }