]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/monitoring/plugins/check_mysql_replication
Adjust sql parameters
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / check_mysql_replication
index 4027f63f0ec57f45fd5df19caacf7b57b9496e74..1ee5de1470c71da3c2eaa3fc4054a5b776f05e07 100755 (executable)
@@ -10,7 +10,10 @@ 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")
+lag=$(echo "$info" | grep "\bSeconds_Behind_Master\b" | cut -d':' -f2 | sed -e "s/\s//g")
+
+IO_running=$(echo "$info" | grep "\bSlave_IO_Running\b" | cut -d':' -f2 | sed -e "s/\s//g")
+SQL_running=$(echo "$info" | grep "\bSlave_SQL_Running\b" | cut -d':' -f2 | sed -e "s/\s//g")
 
 if [[ $exit_code -ne 0 ]]; then
   echo "UNKNOWN - Impossible to run mysql command"
@@ -18,6 +21,9 @@ if [[ $exit_code -ne 0 ]]; then
 elif [[ -z "$lag" ]]; then
   echo "UNKNOWN - No replication found for mysql"
   exit $STATE_UNKNOWN
+elif [[ "$IO_running" != "Yes" || "$SQL_running" != "Yes" ]]; then
+  echo "UNKNOWN - Replication is not running"
+  exit $STATE_UNKNOWN
 else
   output="Replication lag for mysql is ${lag}s"
   LC_ALL=C lag=$(printf "%.*f" 0 $lag)