Monkey Albino

Linux altar53.supremepanel53.com 4.18.0-553.8.1.lve.el8.x86_64 #1 SMP Thu Jul 4 16:24:39 UTC 2024 x86_64
/ lib64/ nagios/ plugins/

//lib64/nagios/plugins/check_mysql_uptime.sh

#!/bin/bash

set -o pipefail

MYSQLADMIN=$(which mysqladmin)
AWK=$(which awk)
CMD="status"

[[ -z "$MYSQLADMIN" ]] && \
printf "\342\235\214 CRITICAL: mysqladmin binary not present on $HOSTNAME" \
&& exit 2

CHK_ERR="$( ( sudo $MYSQLADMIN $CMD | $AWK '{print $2}' ) 2>&1 >/dev/null )"

[[ ! -z "$CHK_ERR" ]] && \
printf "\342\235\214 CRITICAL: 'mysqladmin status' exited with error: $CHK_ERR\n" \
&& exit 2

MYUPTIME=$(sudo $MYSQLADMIN $CMD | $AWK '{print $2}')
WARNTIME="120"
CRITTIME="20"

[[ "$MYUPTIME" -le "$CRITTIME" ]] && \
printf "\342\235\214 CRITICAL: mysql server uptime less than or equal to $CRITTIME seconds\n" \
&& exit 2

[[ "$MYUPTIME" -le "$WARNTIME" ]] && \
printf "⚠️  WARNING: mysql server uptime less than or equal to $WARNTIME seconds\n" \
&& exit 1

printf "\360\237\222\232 OK: mysql server uptime is $MYUPTIME seconds\n" \
&& exit 0