Skip to content
Snippets Groups Projects
Select Git revision
  • 09af01af86f7670ab79650d22b1dbce44096f66e
  • master default protected
  • simple-task/7248-eol-check-add-node-22
  • 6877_check_iml_deployment
4 results

check_smartstatus

Blame
  • 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
    
    # ----------------------------------------------------------------------