diff --git a/README.md b/README.md index fcaf359efbc5a293a2c7ce0dd44e6814f92d484c..3d319c1ad869a155aac05431734a29b0b7f126cf 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 0000000000000000000000000000000000000000..2c9195991456d41c18857def5fe260f2878c9436 --- /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