Skip to content
Snippets Groups Projects
Commit 77d0e434 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

mysqlserver - some shell fixes

parent 6ed9bef2
No related branches found
No related tags found
1 merge request!856010 check pqsql
#!/bin/bash #!/bin/bash
# ====================================================================== # ======================================================================
# #
# !!! WORK IN PROGRESS !!! DO NOT USE YET !!!
#
# Check MYSQL / MARIADB SERVER # Check MYSQL / MARIADB SERVER
# #
# requirements: # requirements:
...@@ -20,19 +18,17 @@ ...@@ -20,19 +18,17 @@
# 2020-08-xx v0.0 <axel.hahn@iml.unibe.ch> # 2020-08-xx v0.0 <axel.hahn@iml.unibe.ch>
# 2021-06-08 v0.1 <axel.hahn@iml.unibe.ch> update HOME .. better implement a param and ENV var # 2021-06-08 v0.1 <axel.hahn@iml.unibe.ch> update HOME .. better implement a param and ENV var
# 2021-06-24 v0.2 <axel.hahn@iml.unibe.ch> check if query cache is enabled as a shared function # 2021-06-24 v0.2 <axel.hahn@iml.unibe.ch> check if query cache is enabled as a shared function
# 2023-06-06 v0.3 <axel.hahn@unibe.ch> some shell fixes
# ====================================================================== # ======================================================================
. `dirname $0`/inc_pluginfunctions . $( dirname $0 )/inc_pluginfunctions
_version="0.2"
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=0.3
# --- set HOME # --- set HOME
# HOME=/etc/icinga2-passive-client
HOME=/etc/icingaclient HOME=/etc/icingaclient
# cd $( dirname $0)
# cd ..
# HOME=$( pwd ); export HOME
# cd - >/dev/null
# --- other vars... # --- other vars...
cfgfile=$HOME/.my.cnf cfgfile=$HOME/.my.cnf
...@@ -89,7 +85,7 @@ function _install(){ ...@@ -89,7 +85,7 @@ function _install(){
echo "- creating config file $cfgfile ... " echo "- creating config file $cfgfile ... "
cat >$cfgfile <<EOF cat >$cfgfile <<EOF
# #
# generated on `date` # generated on $(date)
# #
[client] [client]
user=$myuser user=$myuser
...@@ -106,17 +102,18 @@ EOF ...@@ -106,17 +102,18 @@ EOF
# show usage # show usage
function _usage(){ function _usage(){
local _self=$( basename $0 )
cat <<EOH cat <<EOH
______________________________________________________________________ ______________________________________________________________________
CHECK MYSQL SERVER :: v${_version} ${self_APPNAME} :: v${self_APPVERSION}
(c) Institute for Medical Education - University of Bern (c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3 Licence: GNU GPL 3
______________________________________________________________________ ______________________________________________________________________
USAGE: USAGE:
`basename $0` [OPTIONS] -m METHOD $_self [OPTIONS] -m METHOD
OPTIONS: OPTIONS:
-h this help -h this help
...@@ -133,8 +130,8 @@ PARAMETERS: ...@@ -133,8 +130,8 @@ PARAMETERS:
qcache-hits query cache efficiency: cached vs non cached and inserted qcache-hits query cache efficiency: cached vs non cached and inserted
EXAMPLES: EXAMPLES:
`basename $0` -i $_self -i
`basename $0` -m commands $_self -m commands
EOH EOH
} }
...@@ -146,8 +143,8 @@ function _mysqlreadvars(){ ...@@ -146,8 +143,8 @@ function _mysqlreadvars(){
function _mysqlgetvar() { function _mysqlgetvar() {
local sVarname=$1 local sVarname=$1
lastvalue=`grep "^$sVarname[^_a-z]" ${datafile} | awk '{ print $2 }'` lastvalue=$(grep "^${sVarname}[^_a-z]" ${datafile} | awk '{ print $2 }')
echo $lastvalue echo "$lastvalue"
} }
# get a value from mysql status output # get a value from mysql status output
# param string variable name # param string variable name
...@@ -160,20 +157,20 @@ function _mysqlrendervar() { ...@@ -160,20 +157,20 @@ function _mysqlrendervar() {
local sFloat=$4 local sFloat=$4
# local iValue=`grep "^$sVarname[^_a-z]" ${datafile} | awk '{ print $2 }'` # local iValue=`grep "^$sVarname[^_a-z]" ${datafile} | awk '{ print $2 }'`
local iValue=`_mysqlgetvar "$sVarname"` local iValue=$(_mysqlgetvar "$sVarname")
if [ "$iValue" = "" ]; then if [ "$iValue" = "" ]; then
ph.abort "no value for ${sVarname}" ph.abort "no value for ${sVarname}"
fi fi
# get label for perfdata # get label for perfdata
local sLabel=`echo ${sVarname} | sed "s#^${sRemove}##g"` local sLabel=$(echo ${sVarname} | sed "s#^${sRemove}##g")
if [ ! -z $sDeltaUnit ]; then if [ ! -z $sDeltaUnit ]; then
local iSpeed=` ph.perfdeltaspeed "mysql-${sVarname}" ${iValue} $sDeltaUnit $sFloat` local iSpeed=$( ph.perfdeltaspeed "mysql-${sVarname}" ${iValue} $sDeltaUnit $sFloat)
out=$out`printf "%25s: %10s %s \n" "${sLabel}" "${iValue}" "... delta = ${iSpeed} per $sDeltaUnit${NL}"` out=$out$(printf "%25s: %10s %s \n" "${sLabel}" "${iValue}" "... delta = ${iSpeed} per $sDeltaUnit${NL}")
ph.perfadd "${sLabel}" "${iSpeed}" ph.perfadd "${sLabel}" "${iSpeed}"
lastvalue=$iSpeed lastvalue=$iSpeed
else else
out=${out}`printf "%25s: %10s \n" "${sLabel}" "${iValue}${NL}"` out=${out}$(printf "%25s: %10s \n" "${sLabel}" "${iValue}${NL}")
ph.perfadd "${sLabel}" "${iValue}" ph.perfadd "${sLabel}" "${iValue}"
lastvalue=$iValue lastvalue=$iValue
fi fi
...@@ -182,8 +179,8 @@ function _mysqlrendervar() { ...@@ -182,8 +179,8 @@ function _mysqlrendervar() {
function _mysqlrenderdelta() { function _mysqlrenderdelta() {
local deltaUnit=$3 local deltaUnit=$3
test -z $deltaUnit && deltaUnit="sec" test -z "$deltaUnit" && deltaUnit="sec"
_mysqlrendervar "$1" "$2" $deltaUnit $4 _mysqlrendervar "$1" "$2" "$deltaUnit" "$4"
} }
# helper function for caching checks # helper function for caching checks
...@@ -204,9 +201,9 @@ function _verify_cache(){ ...@@ -204,9 +201,9 @@ function _verify_cache(){
# MAIN # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
bOptInstall=` ph.hasParamoption "i" "$@"` bOptInstall=$( ph.hasParamoption "i" "$@")
bOptUninstall=` ph.hasParamoption "u" "$@"` bOptUninstall=$( ph.hasParamoption "u" "$@")
bOptHelp=` ph.hasParamoption "h" "$@"` bOptHelp=$( ph.hasParamoption "h" "$@")
if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then
_usage _usage
...@@ -247,7 +244,7 @@ fi ...@@ -247,7 +244,7 @@ fi
# --- check installation # --- check installation
grep $myuser $cfgfile >/dev/null 2>/dev/null grep $myuser $cfgfile >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
ph.abort "MYSQL access not possible yet. You need to install the monitoring user first: as root execute `basename $0` -i" ph.abort "MYSQL access not possible yet. You need to install the monitoring user first: as root execute $(basename $0) -i"
fi fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -260,10 +257,10 @@ if [ $? -ne 0 ]; then ...@@ -260,10 +257,10 @@ if [ $? -ne 0 ]; then
fi fi
# --- set optional limits # --- set optional limits
typeset -i iWarnLimit=` ph.getValueWithParam 0 w "$@"` typeset -i iWarnLimit=$( ph.getValueWithParam 0 w "$@")
typeset -i iCriticalLimit=` ph.getValueWithParam 0 c "$@"` typeset -i iCriticalLimit=$( ph.getValueWithParam 0 c "$@")
sMode=`ph.getValueWithParam '' m "$@"` sMode=$(ph.getValueWithParam '' m "$@")
case "${sMode}" in case "${sMode}" in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment