Skip to content
Snippets Groups Projects
check_sensuplugins 1.87 KiB
#!/bin/bash
# ======================================================================
#
# SENSU CHECK FOR VALIDITY OF PLUGIN LINKS
#
# ----------------------------------------------------------------------
#
# ----------------------------------------------------------------------
# 2018-07-17  first lines
# 2022-10-21  v1.1  <axel.hahn@unibe.ch>     remove grep: warning: stray \ before white space
# ======================================================================

. `dirname $0`/inc_pluginfunctions


tmpfile=/tmp/check_sensuplugins.out

# ----------------------------------------------------------------------
# functions to fetch infos by status
# ----------------------------------------------------------------------

function _getStatus(){
  cat $tmpfile  | grep '^\.\.\.' | grep " $1\:"
}

function getTotal(){
  _getStatus '.*'
}
function getOK(){
  _getStatus "OK"
}
function getWarnings(){
  _getStatus "WARNING"
}
function getErrors(){
  _getStatus "ERROR"
}


# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
(/usr/local/bin/link-sensu-checks.sh -i ; /usr/local/bin/link-sensu-checks.sh -f) >$tmpfile

# --- output of errors and warnings
echo --- Check sensu plugins
getErrors
getWarnings

# --- show status
typeset -i iTOTAL=`getTotal | wc -l`
typeset -i iOK=`getOK | wc -l`
typeset -i iERRORS=`getErrors | wc -l`
typeset -i iWARNINGS=`getWarnings | wc -l`

echo --- Status:
echo "total   : $iTOTAL"
echo "Errors  : $iERRORS"
echo "Warnings: $iWARNINGS"
echo "OK      : $iOK"

rm -f $tmpfile

# --- return with wanted exitcode
if [ $iERRORS -gt 0 ]; then
  echo exit with error.
  exit $EXIT_CRITICAL
fi

if [ $iWARNINGS -gt 0 ]; then
  echo exit with warning
  exit $EXIT_WARNING
fi

echo exit with OK
exit $EXIT_OK

# ----------------------------------------------------------------------