add power supply check
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
- https://easysnmp.readthedocs.io/en/latest/session_api.html
|
- https://easysnmp.readthedocs.io/en/latest/session_api.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = '0.1.0'
|
__version__ = '0.3.0'
|
||||||
__author__ = 'anima'
|
__author__ = 'anima'
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
@@ -135,7 +135,7 @@ class SNMPSynologySysTempResource(nagiosplugin.Resource):
|
|||||||
self.session = session
|
self.session = session
|
||||||
|
|
||||||
def probe(self) -> list:
|
def probe(self) -> list:
|
||||||
"""check system status (normal or failed).
|
"""check system temperature in °C
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
nagiosplugin.Metric: single metric element (return)
|
nagiosplugin.Metric: single metric element (return)
|
||||||
@@ -143,12 +143,48 @@ class SNMPSynologySysTempResource(nagiosplugin.Resource):
|
|||||||
baseoid = '.1.3.6.1.4.1.6574.1'
|
baseoid = '.1.3.6.1.4.1.6574.1'
|
||||||
oids = dict()
|
oids = dict()
|
||||||
result = self.session.get(baseoid + '.2.0').value
|
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:
|
def __init__(self, session) -> None:
|
||||||
self.session = session
|
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
|
# Arguments
|
||||||
@@ -172,6 +208,7 @@ def parse_args() -> argparse.Namespace:
|
|||||||
choices=[
|
choices=[
|
||||||
'system',
|
'system',
|
||||||
'systemp',
|
'systemp',
|
||||||
|
'powersupply',
|
||||||
],
|
],
|
||||||
help='check mode to run')
|
help='check mode to run')
|
||||||
|
|
||||||
@@ -227,6 +264,11 @@ def main():
|
|||||||
nagiosplugin.ScalarContext(name='systemp_scalar_context', warning=args.warning, critical=args.critical),
|
nagiosplugin.ScalarContext(name='systemp_scalar_context', warning=args.warning, critical=args.critical),
|
||||||
nagiosplugin.Summary())
|
nagiosplugin.Summary())
|
||||||
check.name = "System Temperatur"
|
check.name = "System Temperatur"
|
||||||
|
case 'powersupply':
|
||||||
|
check = nagiosplugin.Check(SNMPSynologyPowerSupplyResource(session=session),
|
||||||
|
SNMPSynologyPowerSupplyContext(name='powersupply_context'),
|
||||||
|
nagiosplugin.Summary())
|
||||||
|
check.name = "Power Supply Status"
|
||||||
case _:
|
case _:
|
||||||
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')
|
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user