Open samva259 opened 5 years ago
sample code to add support for --login-path parameter as an alternative to --user and --password parameters, and to add some logic to check for conflicting parameter(s): ... #########################################################################
######################################################################### help="\ncheck_mysql_slavestatus.sh (c) 2008-2019 GNU GPLv2 licence Usage: $0 (-o file|(-H dbhost [-P port]|-S socket) (-u username -p password|-l loginpath)) [-s connection] [-w integer] [-c integer] [-m]\n Options:\n-o Path to option file containing connection settings (e.g. /home/nagios/.my.cnf). Note: If this option is used, -H, -u, -p, -l parameters will become optional\n-H Hostname or IP of slave server\n-P MySQL Port of slave server (optional, defaults to 3306)\n-u Username of DB-user\n-p Password of DB-user\n-l Login Path (used instead of Username and Password)\n-S database socket\n-s Connection name (optional, with multi-source replication)\n-w Replication delay in seconds for Warning status (optional)\n-c Replication delay in seconds for Critical status (optional)\n-m Threshold in seconds since when replication did not move (compares the slaves log position)\n Attention: The DB-user you type in must have CLIENT REPLICATION rights on the DB-server. Example:\n\tGRANT REPLICATION CLIENT on . TO 'nagios'@'%' IDENTIFIED BY 'secret';" ... while getopts "H:P:u:p:S:s:w:c:o:m:l:h" Input; ... l) loginpath_p="y";loginpath="--login-path=${OPTARG}";; ...
if [[ -z "${optfile}" && -z "${host}" && -z "${socket}" && -z "${loginpath}" ]]; then echo -e "Missing required parameter(s)"; exit ${STATE_UNKNOWN} elif [[ -z "${optfile}" && ((-z "${host}" && -z "${socket}") || (-z "${loginpath}" && (-z "${user}" || -z "${password}"))) ]]; then echo -e "Missing required parameter(s)"; exit ${STATE_UNKNOWN} elif [[ -z "${optfile}" && (-n "${host}" && -n "${socket}") ]]; then echo -e "Conflicting parameter(s)"; exit ${STATE_UNKNOWN} elif [[ -z "${optfile}" && (-n "${loginpath}" && -n "${user}") ]]; then echo -e "Conflicting parameter(s)"; exit ${STATE_UNKNOWN} elif [[ -z "${optfile}" && (-n "${loginpath}" && -n "${password}") ]]; then echo -e "Conflicting parameter(s)"; exit ${STATE_UNKNOWN} fi ...
if [[ -n $loginpath ]]; then if [[ -n $socket ]]; then ConnectionResult=$(mysql ${loginpath} ${optfile} ${socket} -e "show slave ${connection} status\G" 2>&1) else ConnectionResult=$(mysql ${loginpath} ${optfile} ${host} ${port} -e "show slave ${connection} status\G" 2>&1) fi else if [[ -n $socket ]]; then ConnectionResult=$(mysql ${optfile} ${socket} ${user} -e "show slave ${connection} status\G" 2>&1) else ConnectionResult=$(mysql ${optfile} ${host} ${port} ${user} -e "show slave ${connection} status\G" 2>&1) fi fi ...
Thank you very much for making this available. I have a small improvement request. Could support for the --login-path parameter for the mysql client be added to this script ?
For example if a new "-l" switch was added the affected lines of code might be something like these (plus relevant documentation changes):
...
while getopts "H:P:u:p:S:s:w:c:o:m:h:l" Input;
...l) loginpath="--login-path=${OPTARG}";;
... then for the case we receive the -l switch the invoke of the mysql client would beConnectionResult=$(mysql ${loginpath} ${optfile} ... -e "show slave ${connection} status\G" 2>&1)
...Thank you again for considering this