From 73bcb038cb1d628df8a7eee9dcd7f3cdfda8927b Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 10 Jun 2013 20:42:30 +0200 Subject: missing-maintainer-keys: add maintainer count to output --- missing-maintainer-keys | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/missing-maintainer-keys b/missing-maintainer-keys index c3f5967..4accd2e 100755 --- a/missing-maintainer-keys +++ b/missing-maintainer-keys @@ -35,7 +35,7 @@ class MissingMaintainerKeys(nagiosplugin.Resource): data = dict() with open(os.path.join(self.hostinfo, host)) as host_file: data = yaml.load(host_file) - + if 'maintainers' in data: maintainers |= set(data['maintainers']) return maintainers @@ -43,6 +43,7 @@ class MissingMaintainerKeys(nagiosplugin.Resource): def probe(self): hosts = self._get_all_hosts() maintainers = self._get_all_maintainers(hosts) + yield nagiosplugin.Metric('count', maintainers, context='count') errors = list() for maintainer in maintainers: @@ -79,6 +80,33 @@ class MissingMaintainerKeysContext(nagiosplugin.Context): crit="1", min="0") +class MaintainersContext(nagiosplugin.Context): + def __init__(self, name, result_cls=nagiosplugin.Result): + super(MaintainersContext, self).__init__( + name, + result_cls=result_cls) + + def describe(self, metric): + if len(metric.value) < 1: + return "no maintainer found" + if len(metric.value) == 1: + return "1 maintainer found" + return "%d maintainers found" % len(metric.value) + + def evaluate(self, metric, resource): + if len(metric.value) < 1: + return self.result_cls(nagiosplugin.Critical, + hint=self.describe(metric), metric=metric) + + return self.result_cls(nagiosplugin.Ok, + hint=self.describe(metric), metric=metric) + + def performance(self, metric, resource): + return nagiosplugin.Performance( + label='count', + value=len(metric.value), + min="0") + def print_version(): import version self = os.path.basename(sys.argv[0]) @@ -116,6 +144,7 @@ def main(): check = nagiosplugin.Check( MissingMaintainerKeys(args.path, args.repo), + MaintainersContext('count'), MissingMaintainerKeysContext('missing')) check.main(verbose=args.verbose) -- cgit v1.2.3-1-g7c22