From a09b5690651bb336e4d087a2b1d5b80a590141c8 Mon Sep 17 00:00:00 2001 From: 1938389 <1938389+netravnen@users.noreply.github.com> Date: Tue, 8 Nov 2022 10:44:01 +0100 Subject: [PATCH] snmp: script: add snmpd extend for counting security updates alongside the total osupdate counting --- snmp/securityupdate | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 snmp/securityupdate diff --git a/snmp/securityupdate b/snmp/securityupdate new file mode 100755 index 000000000..5bb91ea05 --- /dev/null +++ b/snmp/securityupdate @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +################################################################ +# copy this script to /etc/snmp/ and make it executable: # +# chmod +x /etc/snmp/securityupdate # +# ------------------------------------------------------------ # +# edit your snmpd.conf and include: # +# extend securityupdate /etc/snmp/securityupdate # +#--------------------------------------------------------------# +# restart snmpd and activate the app for desired host # +#--------------------------------------------------------------# +# please make sure you have the path/binaries below # +################################################################ +BIN_WC='/usr/bin/env wc' +BIN_GREP='/usr/bin/env grep' +CMD_GREP='-c' +CMD_WC='-l' +BIN_APT='/usr/bin/env apt-get' +CMD_APT='-qq -s upgrade' + +################################################################ +# Don't change anything unless you know what are you doing # +################################################################ +if command -v apt-get &>/dev/null ; then + # Debian / Devuan / Ubuntu + # shellcheck disable=SC2086 + UPDATES=$($BIN_APT $CMD_APT | $BIN_GREP 'Inst' | $BIN_GREP $CMD_GREP '-security') + if [ "$UPDATES" -ge 1 ]; then + echo "$UPDATES"; + else + echo "0"; + fi +else + echo "0"; +fi