Skip to content

Instantly share code, notes, and snippets.

@maxried
Created September 15, 2016 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxried/cad35ef9652b894b48601bb6e8c59edf to your computer and use it in GitHub Desktop.
Save maxried/cad35ef9652b894b48601bb6e8c59edf to your computer and use it in GitHub Desktop.
#!/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