#! /bin/bash set -eu -o pipefail function _usage { echo "Usage: $O -H addresse -C public -w W% -c X%" exit 3 } black=SNMPv2-SMI::mib-2.43.11.1.1.9.1.1 blue=SNMPv2-SMI::mib-2.43.11.1.1.9.1.2 magenta=SNMPv2-SMI::mib-2.43.11.1.1.9.1.3 yellow=SNMPv2-SMI::mib-2.43.11.1.1.9.1.4 if [ $# -lt 1 ] ; then _usage ; fi while getopts "hH:w:c:C:i:" opt ; do case $opt in (i) color=$OPTARG ;; (C) community=$OPTARG ;; (H) host=$OPTARG ;; (h) _usage ;; (w) warning=$OPTARG ;; (c) critical=$OPTARG ;; (*) _usage ;; esac done test -x /usr/bin/snmpwalk || exit 3 v=$(snmpwalk -v2c -c "${community}" "${host}" ${!color} -Oq | awk '{print $2}') if [ "$v" -lt "$critical" ] ; then echo "$color critical level" exit 2 fi if [ "$v" -lt "$warning" ] ; then echo "$color warning level" exit 1 fi echo "$color ok level" exit 0