aboutsummaryrefslogtreecommitdiffstats
path: root/templates/database/clustercheck.erb
diff options
context:
space:
mode:
Diffstat (limited to 'templates/database/clustercheck.erb')
-rw-r--r--templates/database/clustercheck.erb56
1 files changed, 56 insertions, 0 deletions
diff --git a/templates/database/clustercheck.erb b/templates/database/clustercheck.erb
new file mode 100644
index 0000000..cc3231b
--- /dev/null
+++ b/templates/database/clustercheck.erb
@@ -0,0 +1,56 @@
+#!/bin/bash
+# Managed by puppet
+#
+# Script to make a proxy (ie HAProxy) capable of monitoring Galera cluster
+#
+# Author: Olaf van Zandwijk <olaf.vanzandwijk@nedap.com>
+# Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
+#
+# Documentation and download: https://github.com/olafz/percona-clustercheck
+#
+# Based on the original script from Unai Rodriguez
+#
+MYSQL_USERNAME='<%= @galera_clustercheck_dbuser %>'
+MYSQL_PASSWORD='<%= @galera_clustercheck_dbpassword %>'
+
+TIMEOUT=10
+ERR_FILE="/dev/null"
+AVAILABLE_WHEN_DONOR=0
+
+MYSQL_CMDLINE="mysql -nNE --connect-timeout=$TIMEOUT --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD} "
+
+mysql_get_status(){
+ ( $MYSQL_CMDLINE -e "SHOW STATUS LIKE '$1';" | tail -1 ) 2>>${ERR_FILE}
+}
+mysql_get_var(){
+ ( $MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE '$1';" | tail -1 ) 2>>${ERR_FILE}
+}
+
+http_response(){
+ status=$1
+ shift
+ msg="$@"
+ if [ "$status" == 200 ]; then
+ /bin/echo -en "HTTP/1.1 200 OK\r\n"
+ else
+ /bin/echo -en "HTTP/1.1 503 Service Unavailable\r\n"
+ fi
+ /bin/echo -en "Content-Type: text/plain\r\n"
+ /bin/echo -en "\r\n"
+ /bin/echo -en "$msg\r\n"
+ /bin/echo -en "\r\n"
+}
+
+
+WSREP_LOCAL_STATE=$(mysql_get_status wsrep_local_state)
+WSREP_READY=$(mysql_get_status wsrep_ready)
+WSREP_CONNECTED=$(mysql_get_status wsrep_connected)
+READY_ONLY=$(mysql_get_var read_only)
+
+case ${AVAILABLE_WHEN_DONOR}-${WSREP_LOCAL_STATE}-${WSREP_READY}-${WSREP_CONNECTED}-${READY_ONLY} in
+ 1-2-ON-ON-OFF|0-4-ON-ON-OFF) http_response 200 "Mariadb Cluster Node is synced, ready and connected." ;;
+ *-*-OFF-*-*) http_response 503 "Mariadb Cluster Node is not ready." ;;
+ *-*-*-OFF-*) http_response 503 "Mariadb Cluster Node is not connected" ;;
+ *-*-*-*-ON) http_response 503 "Mariadb Cluster Node is readonly" ;;
+ *) http_response 503 "Mariadb Cluster Node is not synced" ;;
+esac