Giter Club home page Giter Club logo

Comments (1)

samva259 avatar samva259 commented on August 27, 2024

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):
...
#########################################################################

Usage: ./check_mysql_slavestatus.sh (-o file|(-H dbhost [-P port]|-S socket) (-u dbuser -p dbpass|-l loginpath)) [-s connection] [-w integer] [-c integer] [-m integer]

#########################################################################
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}";;
...

Check whether all required arguments were passed in (either option file or full connection settings)

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
...

Connect to the DB server and store output in vars

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
...

from check_mysql_slavestatus.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.