From 7f05c501e806d9a09fc9839d326c8360e756120e Mon Sep 17 00:00:00 2001
From: Andrea Gottsponer <ago@attr.ch>
Date: Fri, 21 Oct 2022 16:50:15 +0200
Subject: [PATCH] - add disc check to snmp-synology

---
 check_snmp_data | 49 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/check_snmp_data b/check_snmp_data
index 6fc4dab..954613f 100755
--- a/check_snmp_data
+++ b/check_snmp_data
@@ -14,7 +14,7 @@
 #
 # SYNTAX: 
 # label    --> DATA:[method]:label:[text]
-# n x data --> DATA:[method]:data:[perf-label]:[oid]:[optional unit]
+# n x data --> DATA:[method]:data:[perf-label]:[oid]:[optional unit]:[loop oid]
 #
 # DATA:cpu:label:CPU usage
 # DATA:cpu:data:cpu-user:1.3.6.1.4.1.2021.11.9.0:%
@@ -33,6 +33,10 @@
 # DATA:synotemp:label:Synology NAS temperature
 # DATA:synotemp:data:temp:1.3.6.1.4.1.6574.1.2.0:°C
 #
+# DATA:disc:label:Disc usage
+# DATA:disc:data:disc-free:1.3.6.1.4.1.6574.3.1.1.2::1.3.6.1.4.1.6574.3.1.1.4
+# DATA:disc:data:disc-space:1.3.6.1.4.1.6574.3.1.1.2::1.3.6.1.4.1.6574.3.1.1.5
+#
 # ----------------------------------------------------------------------
 # 2020-08-11  <axel.hahn@iml.unibe.ch>  initial version
 # 2020-08-13  <axel.hahn@iml.unibe.ch>  add host in label for counter data
@@ -45,6 +49,7 @@
 ABOUT="SNMP performance data v0.4"
 SNMPCOMMUNITY="public"
 SNMPVERSION="2c"
+SNMPWALK=$(which snmpwalk)
 SNMPGET=$(which snmpget)
 
 HOSTNAME="127.0.0.1"
@@ -201,9 +206,30 @@ fi
 prflist=( $(_cfg_dataitem 4) )
 oidlist=( $(_cfg_dataitem 5) )
 unitlist=( $(_cfg_dataitem 6) )
+looplist=( $(_cfg_dataitem 7) )
+
+# --- check for looplist
+if [ -n "$looplist" ]; then
+  nb=`$SNMPWALK -OQne -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]} 2> /dev/null | wc -l`
+
+  declare -a tmpPrflist=()
+  declare -a tmpOidlist=()
+  declare -a tmpUnitlist=()
+  for i in `seq 1 $nb`;
+  do
+    for j in `seq 1 ${#looplist[@]}`
+    do
+      tmpPrflist+=("${prflist[$(($j-1))]}.$(($i-1))")
+      tmpOidlist+=("${looplist[$(($j-1))]}.$(($i-1))")
+      tmpUnitlist+=("${unitlist[$(($j-1))]}")
+    done
+  done
+  prflist=( "${tmpPrflist[@]}" )
+  oidlist=( "${tmpOidlist[@]}" )
+  unitlist=( "${tmpUnitlist[@]}" )
+fi
 
-
-# --- SNPGET to all wanted oids
+# --- SNMPGET to all wanted oids
 SYNO=`$SNMPGET -One -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]} 2> /dev/null`
 
 if [ $? -ne 0 ] ; then
@@ -219,13 +245,18 @@ do
     value=$(_get ${oidlist[$index]})
     unit="${unitlist[$index]}"
 
-    # handle counter data
-    if [ "$(_iscounter ${oidlist[$index]})" = "true" ]; then
-        value2=`ph.perfdeltaspeed "snmp-data-${HOSTNAME}-${method}-${label}" $value`
-        _wd "$( printf '%-14s total: %-14s delta: %6s %s per sec' $label $value $value2 $unit )"
-        value=$value2
+    # handle loop data
+    if [ -n "$looplist" ]; then
+      _wd "$( printf '%-14s %s %s' $label $value $unit )"
     else
-        _wd "$( printf '%-14s %s %s' $label $value $unit )"
+      # handle counter data
+      if [ "$(_iscounter ${oidlist[$index]})" = "true" ]; then
+          value2=`ph.perfdeltaspeed "snmp-data-${HOSTNAME}-${method}-${label}" $value`
+          _wd "$( printf '%-14s total: %-14s delta: %6s %s per sec' $label $value $value2 $unit )"
+          value=$value2
+      else
+          _wd "$( printf '%-14s %s %s' $label $value $unit )"
+      fi
     fi
 
     ph.perfadd "${label}" "${value}"
-- 
GitLab