From 11a16bb362650f3e5e812059572ddce3dcc0eaa1 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Tue, 29 Dec 2015 22:17:59 +0100 Subject: [PATCH 1/3] 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. --- changes.md | 5 +++++ check_xmppng | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/changes.md b/changes.md index 5e8e111..c60d713 100644 --- a/changes.md +++ b/changes.md @@ -1,5 +1,10 @@ # 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 * first icinga exchange release diff --git a/check_xmppng b/check_xmppng index 59d0efa..661b36a 100755 --- a/check_xmppng +++ b/check_xmppng @@ -31,7 +31,7 @@ from defusedxml.sax import make_parser import nagiosplugin __author__ = "Jan Dittberner" -__version__ = "0.1.2" +__version__ = "0.2.dev1" NS_IETF_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl' @@ -418,6 +418,7 @@ class Xmpp(nagiosplugin.Resource): except socket.gaierror as e: self.state = nagiosplugin.Critical self.cause = str(e) + _LOG.debug("got an gaierror %s", e) return nagiosplugin.Metric("time", "unknown") except XmppException as e: self.state = nagiosplugin.Critical @@ -455,23 +456,32 @@ class DaysValidContext(nagiosplugin.Context): Context for checking the certificate expiry date. """ + fmt_hint = "less than {value} days" def __init__( 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) self.warning = nagiosplugin.Range('@%d:' % warndays) self.critical = nagiosplugin.Range('@%d:' % critdays) + self.warndays = warndays + self.critdays = critdays def evaluate(self, metric, resource): if resource.checkcerts and metric.value is not None: - hint = self.describe(metric) 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): - return nagiosplugin.Result(nagiosplugin.Warn, hint, metric) - return nagiosplugin.Result(nagiosplugin.Ok, hint, metric) + return nagiosplugin.Result( + nagiosplugin.Warn, + hint=self.fmt_hint.format(value=self.warndays), + metric=metric) + return nagiosplugin.Result( + nagiosplugin.Ok, "", metric) return nagiosplugin.Result(nagiosplugin.Ok) def performance(self, metric, resource): @@ -480,6 +490,16 @@ class DaysValidContext(nagiosplugin.Context): 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 def main(): """ @@ -551,8 +571,10 @@ def main(): ] check = nagiosplugin.Check( Xmpp(**kwargs), - XmppContext('time', warning, critical), - DaysValidContext('daysleft', warndays, critdays) + XmppContext( + 'time', warning, critical, fmt_metric="request took {value}{uom}"), + DaysValidContext('daysleft', warndays, critdays), + XmppSummary(), ) check.main(verbose=verbose, timeout=0) From 37351a87a04241f076fbc3e4773f039ac87a3a9e Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Tue, 29 Dec 2015 22:25:03 +0100 Subject: [PATCH 2/3] Finalize version number --- changes.md | 2 +- check_xmppng | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changes.md b/changes.md index c60d713..fb8ed8f 100644 --- a/changes.md +++ b/changes.md @@ -1,6 +1,6 @@ # change log -## version 0.2 yyyy-mm-dd +## version 0.2 2015-12-29 * improve human readable output by returning both response time as well as certificate expiry diff --git a/check_xmppng b/check_xmppng index 661b36a..da46d7a 100755 --- a/check_xmppng +++ b/check_xmppng @@ -31,7 +31,7 @@ from defusedxml.sax import make_parser import nagiosplugin __author__ = "Jan Dittberner" -__version__ = "0.2.dev1" +__version__ = "0.2" NS_IETF_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl' From f8e1a0eb3827311fd900fe35a11bfa7fc64f6923 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Tue, 29 Dec 2015 22:25:30 +0100 Subject: [PATCH 3/3] Add new release to icingaexchange.yml --- icingaexchange.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/icingaexchange.yml b/icingaexchange.yml index eb11202..bee5230 100644 --- a/icingaexchange.yml +++ b/icingaexchange.yml @@ -7,6 +7,29 @@ target: Messaging type: Plugin license: gplv3 releases: + - name: 0.2 + description: "better human readable output" + files: + - + name: check_xmppng + url: "file:///check_xmppng" + description: "Check command" + checksum: 7369095c7daad89e04e0fbdd81ef0e00 + - + name: COPYING + url: "file:///COPYING" + description: "GPL 3.0 license text" + checksum: d32239bcb673463ab874e80d47fae504 + - + name: README.md + url: "file:///README.md" + description: "documentation" + checksum: 1e6f6632b12e4ef5fc4f02c3ea65da8a + - + name: changes.md + url: "file:///changes.md" + description: "change log" + checksum: f09a79d4762efc8c5a97e6d9f301b398 - name: 0.1.2 description: "first icingaexchange release"