From 47a7c1f95d8c5c070387b44d8726dfe15a0cddc0 Mon Sep 17 00:00:00 2001
From: anima
Date: Mon, 10 Feb 2025 01:13:40 +0100
Subject: [PATCH] add raid space usage
---
checks/check_snmp_synology.py | 72 ++++++++++++++++++++++++++++++++++-
1 file changed, 70 insertions(+), 2 deletions(-)
diff --git a/checks/check_snmp_synology.py b/checks/check_snmp_synology.py
index f3be56f..e878869 100755
--- a/checks/check_snmp_synology.py
+++ b/checks/check_snmp_synology.py
@@ -8,7 +8,7 @@
- https://easysnmp.readthedocs.io/en/latest/session_api.html
"""
-__version__ = '0.11.0'
+__version__ = '0.12.0'
__author__ = 'anima'
# imports
@@ -126,6 +126,42 @@ class SNMPSynologyDisk():
return disks
+#
+# Synology [DSM & DSM UC] Checks raids (baseclass)
+#
+class SNMPSynologyRaid():
+ def __init__(self, session):
+ self.session = session
+
+ def get_raids(self):
+ raids = list()
+ baseoid = '.1.3.6.1.4.1.6574.3'
+ oids = dict()
+ oids['index'] = '1'
+ oids['name'] = '2'
+ oids['status'] = '3'
+ oids['free'] = '4'
+ oids['total'] = '5'
+ oids['hotspare'] = '6'
+
+ raid_ids = list()
+ results = self.session.walk(baseoid)
+ for result in results:
+ if '6574.3.1.1.1.' in result.oid:
+ raid_ids.append(result.value)
+
+ for raid in raid_ids:
+ tmp_raid = dict()
+ for result in results:
+ for name, oid in oids.items():
+ if '6574.3.1.1.' + oid + '.' + raid in result.oid:
+ tmp_raid[name] = result.value
+ break
+ raids.append(tmp_raid)
+
+ return raids
+
+
#
# Synology General Summary
#
@@ -516,10 +552,36 @@ class SNMPSynologyDiskHealthResult(nagiosplugin.Result):
return f'Health of {self.metric.name} is in status {status}!'
+#
+# Synology [DSM & DSM UC] Checks RAID status
+#
+class SNMPSynologyRaidSpaceResource(nagiosplugin.Resource, SNMPSynologyRaid):
+ def __init__(self, session) -> None:
+ self.session = session
+
+ def probe(self) -> list:
+ """check memory usage in %
+
+ Returns:
+ Generator[nagisplugin.Metric]: multiple metric elements (yield)
+ """
+ raids = self.get_raids()
+ for raid in raids:
+ # skip storage pools because they already full of there volumes
+ # works only with default naming maybe as argument ?
+ if raid['name'].startswith('Storage Pool'):
+ continue
+ used_space_in_percent = 100 - int(int(raid['free']) / int(raid['total']) * 100)
+ yield nagiosplugin.Metric(name='raid_' + raid["name"].lower().replace(' ', '_'), value=used_space_in_percent, uom='%', context='raid_space_scalar_context')
+
+ def __init__(self, session) -> None:
+ self.session = session
+
+
#
# Arguments
#
-def parse_args() -> argparse.Namespace:
+def parse_args() -> argparse.Namespace:
"""evaluates given arguments
Returns:
@@ -548,6 +610,7 @@ def parse_args() -> argparse.Namespace:
'disk_ident',
'disk_life',
'disk_sectors',
+ 'raid',
],
help='check mode to run')
@@ -654,6 +717,11 @@ def main():
nagiosplugin.ScalarContext(name='disk_sectors_scalar_context', warning=args.warning, critical=args.critical),
nagiosplugin.Summary())
check.name = "Disk BadSectors"
+ case 'raid':
+ check = nagiosplugin.Check(SNMPSynologyRaidSpaceResource(session=session),
+ nagiosplugin.ScalarContext(name='raid_space_scalar_context', warning=args.warning, critical=args.critical),
+ nagiosplugin.Summary())
+ check.name = "Raid space usage"
case _:
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')