add power supply check

This commit is contained in:
2025-02-07 16:50:32 +01:00
parent 135863cdf8
commit f1cc9bb7c5

View File

@@ -8,7 +8,7 @@
- https://easysnmp.readthedocs.io/en/latest/session_api.html
"""
__version__ = '0.1.0'
__version__ = '0.3.0'
__author__ = 'anima'
# imports
@@ -135,7 +135,7 @@ class SNMPSynologySysTempResource(nagiosplugin.Resource):
self.session = session
def probe(self) -> list:
"""check system status (normal or failed).
"""check system temperature in °C
Returns:
nagiosplugin.Metric: single metric element (return)
@@ -143,12 +143,48 @@ class SNMPSynologySysTempResource(nagiosplugin.Resource):
baseoid = '.1.3.6.1.4.1.6574.1'
oids = dict()
result = self.session.get(baseoid + '.2.0').value
return nagiosplugin.Metric(name='systemp', value=int(result), context='systemp_scalar_context')
return nagiosplugin.Metric(name='systemp', value=int(result), uom='°C', context='systemp_scalar_context')
def __init__(self, session) -> None:
self.session = session
#
# Synology [DSM & DSM UC] Returns error if power supplies fail
#
class SNMPSynologyPowerSupplyResource(nagiosplugin.Resource):
def __init__(self, session) -> None:
self.session = session
def probe(self) -> list:
"""check power supply status (normal or failed)
Returns:
nagiosplugin.Metric: single metric element (return)
"""
baseoid = '.1.3.6.1.4.1.6574.1'
result = self.session.get(baseoid + '.3.0').value
return nagiosplugin.Metric(name='status', value=result, context='powersupply_context')
class SNMPSynologyPowerSupplyResult(nagiosplugin.Result):
def __str__(self):
if self.metric.value == '1': status = 'normal'
else: status = 'failed'
return f'Power Supply is in status {status}!'
class SNMPSynologyPowerSupplyContext(nagiosplugin.Context):
def __init__(self, name):
super().__init__(name, fmt_metric='{name} is', result_cls=SNMPSynologyPowerSupplyResult)
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)
#
# Arguments
@@ -172,6 +208,7 @@ def parse_args() -> argparse.Namespace:
choices=[
'system',
'systemp',
'powersupply',
],
help='check mode to run')
@@ -227,6 +264,11 @@ def main():
nagiosplugin.ScalarContext(name='systemp_scalar_context', warning=args.warning, critical=args.critical),
nagiosplugin.Summary())
check.name = "System Temperatur"
case 'powersupply':
check = nagiosplugin.Check(SNMPSynologyPowerSupplyResource(session=session),
SNMPSynologyPowerSupplyContext(name='powersupply_context'),
nagiosplugin.Summary())
check.name = "Power Supply Status"
case _:
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')