X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix.git;a=blobdiff_plain;f=modules%2Fprivate%2Fmonitoring%2Fplugins%2Fcheck_mysql_replication;fp=modules%2Fprivate%2Fmonitoring%2Fplugins%2Fcheck_mysql_replication;h=89239281b3da089fb6128a0fd4615de8baaa5c62;hp=0000000000000000000000000000000000000000;hb=6015a3b52c3b155ac444aeb39950c38a5e653101;hpb=dded66995529a0419cc56778f4ebb4247c2ab765 diff --git a/modules/private/monitoring/plugins/check_mysql_replication b/modules/private/monitoring/plugins/check_mysql_replication new file mode 100755 index 0000000..8923928 --- /dev/null +++ b/modules/private/monitoring/plugins/check_mysql_replication @@ -0,0 +1,35 @@ +#!/bin/bash + +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 + +socket=$1 +config_file=$2 +info=$(mysql --defaults-file=${config_file} -S $socket -e "show slave status" --vertical) +exit_code=$? + +lag=$(echo "$info" | grep Seconds_Behind_Master | cut -d':' -f2 | sed -e "s/\s//g") + +if [[ $exit_code -ne 0 ]]; then + echo "UNKNOWN - Impossible to run mysql command" + exit $STATE_UNKNOWN +elif [[ -z "$lag" ]]; then + echo "UNKNOWN - No replication found for mysql" + exit $STATE_UNKNOWN +else + output="Replication lag for mysql is ${lag}s" + LC_ALL=C lag=$(printf "%.*f" 0 $lag) + + if [[ $lag -lt 5 ]]; then + echo "OK - $output" + exit $STATE_OK + elif [[ $lag -lt 10 ]]; then + echo "WARNING - $output" + exit $STATE_WARNING + else + echo "CRITICAL - $output" + exit $STATE_CRITICAL + fi +fi