From 7be320c88ba20d19e66d9face5531eaa3d02d38f Mon Sep 17 00:00:00 2001 From: anima Date: Fri, 7 Feb 2025 17:08:44 +0100 Subject: [PATCH] move context above result --- checks/check_snmp_synology.py | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/checks/check_snmp_synology.py b/checks/check_snmp_synology.py index e71364a..eef16c7 100755 --- a/checks/check_snmp_synology.py +++ b/checks/check_snmp_synology.py @@ -108,13 +108,6 @@ class SNMPSynologySystemResource(nagiosplugin.Resource): return nagiosplugin.Metric(name='status', value=result, context='system_context') -class SNMPSynologySystemResult(nagiosplugin.Result): - def __str__(self): - if self.metric.value['status'] == '1': status = 'normal' - else: status = 'failed' - return f'{self.metric.value["model"]} (SN: {self.metric.value["sn"]}) is in status {status}!' - - class SNMPSynologySystemContext(nagiosplugin.Context): def __init__(self, name): super().__init__(name, fmt_metric='{name} is', result_cls=SNMPSynologySystemResult) @@ -127,6 +120,13 @@ class SNMPSynologySystemContext(nagiosplugin.Context): return self.result_cls(nagiosplugin.Unknown, "unknown", metric) +class SNMPSynologySystemResult(nagiosplugin.Result): + def __str__(self): + if self.metric.value['status'] == '1': status = 'normal' + else: status = 'failed' + return f'{self.metric.value["model"]} (SN: {self.metric.value["sn"]}) is in status {status}!' + + # # Synology [DSM & DSM UC] Temperature of NAS # @@ -167,13 +167,6 @@ class SNMPSynologyPowerSupplyResource(nagiosplugin.Resource): 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) @@ -186,6 +179,13 @@ class SNMPSynologyPowerSupplyContext(nagiosplugin.Context): return self.result_cls(nagiosplugin.Unknown, "unknown", metric) +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}!' + + # # Synology [DSM & DSM UC] Returns error if system fan fails # @@ -209,13 +209,6 @@ class SNMPSynologyFansResource(nagiosplugin.Resource): 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) @@ -228,6 +221,13 @@ class SNMPSynologyFansContext(nagiosplugin.Context): return self.result_cls(nagiosplugin.Unknown, "unknown", metric) +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 SNMPSynologyFansSummary(nagiosplugin.Summary): def verbose(self, results): result_str = ''