From ddd3e386a25827796e90849dbbe74e845277a63d Mon Sep 17 00:00:00 2001
From: anima
Date: Fri, 7 Feb 2025 17:58:39 +0100
Subject: [PATCH] add memory check
---
checks/check_snmp_synology.py | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/checks/check_snmp_synology.py b/checks/check_snmp_synology.py
index 7501994..c55bd4c 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.6.0'
+__version__ = '0.7.0'
__author__ = 'anima'
# imports
@@ -300,7 +300,7 @@ class SNMPSynologyCPUResource(nagiosplugin.Resource):
self.session = session
def probe(self) -> list:
- """check system temperature in °C
+ """check cpu usage %
Returns:
nagiosplugin.Metric: single metric element (return)
@@ -314,6 +314,28 @@ class SNMPSynologyCPUResource(nagiosplugin.Resource):
self.session = session
+#
+# Synology [DSM & DSM UC] Utilization % is the sum of user and system CPU usage
+#
+class SNMPSynologyMemoryResource(nagiosplugin.Resource):
+ def __init__(self, session) -> None:
+ self.session = session
+
+ def probe(self) -> list:
+ """check memory usage in %
+
+ Returns:
+ nagiosplugin.Metric: single metric element (return)
+ """
+ baseoid = '.1.3.6.1.4.1.6574.1'
+ oids = dict()
+ result = self.session.get(baseoid + '.7.2.0').value
+ return nagiosplugin.Metric(name='memory', value=int(result), uom='%', context='memory_scalar_context')
+
+ def __init__(self, session) -> None:
+ self.session = session
+
+
#
# Arguments
@@ -341,6 +363,7 @@ def parse_args() -> argparse.Namespace:
'fans',
'firmware',
'cpu',
+ 'memory',
],
help='check mode to run')
@@ -416,6 +439,11 @@ def main():
nagiosplugin.ScalarContext(name='cpu_scalar_context', warning=args.warning, critical=args.critical),
nagiosplugin.Summary())
check.name = "CPU Usage"
+ case 'memory':
+ check = nagiosplugin.Check(SNMPSynologyMemoryResource(session=session),
+ nagiosplugin.ScalarContext(name='memory_scalar_context', warning=args.warning, critical=args.critical),
+ nagiosplugin.Summary())
+ check.name = "Memory Usage"
case _:
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')