]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/monitoring/plugins/check_mysql_replication
Add status engine website
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / check_mysql_replication
1 #!/bin/bash
2
3 STATE_OK=0
4 STATE_WARNING=1
5 STATE_CRITICAL=2
6 STATE_UNKNOWN=3
7
8 socket=$1
9 config_file=$2
10 info=$(mysql --defaults-file=${config_file} -S $socket -e "show slave status" --vertical)
11 exit_code=$?
12
13 lag=$(echo "$info" | grep Seconds_Behind_Master | cut -d':' -f2 | sed -e "s/\s//g")
14
15 if [[ $exit_code -ne 0 ]]; then
16 echo "UNKNOWN - Impossible to run mysql command"
17 exit $STATE_UNKNOWN
18 elif [[ -z "$lag" ]]; then
19 echo "UNKNOWN - No replication found for mysql"
20 exit $STATE_UNKNOWN
21 else
22 output="Replication lag for mysql is ${lag}s"
23 LC_ALL=C lag=$(printf "%.*f" 0 $lag)
24
25 if [[ $lag -lt 5 ]]; then
26 echo "OK - $output | time=${lag}s;5;10;;"
27 exit $STATE_OK
28 elif [[ $lag -lt 10 ]]; then
29 echo "WARNING - $output | time=${lag}s;5;10;;"
30 exit $STATE_WARNING
31 else
32 echo "CRITICAL - $output | time=${lag}s;5;10;;"
33 exit $STATE_CRITICAL
34 fi
35 fi