Verschiebe in Root
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
function log_info() {
|
||||
echo "{\"timestamp\": \"$(date)\", \"level\": \"INFO\", \"message\": \"$1\"}" >> $LOG_FILE
|
||||
}
|
||||
|
||||
function log_error() {
|
||||
echo "{\"timestamp\": \"$(date)\", \"level\": \"ERROR\", \"message\": \"$1\"}" >> $LOG_FILE
|
||||
}
|
||||
|
||||
function log_critical() {
|
||||
echo "{\"timestamp\": \"$(date)\", \"level\": \"CRITICAL\", \"message\": \"$1\"}" >> $LOG_FILE
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
function check_network_traffic() {
|
||||
total_inbound=0
|
||||
total_outbound=0
|
||||
|
||||
for ((i=1; i<=$MEASUREMENT_COUNT; i++)); do
|
||||
usage=$(ifstat -i $INTERFACE $INTERVAL 1 | tail -n 1)
|
||||
|
||||
if [[ -z "$usage" ]]; then
|
||||
log_error "No output from ifstat on measurement $i."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
inbound=$(echo $usage | awk '{print $1}')
|
||||
outbound=$(echo $usage | awk '{print $2}')
|
||||
|
||||
total_inbound=$(echo "$total_inbound + $inbound" | bc)
|
||||
total_outbound=$(echo "$total_outbound + $outbound" | bc)
|
||||
done
|
||||
|
||||
avg_inbound=$(echo "scale=2; $total_inbound / $MEASUREMENT_COUNT" | bc)
|
||||
avg_outbound=$(echo "scale=2; $total_outbound / $MEASUREMENT_COUNT" | bc)
|
||||
|
||||
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
|
||||
else
|
||||
log_info "Network traffic is above thresholds. Avg In: $avg_inbound KB/s, Avg Out: $avg_outbound KB/s."
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
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"
|
||||
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 'running'"
|
||||
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."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/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 otrs_ticket WHERE create_user = 'LIDLWebservice';")
|
||||
|
||||
last_bsi_log_time=$(mysql -u $DB_USER -p$DB_PASSWORD -D $DB_NAME -sse \
|
||||
"SELECT MAX(log_time) FROM bsi_logs WHERE service = 'ITNovumBSIConnector';")
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user