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