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

Merge branch '5665-packages2install-fix-yum' into 'master'

5665 packages2install fix yum

See merge request !37
parents 0413bc08 c1450bc3
No related branches found
No related tags found
1 merge request!375665 packages2install fix yum
...@@ -40,7 +40,7 @@ function yum.getPackageList(){ ...@@ -40,7 +40,7 @@ function yum.getPackageList(){
# get custom status # get custom status
function yum.getStatusLine(){ function yum.getStatusLine(){
typeset -i local _osversion typeset -i local _osversion
_osversion=$(awk '{ print $4 }' /etc/redhat-release | cut -f 1 -d '.') _osversion=$( ph.getOSMajor )
if [ $_osversion -ge 8 ]; then if [ $_osversion -ge 8 ]; then
if ! sudo /usr/bin/yum --security check-update 2>&1 | grep "available" ; then if ! sudo /usr/bin/yum --security check-update 2>&1 | grep "available" ; then
echo "rc = $? [Not detected on v$_osversion]" echo "rc = $? [Not detected on v$_osversion]"
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
# 2019-10-29 added setExitcode # 2019-10-29 added setExitcode
# 2020-03-05 v1.2 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions # 2020-03-05 v1.2 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2020-09-01 v1.3 <axel.hahn@iml.unibe.ch> added ph.hasParamoption # 2020-09-01 v1.3 <axel.hahn@iml.unibe.ch> added ph.hasParamoption
# 2022-08-31 v1.4 <axel.hahn@iml.unibe.ch> shellfix corrections
# ====================================================================== # ======================================================================
...@@ -49,7 +50,7 @@ ph_cmd__params="$@" ...@@ -49,7 +50,7 @@ ph_cmd__params="$@"
# abort a check and exit with status "unknown" # abort a check and exit with status "unknown"
function ph.abort(){ function ph.abort(){
ph.setStatus "unknown" ph.setStatus "unknown"
echo $* echo "$*"
ph.exit ph.exit
} }
...@@ -77,20 +78,20 @@ function ph.exit(){ ...@@ -77,20 +78,20 @@ function ph.exit(){
# detect LINUX DISTRO as lowercase # detect LINUX DISTRO as lowercase
# returns one of centos|debian|ubuntu|... # returns one of centos|debian|ubuntu|...
function ph.getOS(){ function ph.getOS(){
distro= local distro=
if [ -z $distro ]; then if [ -z $distro ]; then
# centos7, debian, manjaro, ubuntu # centos7, debian, manjaro, ubuntu
distro=`cat /etc/*-release | grep "^ID=" | cut -f 2 -d "="` distro=$( grep "^ID=" /etc/*-release | cut -f 2 -d "=" )
fi fi
if [ -z $distro ]; then if [ -z $distro ]; then
# debian6,7, ubuntu 10,12 .. maybe unneeded. # debian6,7, ubuntu 10,12 .. maybe unneeded.
distro=`cat /etc/issue | head -1 | grep "^[a-zA-Z]" | cut -f 1 -d " "` distro=$( head -1 /etc/issue | grep "^[a-zA-Z]" | cut -f 1 -d " " )
fi fi
# sanitize: lowercase, remove " # sanitize: lowercase, remove "
distro=`echo $distro | tr -d '"' | tr [:upper:] [:lower:]` distro=$( echo $distro | tr -d '"' | tr [:upper:] [:lower:] )
if [ -z $distro ]; then if [ -z $distro ]; then
ph.abort "UNKNOWN: distro was not detected." ph.abort "UNKNOWN: distro was not detected."
...@@ -104,12 +105,12 @@ function ph.getOS(){ ...@@ -104,12 +105,12 @@ function ph.getOS(){
# returns an integer, i.e. 7 on CentOS7 # returns an integer, i.e. 7 on CentOS7
function ph.getOSMajor(){ function ph.getOSMajor(){
local _version= local _version=
_version=`cat /etc/*-release | egrep "^(VERSION_ID|DISTRIB_RELEASE)=" | head -1 | cut -f 2 -d "=" | sed 's#"##g' | cut -f 1 -d "."` _version=$( grep -E "^(VERSION_ID|DISTRIB_RELEASE)=" /etc/*-release | head -1 | cut -f 2 -d "=" | sed 's#"##g' | cut -f 1 -d "." )
if [ -z "$_version" ]; then if [ -z "$_version" ]; then
_version="?" _version="?"
exit 1 exit 1
fi fi
echo $_version echo "$_version"
} }
# helper to use the default _value or override it with a found param # helper to use the default _value or override it with a found param
...@@ -136,7 +137,7 @@ function ph.getValueWithParam(){ ...@@ -136,7 +137,7 @@ function ph.getValueWithParam(){
;; ;;
esac esac
done done
echo $_value echo "$_value"
} }
# check if a letter was used as command line option and return as 0 (=no) or 1 (=yes) # check if a letter was used as command line option and return as 0 (=no) or 1 (=yes)
...@@ -159,7 +160,7 @@ function ph.hasParamoption(){ ...@@ -159,7 +160,7 @@ function ph.hasParamoption(){
while getopts "abcdefghijklmnopqrstuvwxyz" _opt; do while getopts "abcdefghijklmnopqrstuvwxyz" _opt; do
# echo "DEBUG: testing $_sParam in ${_opt} ..." # echo "DEBUG: testing $_sParam in ${_opt} ..."
case "${_opt}" in case "${_opt}" in
$_sParam) "$_sParam")
echo "1" echo "1"
return 1 return 1
;; ;;
...@@ -255,7 +256,8 @@ function ph.status(){ ...@@ -255,7 +256,8 @@ function ph.status(){
# example: 12M returns 2^30 from ending "M" # example: 12M returns 2^30 from ending "M"
# param value with ending scale [none]=1 K=Kilo M=Mega G=Giga # param value with ending scale [none]=1 K=Kilo M=Mega G=Giga
function ph._getExp(){ function ph._getExp(){
local _unit=`echo $1 | sed "s#[0-9]##g"` local _unit
_unit=$( echo $1 | sed "s#[0-9]##g" )
test -z "$_unit" && echo 1 test -z "$_unit" && echo 1
...@@ -311,14 +313,17 @@ function ph.getFileAge(){ ...@@ -311,14 +313,17 @@ function ph.getFileAge(){
echo $(($(date +%s) - $(date +%s -r "$1"))) echo $(($(date +%s) - $(date +%s -r "$1")))
} }
# get file for storage of last value
# global string dir_data custom path; default is /tmp/icinga_counter/
function ph._getStorefile(){ function ph._getStorefile(){
local varName=$1 local varName=$1
local mydir="/tmp/icinga_counter" local mydir="/tmp/icinga_counter"
test -z $dir_data || mydir="${dir_data}/_counter" test -n "$dir_data" && mydir="${dir_data}/_counter"
local _basename=`basename $0` local _basename
_basename=$(basename $0)
test -d ${mydir} || mkdir -p ${mydir} test -d "${mydir}" || mkdir -p "${mydir}"
echo "${mydir}/${_basename}${varName}.lastvalue" echo "${mydir}/${_basename}${varName}.lastvalue"
} }
...@@ -327,7 +332,7 @@ function ph._getStorefile(){ ...@@ -327,7 +332,7 @@ function ph._getStorefile(){
function ph._savecounter() { function ph._savecounter() {
local varName=$1 local varName=$1
local value=$2 local value=$2
local sStoreFile=`ph._getStorefile "${varName}"` local sStoreFile=$(ph._getStorefile "${varName}")
#echo "DEBUG: `date +%s`:${value} \> ${sStoreFile}" #echo "DEBUG: `date +%s`:${value} \> ${sStoreFile}"
# echo "`date +%s`:${value}" > "${sStoreFile}" # echo "`date +%s`:${value}" > "${sStoreFile}"
echo ${value} > "${sStoreFile}" echo ${value} > "${sStoreFile}"
...@@ -335,7 +340,7 @@ function ph._savecounter() { ...@@ -335,7 +340,7 @@ function ph._savecounter() {
function ph._getageoflastvalue() { function ph._getageoflastvalue() {
local varName=$1 local varName=$1
local sStoreFile=`ph._getStorefile "${varName}"` local sStoreFile=$(ph._getStorefile "${varName}")
ph.getFileAge "${sStoreFile}" ph.getFileAge "${sStoreFile}"
# local ilast=`cat "${sStoreFile}" 2>/dev/null | cut -f 1 -d ":" ` # local ilast=`cat "${sStoreFile}" 2>/dev/null | cut -f 1 -d ":" `
# local inow=`date +%s` # local inow=`date +%s`
...@@ -343,7 +348,7 @@ function ph._getageoflastvalue() { ...@@ -343,7 +348,7 @@ function ph._getageoflastvalue() {
} }
function ph._readlastvalue(){ function ph._readlastvalue(){
local varName=$1 local varName=$1
local sStoreFile=`ph._getStorefile "${varName}"` local sStoreFile=$(ph._getStorefile "${varName}")
# cat "${sStoreFile}" 2>/dev/null | cut -f 2 -d ":" # cat "${sStoreFile}" 2>/dev/null | cut -f 2 -d ":"
cat "${sStoreFile}" 2>/dev/null cat "${sStoreFile}" 2>/dev/null
} }
...@@ -351,14 +356,15 @@ function ph._readlastvalue(){ ...@@ -351,14 +356,15 @@ function ph._readlastvalue(){
# init usage for performance data # init usage for performance data
# it creates a filename based on the started check script # it creates a filename based on the started check script
function ph._perfinit(){ function ph._perfinit(){
local _basename=`basename $0` local _basename
ph_perfdatafile="/tmp/perfdata_`echo $_basename | sed "s#[^a-z0-9\-]#_#g"`" _basename=$(basename $0)
ph_perfdatafile="/tmp/perfdata_$(echo $_basename | sed "s#[^a-z0-9\-]#_#g")"
rm -f "${ph_perfdatafile}" 2>/dev/null rm -f "${ph_perfdatafile}" 2>/dev/null
} }
# generate label for performance data value # generate label for performance data value
function ph._getperflabel(){ function ph._getperflabel(){
echo $1 | tr [:upper:] [:lower:] | sed "s#[^a-z0-9\-]##g" echo "$1" | tr [:upper:] [:lower:] | sed "s#[^a-z0-9\-]##g"
} }
# get speed of change of a counter value # get speed of change of a counter value
# param1: string variable name # param1: string variable name
...@@ -371,7 +377,6 @@ function ph.perfdeltaspeed(){ ...@@ -371,7 +377,6 @@ function ph.perfdeltaspeed(){
local bcParam= local bcParam=
typeset -i newvalue=0
typeset -i deltaFactor=1 typeset -i deltaFactor=1
test "$deltaUnit" = "s" && deltaFactor=1 test "$deltaUnit" = "s" && deltaFactor=1
...@@ -382,7 +387,7 @@ function ph.perfdeltaspeed(){ ...@@ -382,7 +387,7 @@ function ph.perfdeltaspeed(){
test "$isFloat" = "float" && bcParam="-l" test "$isFloat" = "float" && bcParam="-l"
# get last value # get last value
local lastvalue=`ph._readlastvalue "${varName}"` local lastvalue=$(ph._readlastvalue "${varName}")
if [ "$lastvalue" = "" ]; then if [ "$lastvalue" = "" ]; then
# retvalue="[no last value]" # retvalue="[no last value]"
retvalue="" retvalue=""
...@@ -395,11 +400,11 @@ function ph.perfdeltaspeed(){ ...@@ -395,11 +400,11 @@ function ph.perfdeltaspeed(){
# retvalue="[reset data]" # retvalue="[reset data]"
retvalue="" retvalue=""
else else
local iage=`ph._getageoflastvalue "${varName}"` local iage=$(ph._getageoflastvalue "${varName}")
test $iage = 0 && iage=1 test $iage = 0 && iage=1
local delta=`echo "${value}-$lastvalue" | bc $bcParam ` local delta=$(echo "${value}-$lastvalue" | bc $bcParam )
local deltaspeed=`echo "${delta}*${deltaFactor}/(${iage})" | bc $bcParam` local deltaspeed=$(echo "${delta}*${deltaFactor}/(${iage})" | bc $bcParam)
retvalue=$deltaspeed retvalue=$deltaspeed
fi fi
fi fi
...@@ -407,7 +412,7 @@ function ph.perfdeltaspeed(){ ...@@ -407,7 +412,7 @@ function ph.perfdeltaspeed(){
#echo DEBUG sData="${sData} '${varName}'=${retvalue}" #echo DEBUG sData="${sData} '${varName}'=${retvalue}"
# sGDData="${sGDData} '${varName}'=${retvalue}" # sGDData="${sGDData} '${varName}'=${retvalue}"
echo ${retvalue} echo "${retvalue}"
# DEBUG - wird in Nagios sichtbar # DEBUG - wird in Nagios sichtbar
# gdAddLabel "... ${varName} absolute: ${value} -> delta: ${delta} -> derive: ${retvalue} ($iage sec)" # gdAddLabel "... ${varName} absolute: ${value} -> delta: ${delta} -> derive: ${retvalue} ($iage sec)"
...@@ -425,7 +430,7 @@ function ph.perfadd(){ ...@@ -425,7 +430,7 @@ function ph.perfadd(){
if [ -z "$ph_perfdatafile" ]; then if [ -z "$ph_perfdatafile" ]; then
ph._perfinit ph._perfinit
fi fi
local _label=`ph._getperflabel "$1"` local _label=$(ph._getperflabel "$1")
local _value=$2 local _value=$2
local _w=$3 local _w=$3
local _c=$4 local _c=$4
...@@ -435,7 +440,7 @@ function ph.perfadd(){ ...@@ -435,7 +440,7 @@ function ph.perfadd(){
if [ -z "$_min" ]; then if [ -z "$_min" ]; then
_min=0 _min=0
fi fi
echo "${_label}=${_value};${_w};${_c};${_min};${_max}" >>${ph_perfdatafile} echo "${_label}=${_value};${_w};${_c};${_min};${_max}" >>"${ph_perfdatafile}"
} }
...@@ -445,8 +450,8 @@ function ph.perfshow(){ ...@@ -445,8 +450,8 @@ function ph.perfshow(){
if [ ! -z "$ph_perfdatafile" ]; then if [ ! -z "$ph_perfdatafile" ]; then
if [ -f "$ph_perfdatafile" ]; then if [ -f "$ph_perfdatafile" ]; then
echo -n " |" echo -n " |"
cat ${ph_perfdatafile} | tr "\n" " " cat "${ph_perfdatafile}" | tr "\n" " "
rm -f ${ph_perfdatafile} rm -f "${ph_perfdatafile}"
fi fi
fi fi
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment