add fan check

This commit is contained in:
2025-02-07 17:07:18 +01:00
parent f1cc9bb7c5
commit ac9e80bf2b

View File

@@ -8,7 +8,7 @@
- https://easysnmp.readthedocs.io/en/latest/session_api.html
"""
__version__ = '0.3.0'
__version__ = '0.4.0'
__author__ = 'anima'
# imports
@@ -186,6 +186,62 @@ class SNMPSynologyPowerSupplyContext(nagiosplugin.Context):
return self.result_cls(nagiosplugin.Unknown, "unknown", metric)
#
# Synology [DSM & DSM UC] Returns error if system fan fails
#
class SNMPSynologyFansResource(nagiosplugin.Resource):
def __init__(self, session) -> None:
self.session = session
def probe(self) -> list:
"""check fans status (normal or failed)
Returns:
nagiosplugin.Metric: single metric element (return)
"""
baseoid = '.1.3.6.1.4.1.6574.1'
fans = dict()
fans['system'] = '.4.1.0'
fans['cpu'] = '.4.2.0'
for fan, oid in fans.items():
result = self.session.get(baseoid + oid).value
yield nagiosplugin.Metric(name=fan, value=result, context='fan_context')
class SNMPSynologyFansResult(nagiosplugin.Result):
def __str__(self):
if self.metric.value == '1': status = 'normal'
else: status = 'failed'
return f'{self.metric.name} fan is in status {status}!'
class SNMPSynologyFansContext(nagiosplugin.Context):
def __init__(self, name):
super().__init__(name, fmt_metric='{name} is', result_cls=SNMPSynologyFansResult)
def evaluate(self, metric, resource):
if metric.value == '2':
return self.result_cls(nagiosplugin.Critical, "critical", metric)
elif metric.value == '1':
return self.result_cls(nagiosplugin.Ok, "ok", metric)
return self.result_cls(nagiosplugin.Unknown, "unknown", metric)
class SNMPSynologyFansSummary(nagiosplugin.Summary):
def verbose(self, results):
result_str = ''
for result in results:
result_str += f'{str(result)}\n'
return result_str
def ok(self, results):
return
def problem(self, results):
return
#
# Arguments
#
@@ -209,6 +265,7 @@ def parse_args() -> argparse.Namespace:
'system',
'systemp',
'powersupply',
'fans',
],
help='check mode to run')
@@ -269,6 +326,11 @@ def main():
SNMPSynologyPowerSupplyContext(name='powersupply_context'),
nagiosplugin.Summary())
check.name = "Power Supply Status"
case 'fans':
check = nagiosplugin.Check(SNMPSynologyFansResource(session=session),
SNMPSynologyFansContext(name='fan_context'),
SNMPSynologyFansSummary())
check.name = "Fans Status"
case _:
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')