]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/monitoring/plugins/check_mysql_replication
Add status engine website
[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
13lag=$(echo "$info" | grep Seconds_Behind_Master | cut -d':' -f2 | sed -e "s/\s//g")
14
15if [[ $exit_code -ne 0 ]]; then
16 echo "UNKNOWN - Impossible to run mysql command"
17 exit $STATE_UNKNOWN
18elif [[ -z "$lag" ]]; then
19 echo "UNKNOWN - No replication found for mysql"
20 exit $STATE_UNKNOWN
21else
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
a97118c4 26 echo "OK - $output | time=${lag}s;5;10;;"
6015a3b5
IB
27 exit $STATE_OK
28 elif [[ $lag -lt 10 ]]; then
a97118c4 29 echo "WARNING - $output | time=${lag}s;5;10;;"
6015a3b5
IB
30 exit $STATE_WARNING
31 else
a97118c4 32 echo "CRITICAL - $output | time=${lag}s;5;10;;"
6015a3b5
IB
33 exit $STATE_CRITICAL
34 fi
35fi