improved sql
This commit is contained in:
@@ -27,7 +27,7 @@ function check_network_traffic() {
|
||||
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
|
||||
}
|
||||
|
||||
+33
-14
@@ -1,27 +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
|
||||
exit 2 # Fehler, Dienst wurde neu gestartet
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user