Improve human readable output
This change introduces more readable and useful output by adding the certificate expiration to the human readable string. The response time is now formatted too.
This commit is contained in:
parent
7b1d482043
commit
11a16bb362
2 changed files with 35 additions and 8 deletions
|
@ -1,5 +1,10 @@
|
||||||
# change log
|
# change log
|
||||||
|
|
||||||
|
## version 0.2 yyyy-mm-dd
|
||||||
|
|
||||||
|
* improve human readable output by returning both response time as well as
|
||||||
|
certificate expiry
|
||||||
|
|
||||||
## version 0.1.2 2015-02-11
|
## version 0.1.2 2015-02-11
|
||||||
|
|
||||||
* first icinga exchange release
|
* first icinga exchange release
|
||||||
|
|
38
check_xmppng
38
check_xmppng
|
@ -31,7 +31,7 @@ from defusedxml.sax import make_parser
|
||||||
import nagiosplugin
|
import nagiosplugin
|
||||||
|
|
||||||
__author__ = "Jan Dittberner"
|
__author__ = "Jan Dittberner"
|
||||||
__version__ = "0.1.2"
|
__version__ = "0.2.dev1"
|
||||||
|
|
||||||
|
|
||||||
NS_IETF_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl'
|
NS_IETF_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl'
|
||||||
|
@ -418,6 +418,7 @@ class Xmpp(nagiosplugin.Resource):
|
||||||
except socket.gaierror as e:
|
except socket.gaierror as e:
|
||||||
self.state = nagiosplugin.Critical
|
self.state = nagiosplugin.Critical
|
||||||
self.cause = str(e)
|
self.cause = str(e)
|
||||||
|
_LOG.debug("got an gaierror %s", e)
|
||||||
return nagiosplugin.Metric("time", "unknown")
|
return nagiosplugin.Metric("time", "unknown")
|
||||||
except XmppException as e:
|
except XmppException as e:
|
||||||
self.state = nagiosplugin.Critical
|
self.state = nagiosplugin.Critical
|
||||||
|
@ -455,23 +456,32 @@ class DaysValidContext(nagiosplugin.Context):
|
||||||
Context for checking the certificate expiry date.
|
Context for checking the certificate expiry date.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
fmt_hint = "less than {value} days"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, name, warndays=0, critdays=0,
|
self, name, warndays=0, critdays=0,
|
||||||
fmt_metric='certificate expires in {value} days'
|
fmt_metric='certificate valid for {value} days'
|
||||||
):
|
):
|
||||||
super(DaysValidContext, self).__init__(name, fmt_metric=fmt_metric)
|
super(DaysValidContext, self).__init__(name, fmt_metric=fmt_metric)
|
||||||
self.warning = nagiosplugin.Range('@%d:' % warndays)
|
self.warning = nagiosplugin.Range('@%d:' % warndays)
|
||||||
self.critical = nagiosplugin.Range('@%d:' % critdays)
|
self.critical = nagiosplugin.Range('@%d:' % critdays)
|
||||||
|
self.warndays = warndays
|
||||||
|
self.critdays = critdays
|
||||||
|
|
||||||
def evaluate(self, metric, resource):
|
def evaluate(self, metric, resource):
|
||||||
if resource.checkcerts and metric.value is not None:
|
if resource.checkcerts and metric.value is not None:
|
||||||
hint = self.describe(metric)
|
|
||||||
if self.critical.match(metric.value):
|
if self.critical.match(metric.value):
|
||||||
return nagiosplugin.Result(nagiosplugin.Critical, hint, metric)
|
return nagiosplugin.Result(
|
||||||
|
nagiosplugin.Critical,
|
||||||
|
hint=self.fmt_hint.format(value=self.critdays),
|
||||||
|
metric=metric)
|
||||||
if self.warning.match(metric.value):
|
if self.warning.match(metric.value):
|
||||||
return nagiosplugin.Result(nagiosplugin.Warn, hint, metric)
|
return nagiosplugin.Result(
|
||||||
return nagiosplugin.Result(nagiosplugin.Ok, hint, metric)
|
nagiosplugin.Warn,
|
||||||
|
hint=self.fmt_hint.format(value=self.warndays),
|
||||||
|
metric=metric)
|
||||||
|
return nagiosplugin.Result(
|
||||||
|
nagiosplugin.Ok, "", metric)
|
||||||
return nagiosplugin.Result(nagiosplugin.Ok)
|
return nagiosplugin.Result(nagiosplugin.Ok)
|
||||||
|
|
||||||
def performance(self, metric, resource):
|
def performance(self, metric, resource):
|
||||||
|
@ -480,6 +490,16 @@ class DaysValidContext(nagiosplugin.Context):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class XmppSummary(nagiosplugin.Summary):
|
||||||
|
"""
|
||||||
|
Summary instance that outputs all metrics if the check results are ok.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def ok(self, results):
|
||||||
|
return ", ".join([str(res) for res in results])
|
||||||
|
|
||||||
|
|
||||||
@nagiosplugin.guarded
|
@nagiosplugin.guarded
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
|
@ -551,8 +571,10 @@ def main():
|
||||||
]
|
]
|
||||||
check = nagiosplugin.Check(
|
check = nagiosplugin.Check(
|
||||||
Xmpp(**kwargs),
|
Xmpp(**kwargs),
|
||||||
XmppContext('time', warning, critical),
|
XmppContext(
|
||||||
DaysValidContext('daysleft', warndays, critdays)
|
'time', warning, critical, fmt_metric="request took {value}{uom}"),
|
||||||
|
DaysValidContext('daysleft', warndays, critdays),
|
||||||
|
XmppSummary(),
|
||||||
)
|
)
|
||||||
check.main(verbose=verbose, timeout=0)
|
check.main(verbose=verbose, timeout=0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue