mirror of
https://github.com/pengutronix/monitoring-check-systemd-service.git
synced 2025-07-23 22:04:46 +02:00
use new Context for Services (without scalars)
This commit is contained in:
parent
e7007a386d
commit
ada72ea3c7
@ -120,6 +120,20 @@ class Systemd_Service(nagiosplugin.Resource):
|
|||||||
self.service_state = (self.activestate(), self.substate())
|
self.service_state = (self.activestate(), self.substate())
|
||||||
yield nagiosplugin.Metric('service_state', self.service_state)
|
yield nagiosplugin.Metric('service_state', self.service_state)
|
||||||
|
|
||||||
|
class Service_Context(nagiosplugin.Context):
|
||||||
|
|
||||||
|
def evaluate(self, metric, recource):
|
||||||
|
# possible Values are:
|
||||||
|
# nagiosplugin.Ok, nagiosplugin.Warn, nagiosplugin.Critical, nagiosplugin.Unknown
|
||||||
|
resultD = collections.defaultdict( lambda: nagiosplugin.Unknown, {
|
||||||
|
'active': nagiosplugin.Ok,
|
||||||
|
'reloading': nagiosplugin.Ok,
|
||||||
|
'activating': nagiosplugin.Ok,
|
||||||
|
'deactivating': nagiosplugin.Warn,
|
||||||
|
'inactive': nagiosplugin.Critical,
|
||||||
|
'failed': nagiosplugin.Critical,
|
||||||
|
})
|
||||||
|
return self.result_cls(resultD[metric.value[0]], metric=metric)
|
||||||
|
|
||||||
|
|
||||||
@nagiosplugin.guarded
|
@nagiosplugin.guarded
|
||||||
@ -136,10 +150,7 @@ def main():
|
|||||||
_log.debug('Found arguments %r', args)
|
_log.debug('Found arguments %r', args)
|
||||||
check = nagiosplugin.Check(
|
check = nagiosplugin.Check(
|
||||||
Systemd_Service(**vars(args)),
|
Systemd_Service(**vars(args)),
|
||||||
nagiosplugin.Context('service_state',
|
Service_Context('service_state', fmt_metric="ServiceState is {value[0]}({value[1]})")
|
||||||
fmt_metric=Service_Fmt_Metric('Service is running. State is {v[0]}, {v[1]}',
|
|
||||||
'Service is broken! State is {v[0]}, {v[1]}')
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
check.main(args.verbose, args.timeout)
|
check.main(args.verbose, args.timeout)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user