Make the USER and PASSWORD parameters optional

This commit is contained in:
Ales Nosek
2016-01-31 10:28:12 -08:00
committed by Guillaume Coré
parent 10802af0c4
commit 4ea9e83e67
2 changed files with 25 additions and 28 deletions
+5 -4
View File
@@ -2,11 +2,12 @@ nagios-plugin-check_galera_cluster
======================================= =======================================
A nagios plugin to check status of a galera cluster A nagios plugin to check status of a galera cluster
Version 1.0, Guillaume Coré <g@fridim.org>
Version 1.1, Guillaume Coré <fridim@onfi.re>, Ales Nosek <ales.nosek@gmail.com>
check_galera_cluster is a Nagios plugin to monitor Galera cluster status. check_galera_cluster is a Nagios plugin to monitor Galera cluster status.
check_galera_cluster -u USER -p PASSWORD [-H HOST] [-P PORT] [-w SIZE] [-c SIZE] [-f FLOAT] [-0] check_galera_cluster [-u USER] [-p PASSWORD] [-H HOST] [-P PORT] [-w SIZE] [-c SIZE] [-f FLOAT] [-0]
Options: Options:
u) u)
@@ -14,9 +15,9 @@ Version 1.0, Guillaume Coré <g@fridim.org>
p) p)
MySQL password. MySQL password.
H) H)
MySQL host. Default is localhost. MySQL host.
P) P)
MySQL port. Default is 3306. MySQL port.
w) w)
Sets minimum number of nodes in the cluster when WARNING is raised. (default is same as critical). Sets minimum number of nodes in the cluster when WARNING is raised. (default is same as critical).
c) c)
Executable → Regular
+20 -24
View File
@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
PROGNAME=`basename $0` PROGNAME=`basename $0`
VERSION="Version 1.0," VERSION="Version 1.1"
AUTHOR="Guillaume Coré <g@fridim.org>" AUTHOR="Guillaume Coré <fridim@onfi.re>, Ales Nosek <ales.nosek@gmail.com>"
ST_OK=0 ST_OK=0
ST_WR=1 ST_WR=1
@@ -17,7 +17,7 @@ print_help() {
echo "" echo ""
echo "$PROGNAME is a Nagios plugin to monitor Galera cluster status." echo "$PROGNAME is a Nagios plugin to monitor Galera cluster status."
echo "" echo ""
echo "$PROGNAME -u USER -p PASSWORD [-H HOST] [-P PORT] [-w SIZE] [-c SIZE] [-f FLOAT] [-0]" echo "$PROGNAME [-u USER] [-p PASSWORD] [-H HOST] [-P PORT] [-w SIZE] [-c SIZE] [-f FLOAT] [-0]"
echo "" echo ""
echo "Options:" echo "Options:"
echo " u)" echo " u)"
@@ -25,9 +25,9 @@ print_help() {
echo " p)" echo " p)"
echo " MySQL password." echo " MySQL password."
echo " H)" echo " H)"
echo " MySQL host. Default is localhost." echo " MySQL host."
echo " P)" echo " P)"
echo " MySQL port. Default is 3306." echo " MySQL port."
echo " w)" echo " w)"
echo " Sets minimum number of nodes in the cluster when WARNING is raised. (default is same as critical)." echo " Sets minimum number of nodes in the cluster when WARNING is raised. (default is same as critical)."
echo " c)" echo " c)"
@@ -41,8 +41,6 @@ print_help() {
# default values # default values
crit=2 crit=2
port='3306'
mysqlhost='localhost'
fcp=0.1 fcp=0.1
while getopts “hvu:p:H:P:w:c:f:0” OPTION; do while getopts “hvu:p:H:P:w:c:f:0” OPTION; do
@@ -91,25 +89,23 @@ if [ -z "$warn" ]; then
warn=$crit warn=$crit
fi fi
# MANDATORY args create_param() {
if [ -z "$mysqluser" ]; then if [ -n "$2" ]; then
echo "argument -u missing" echo $1$2
print_help fi
exit $ST_UK }
fi
if [ -z "$password" ]; then param_mysqlhost=$(create_param -h "$mysqlhost")
echo "argument -p missing" param_port=$(create_param -P "$port")
print_help param_mysqluser=$(create_param -u "$mysqluser")
exit $ST_UK param_password=$(create_param -p "$password")
fi
r1=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_cluster_size'"|cut -f 2) # 3 (GALERA_CLUSTER_SIZE) r1=$(mysql $param_mysqlhost $param_port $param_mysqluser $param_password -B -N -e "show status like 'wsrep_cluster_size'"|cut -f 2) # 3 (GALERA_CLUSTER_SIZE)
r2=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_cluster_status'"|cut -f 2) # Primary r2=$(mysql $param_mysqlhost $param_port $param_mysqluser $param_password -B -N -e "show status like 'wsrep_cluster_status'"|cut -f 2) # Primary
r3=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_flow_control_paused'"|cut -f 2) # < 0.1 r3=$(mysql $param_mysqlhost $param_port $param_mysqluser $param_password -B -N -e "show status like 'wsrep_flow_control_paused'"|cut -f 2) # < 0.1
r4=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_ready'"|cut -f 2) # ON r4=$(mysql $param_mysqlhost $param_port $param_mysqluser $param_password -B -N -e "show status like 'wsrep_ready'"|cut -f 2) # ON
r5=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_connected'"|cut -f 2) # ON r5=$(mysql $param_mysqlhost $param_port $param_mysqluser $param_password -B -N -e "show status like 'wsrep_connected'"|cut -f 2) # ON
r6=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_local_state_comment'"|cut -f 2) # Synced r6=$(mysql $param_mysqlhost $param_port $param_mysqluser $param_password -B -N -e "show status like 'wsrep_local_state_comment'"|cut -f 2) # Synced
if [ -z "$r3" ]; then if [ -z "$r3" ]; then
echo "UNKNOWN: wsrep_flow_control_paused is empty" echo "UNKNOWN: wsrep_flow_control_paused is empty"