Skip to content

Instantly share code, notes, and snippets.

@davidc
Created September 19, 2019 20:40
Show Gist options
  • Save davidc/ac573b62d6e9a9a9b6046b0142996fed to your computer and use it in GitHub Desktop.
Save davidc/ac573b62d6e9a9a9b6046b0142996fed to your computer and use it in GitHub Desktop.
check_mikrotik_sw_fw updates
# diff -u check_mikrotik_sw_fw check_mikrotik_sw_fw.new
--- check_mikrotik_sw_fw 2019-09-05 16:12:12.843534466 +0200
+++ check_mikrotik_sw_fw.new 2019-09-19 22:38:11.560855856 +0200
@@ -24,8 +24,19 @@
;;
esac
done
-FW=$(snmpwalk -Ov -On -Oq -Cc -c $COMMUNITY -v $VERSION $HOST .1.3.6.1.4.1.14988.1.1.7.4.0)
-SW=$(snmpwalk -Ov -On -Oq -Cc -c $COMMUNITY -v $VERSION $HOST .1.3.6.1.4.1.14988.1.1.4.4.0)
+
+FW=$(snmpget -Ov -Oq -c $COMMUNITY -v $VERSION $HOST .1.3.6.1.4.1.14988.1.1.7.4.0 2>&1)
+if [ $? -ne 0 ]; then
+ echo "UNKNOWN: ${FW}"
+ exit 3
+fi
+
+SW=$(snmpget -Ov -Oq -c $COMMUNITY -v $VERSION $HOST .1.3.6.1.4.1.14988.1.1.4.4.0 2>&1)
+if [ $? -ne 0 ]; then
+ echo "UNKNOWN: ${SW}"
+ exit 3
+fi
+
if [ "$FW" == "$SW" ]; then
echo "OK: Software and firmware versions match ($SW)"
exit 0
@davidc
Copy link
Author

davidc commented Sep 19, 2019

  • check exit status from snmp command and return "UNKNOWN" if it failed
  • use snmpget instead of snmpwalk since a specific OID is being queried, we don't need to walk anything
  • don't use -On, unnecessary since OID is being suppressed anyway by -Ov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment