#!/bin/bash # Source in the nagios return code library. . utils.sh TOCHECK="" CHECKSECURITY=0 while getopts ":sr:" flag do if [ "$(echo "$flag" $OPTIND | grep "r")" ]; then TOCHECK="${TOCHECK} ${OPTARG}"; elif [ "$(echo "$flag" $OPTIND | grep "s")" ]; then CHECKSECURITY=1; elif [ "$(echo "$flag" $OPTIND $OPTARG | grep "\?")" ]; then echo "Usage: $0 [-s] [-r pkg_name] [-r pkgname] [-r pkgname]..."; echo " -s = set state as critical if there are security packages available."; echo " -r = set state as critical if this package has an update available."; exit ${STATE_UNKNOWN}; fi done if [ ! "`which yum`" ]; then echo "UNKNOWN: This utility requires the yum package manager." exit ${STATE_UNKNOWN}; fi YUM=`which yum`; # Clean out the yum cache. ${YUM} clean all 2>/dev/null >/dev/null # Check for packages that are required to be installed. for i in `yum check-update | awk '{print $1}' | grep -v "Loaded" | grep -v "Skipping"`; do for j in ${TOCHECK}; do if [ ${i} == ${j} ]; then echo "CRITICAL: A package marked as required has an update available."; exit ${STATE_CRITICAL}; fi done done if [ ${CHECKSECURITY} -ne 0 ]; then # Check for security updates. If they're available, the system is critical. if [ "`${YUM} check-update --security 2>/dev/null | grep "Needed .* of .* packages, for security"`" ]; then echo "CRITICAL: Security updates available."; exit ${STATE_CRITICAL}; # Check bug-fix and feature updates. These are still important, but probably not critical. elif [ $((`${YUM} check-update 2>/dev/null | wc -l`)) -gt 3 ]; then echo "WARNING: Bug fix or enhancement updates available."; exit ${STATE_WARNING}; # The system is up to date. else echo "OK: System appears to be up to date."; exit ${STATE_OK}; fi else if [ $((`${YUM} check-update 2>/dev/null | wc -l`)) -gt 3 ]; then echo "WARNING: Updates available."; exit ${STATE_WARNING}; # The system is up to date. else echo "OK: System appears to be up to date."; exit ${STATE_OK}; fi fi