add basic ups check, but not done
This commit is contained in:
@@ -398,9 +398,6 @@ class SNMPSynologyCPUResource(nagiosplugin.Resource):
|
||||
result = self.session.get(baseoid + '.7.1.0').value
|
||||
return nagiosplugin.Metric(name='cpu', value=int(result), uom='%', context='cpu_scalar_context')
|
||||
|
||||
def __init__(self, session) -> None:
|
||||
self.session = session
|
||||
|
||||
|
||||
#
|
||||
# Synology [DSM] Utilization % is the sum of user and system CPU usage
|
||||
@@ -419,9 +416,6 @@ class SNMPSynologyMemoryResource(nagiosplugin.Resource):
|
||||
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
|
||||
|
||||
|
||||
#
|
||||
# Synology [DSM & DSM UC] Checks disks
|
||||
@@ -635,6 +629,54 @@ class SNMPSynologyRaidStatusResult(nagiosplugin.Result):
|
||||
return f'{self.metric.name} is in status {status}!'
|
||||
|
||||
|
||||
#
|
||||
# Synology [DSM & DSM UC] UPS staus (paused, not done)
|
||||
#
|
||||
class SNMPSynologyUPSResource(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.4'
|
||||
data = self.session.walk(baseoid)
|
||||
# not sure if this value time remaining ...
|
||||
time_until_empty = self.session.get(baseoid + '.3.6.1.0').value
|
||||
# not shure what (for my ups) satus 'OL' says, maybe "online" ?
|
||||
ups = dict()
|
||||
|
||||
ups['status'] = self.session.get(baseoid + '.2.1.0').value
|
||||
ups['model'] = self.session.get(baseoid + '.1.1.0').value
|
||||
ups['serial'] = self.session.get(baseoid + '.1.3.0').value
|
||||
return nagiosplugin.Metric(name='ups_' + ups["model"].lower().replace(' ', '_'), value=ups, context='ups_context')
|
||||
|
||||
|
||||
|
||||
class SNMPSynologyUPSContext(nagiosplugin.Context):
|
||||
def __init__(self, name):
|
||||
super().__init__(name, fmt_metric='{name} is', result_cls=SNMPSynologyUPSResult)
|
||||
|
||||
def evaluate(self, metric, resource):
|
||||
if metric.value['status'] == '?':
|
||||
return self.result_cls(nagiosplugin.Critical, "critical", metric)
|
||||
elif metric.value['status'] == '?':
|
||||
return self.result_cls(nagiosplugin.Warn, "warning", metric)
|
||||
elif metric.value['status'] == 'OL':
|
||||
return self.result_cls(nagiosplugin.Ok, "ok", metric)
|
||||
return self.result_cls(nagiosplugin.Unknown, "unknown", metric)
|
||||
|
||||
|
||||
class SNMPSynologyUPSResult(nagiosplugin.Result):
|
||||
def __str__(self):
|
||||
if self.metric.value['status'] == 'OL': status = 'Online' # ?
|
||||
else: status = 'unknown'
|
||||
return f'{self.metric.name} is in status {status}!'
|
||||
|
||||
|
||||
#
|
||||
# Arguments
|
||||
#
|
||||
@@ -669,6 +711,7 @@ def parse_args() -> argparse.Namespace:
|
||||
'disk_sectors',
|
||||
'raid',
|
||||
'raid_space',
|
||||
'ups',
|
||||
],
|
||||
help='check mode to run')
|
||||
|
||||
@@ -785,6 +828,11 @@ def main():
|
||||
nagiosplugin.ScalarContext(name='raid_space_scalar_context', warning=args.warning, critical=args.critical),
|
||||
nagiosplugin.Summary())
|
||||
check.name = "Raid space usage"
|
||||
case 'ups':
|
||||
check = nagiosplugin.Check(SNMPSynologyUPSResource(session=session),
|
||||
SNMPSynologyUPSContext(name='ups_context'),
|
||||
SNMPSynologySummary())
|
||||
check.name = "UPS status"
|
||||
case _:
|
||||
raise nagiosplugin.CheckError(f'Unknown check mode: {args.check_mode}')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user