Files
vpn-con-checker/functions/sql_check.sh
T
2024-11-28 13:57:54 +01:00

26 lines
924 B
Bash

#!/bin/bash
function check_sql_activity() {
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';")
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;")
if [[ -z "$last_order_time" || -z "$last_bsi_log_time" ]]; then
log_error "SQL query failed or returned no data."
exit 2
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
else
log_info "SQL activity is within acceptable limits."
fi
}