From 5396d44922001f96dbcd16ba39995d01f77e4e56 Mon Sep 17 00:00:00 2001 From: BaranekD <0Baranek.dominik0@gmail.com> Date: Wed, 20 Feb 2019 14:43:21 +0100 Subject: [PATCH] mariadb_replication_check added --- README.md | 16 +++++++++++++++- mariadb_replication_check.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 mariadb_replication_check.sh diff --git a/README.md b/README.md index fcaf359..3d319c1 100644 --- a/README.md +++ b/README.md @@ -68,4 +68,18 @@ This script checks the login via active ProxyIdP machine * Example: <pre> ./proxy_idp_auth_test_active.sh "https://aai-playground.ics.muni.cz/simplesaml/nagios_check.php?proxy_idp=cesnet" "https://idp2.ics.muni.cz/idp/Authn/UserPassword" "login" "passwd" - </pre> \ No newline at end of file + </pre> + +### mariadb_replication_check.sh +This script checks the database replication + +* How to run this script: + * Params: + * 1 - Login used for connection to the database + * 2 - Password used for connection to the database (the password has to be in quotes) + * 3 - List of addresses separated by space (the list has to be in quotes) + * Example: + <pre> + ./mariadb_replication_check.sh "USER" "PASSWORD" "Address1 Address2 Address3" + </pre> + \ No newline at end of file diff --git a/mariadb_replication_check.sh b/mariadb_replication_check.sh new file mode 100755 index 0000000..2c91959 --- /dev/null +++ b/mariadb_replication_check.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +USER=$1 +PASSWD=$2 +# List of addresses separated by space +machines=$3 +count=0 + +for i in ${machines}; do + listOfMachines[${count}]=${i} + result[${count}]=$(mysql -u ${USER} -p${PASSWD} -h ${i} --execute="SHOW STATUS LIKE 'wsrep_last_committed';" 2> /dev/null | tr -dc '0-9') + + if [[ -z ${result[${count}]} ]]; then + echo "CRITICAL - mariadb_replication_check - ${i}: An error appeared while connecting mariadb." + exit 2 + fi + count=$(expr ${count} + 1) +done + +for i in $(seq 0 $(expr ${count} - 2)); do + if [[ ${result[i]} -ne ${result[i+1]} ]]; then + echo "CRITICAL - mariadb_replication_check - The result from ${machines[1]} (${result[i]}) is not equal to the result from ${machines[i+1]} (${result[i+1]})" + exit 2 + fi +done + +echo "OK - mariadb_replication_check - OK" +exit 0 -- GitLab