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

check_ceph_io

Blame
  • check_packages2install 3.73 KiB
    #!/bin/bash
    # ======================================================================
    #
    # NAGIOS CLIENT CHECK :: check available package updates
    # requires no root for yum ... apt I must verify
    #
    # ----------------------------------------------------------------------
    #
    # ah=axel.hahn@iml.unibe.ch
    # ds=daniel.schueler@iml.unibe.ch
    #
    # 2016-12-23  v0.3  ah,ds
    # 2018-12-18  v1.0  ah     added check for auto update (IML specific)
    # 2019-03-26  v1.1  ah     fix apt-get (not all constellations worked)
    # 2019-04-29  v1.2  ah     yum: supress error channel output (task #2959)
    # 2020-03-05  v1.3  <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
    # 2020-03-11  v1.4  <axel.hahn@iml.unibe.ch> add -c -w limits; added perfdata (yum)
    # ======================================================================
    
    
    . `dirname $0`/inc_pluginfunctions
    
    typeset -i iCount=0
    tmpfile=/tmp/packages2install.log
    cronfile=/etc/cron.d/system-updater
    
    # ----------------------------------------------------------------------
    # functions
    # ----------------------------------------------------------------------
    
    function showAutoupdate(){
      ls ${cronfile} >/dev/null 2>&1
      if [ $? -eq 0 ]; then
        echo Autoupdate ON
        grep "\ \-r" ${cronfile} >/dev/null 2>&1
        if [ $? -eq 0 ]; then
          echo Autoreboot ON
        else
          echo Autoreboot OFF
        fi
      else
        echo Autoupdate OFF
      fi
    }
    
    # check updates with apt and exit script
    function checkApt(){
      # bug #2818
      sudo apt-get -v >/dev/null
      if [ $? -ne 0 ]; then
        ph.setStatus "error"
        echo "ERROR: failed to run apt-get"
        echo "OUTPUT is:"
        sudo apt-get -v
      else
    
        summary=`ph.execIfReady "sudo apt-get -u upgrade --assume-no | grep installed | grep upgraded" `
        # example output:
        # 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
        typeset -i local iPkg2Update=`echo $summary | cut -f 1 -d " "`
    
        ph.setStatusByLimit ${iPkg2Update} ${iWarnLimit} ${iCriticalLimit}
        ph.perfadd "updates-available" "${iPkg2Update}" ${iWarnLimit} ${iCriticalLimit}
    
        # --- output
        ph.status "$summary"
        echo "[apt]"
        echo
    
      fi
    
    }
    
    
    # check updates with yum and exit script
    function checkYum(){
    
      summary=`ph.execIfReady "/usr/bin/yum --security  check-update 2>/dev/null | fgrep 'for security'" `
    
      # example outputs:
      # I   No packages needed for security; 223 packages available
      # II  2 package(s) needed for security, out of 237 available
      typeset -i local iPkgSecurity=` echo $summary | cut -f 1  -d ' ' | sed "s#[^0-9]##g"`
      typeset -i local iPkg2Update=`  echo $summary | cut -f 2- -d ' ' | sed "s#[^0-9]##g"`
    
      # step I: check limits with packages to update:
      ph.setStatusByLimit ${iPkg2Update} ${iWarnLimit} ${iCriticalLimit}
    
      # step II: security packages switch to "critical"
      if [ ${iPkgSecurity} -ne 0 ]; then
        ph.setStatus "critical"
      fi
    
      ph.perfadd "updates-available" "${iPkg2Update}"  ${iWarnLimit} ${iCriticalLimit}
      ph.perfadd "updates-security"  "${iPkgSecurity}" ""            1
    
      ph.status "$summary"
      echo "[yum]"
      echo
    }
    
    
    # ----------------------------------------------------------------------
    # main
    # ----------------------------------------------------------------------
    
    # set default / override from command line params
    typeset -i iWarnLimit=`     ph.getValueWithParam 1   w "$@"`
    typeset -i iCriticalLimit=` ph.getValueWithParam 200 c "$@"`
    
    typeset -i bFound=0
    
    # ----- try package manager apt
    if [ `which apt-get 2>/dev/null` ]; then
      bFound=1
      checkApt
    fi
    
    # ----- try package manager yum
    if [ `which yum 2>/dev/null` ]; then
      bFound=1
      checkYum
    fi
    
    
    if [ $bFound -eq 0 ]; then
      ph.abort "UNKNOWN: package manager is not supported yet. I only know apt and yum so far."
    fi
    
    showAutoupdate
    ph.exit
    
    
    # ----------------------------------------------------------------------