feat: Add check_ping

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2023-09-21 19:58:26 +02:00
parent 2ced5e5a40
commit 234c6c46db
No known key found for this signature in database
GPG key ID: A2EB1F2CA8E3F677
5 changed files with 127 additions and 2 deletions

View file

@ -1,6 +1,30 @@
import logging
import os
from nagiosplugin import Context
from nagiosplugin.state import Critical, Ok, Unknown, Warn
class BooleanContext(Context):
def __init__(self, name, expected=True, warning=False, critical=False):
super().__init__(name)
self.expected = expected
self.warning = warning
self.critical = critical
def evaluate(self, metric, resource):
if not metric.value is self.expected:
result_type = Ok
if self.critical:
result_type = Critical
elif self.warning:
result_type = Warn
return self.result_cls(
result_type, f"{metric.name} is not {self.expected}", metric
)
else:
return self.result_cls(Ok, None, metric)
def show_version():
with open(