Merge branch 'release/0.2'

* release/0.2:
  Add new release to icingaexchange.yml
  Finalize version number
  Improve human readable output
This commit is contained in:
Jan Dittberner 2015-12-29 22:27:02 +01:00
commit 3469355a4b
3 changed files with 58 additions and 8 deletions

View file

@ -1,5 +1,10 @@
# change log
## version 0.2 2015-12-29
* 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

View file

@ -31,7 +31,7 @@ from defusedxml.sax import make_parser
import nagiosplugin
__author__ = "Jan Dittberner"
__version__ = "0.1.2"
__version__ = "0.2"
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)

View file

@ -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"