Created
September 15, 2016 12:59
-
-
Save maxried/cad35ef9652b894b48601bb6e8c59edf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
oid="" | |
community="" | |
host="" | |
label="" | |
unit="" | |
while getopts "C:H:o:l:u:" o; do | |
case "${o}" in | |
C) | |
community="$OPTARG" | |
;; | |
H) | |
host="$OPTARG" | |
;; | |
o) | |
oid="$OPTARG" | |
;; | |
l) | |
label="$OPTARG" | |
;; | |
u) | |
unit="$OPTARG" | |
;; | |
esac | |
done | |
result=$(snmpget -v2c -c $community -Oq -mALL "$host" "$oid" 2> /dev/null) | |
if [[ $? != 0 ]]; then | |
echo "SNMP UNKNOWN - $?" | |
exit 3 | |
else | |
declare -a 'a=('"$result"')' | |
name=${a[0]} | |
value=${a[1]} | |
unitsnmp=${a[2]} | |
if [[ "$label" != "" ]]; then | |
name="$label" | |
fi | |
if [[ "$unit" != "" ]]; then | |
unitsnmp="$unit" | |
fi | |
fi | |
echo "SNMP OK - $name $value $unitsnmp | '$name'=$value" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment