From 2f616834be2e6e104c9cd108e08030b2b4be68da Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 7 Jun 2013 14:35:28 +0200 Subject: debian: debianization --- .gitignore | 1 + Makefile | 13 ++++ debian/.gitignore | 2 + debian/changelog | 30 +++++++++ debian/compat | 1 + debian/control | 18 ++++++ debian/copyright | 26 ++++++++ debian/cron.d | 3 + debian/rules | 5 ++ missing-maintainer-keys | 156 --------------------------------------------- missing-maintainer-keys.in | 155 ++++++++++++++++++++++++++++++++++++++++++++ version.py | 42 ------------ 12 files changed, 254 insertions(+), 198 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 debian/.gitignore create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/cron.d create mode 100755 debian/rules delete mode 100755 missing-maintainer-keys create mode 100755 missing-maintainer-keys.in delete mode 100644 version.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8d8004 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +missing-maintainer-keys diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a178da3 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +#!/usr/bin/make -f + +VERSION=$(shell dpkg-parsechangelog | sed -n 's/^Version: //p') + +all: + cp -a missing-maintainer-keys.in missing-maintainer-keys + sed -i 's/__VERSION__/$(VERSION)/' missing-maintainer-keys + +clean: + $(RM) missing-maintainer-keys + +install: + install -D missing-maintainer-keys $(DESTDIR)/usr/lib/nagios/plugins/missing-maintainer-keys diff --git a/debian/.gitignore b/debian/.gitignore new file mode 100644 index 0000000..b72a3db --- /dev/null +++ b/debian/.gitignore @@ -0,0 +1,2 @@ +nagios-plugins-hostinfo-maintainer* +files diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..e51b26a --- /dev/null +++ b/debian/changelog @@ -0,0 +1,30 @@ +hostinfo-maintainer (0.1.5) UNRELEASED; urgency=low + + * missing-maintainer-keys: fix handling of None value for maintainers + + -- Alexander Sulfrian Tue, 13 Aug 2013 20:24:07 +0200 + +hostinfo-maintainer (0.1.4) UNRELEASED; urgency=low + + * missing-maintainer-keys: allow extended maintainers + + -- Alexander Sulfrian Tue, 13 Aug 2013 19:59:21 +0200 + +hostinfo-maintainer (0.1.3) UNRELEASED; urgency=low + + * version: show if working copy is dirty + * missing-maintainer-keys: add maintainer count to output + + -- Alexander Sulfrian Mon, 10 Jun 2013 20:45:37 +0200 + +hostinfo-maintainer (0.1.2-2) UNRELEASED; urgency=low + + * debain/cron.d: set the required PATH + + -- Alexander Sulfrian Fri, 07 Jun 2013 16:36:19 +0200 + +hostinfo-maintainer (0.1.2) unstable; urgency=low + + * Initial release. + + -- Alexander Sulfrian Mon, 06 May 2013 17:31:41 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..d681380 --- /dev/null +++ b/debian/control @@ -0,0 +1,18 @@ +Source: hostinfo-maintainer +Section: net +Priority: extra +Maintainer: Alexander Sulfrian +Build-Depends: debhelper (>= 7.0.50~), python-all (>= 2.6.6-3~), + python-all (<< 3), dpkg-dev +Standards-Version: 3.9.1 +Homepage: http://git.spline.inf.fu-berlin.de/hostinfo-maintainer/ +Vcs-Git: git://git.spline.inf.fu-berlin.de/hostinfo-maintainer +X-Python-Version: >= 2.6, << 3.0 + +Package: nagios-plugins-hostinfo-maintainer +Architecture: all +Depends: ${python:Depends}, ${misc:Depends}, python-yaml, python-nagiosplugin, + nsca-ng-client | nsca-client +Description: nagios checks for maintainer information in hostinfo database + With this nagios checks you could run different checks concering + the maintainer information stored in the hostinfo database. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..7489c23 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,26 @@ +This work was packaged for Debian by: + + Alexander Sulfrian on Mon, 06 May 2013 17:30:15 +0200 + +It was downloaded from: + + http://git.spline.inf.fu-berlin.de/hostinfo-maintainer/ + +Upstream Author(s): + + Alexander Sulfrian + +Copyright: + + Copyright (C) 2013 Alexander Sulfrian + +License: + + as-is + +The Debian packaging is: + + Copyright (C) 2013 Alexander Sulfrian + +and is licensed under the GPL version 3, +see "/usr/share/common-licenses/GPL-3". diff --git a/debian/cron.d b/debian/cron.d new file mode 100644 index 0000000..f8f92f3 --- /dev/null +++ b/debian/cron.d @@ -0,0 +1,3 @@ +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin + +*/1 * * * * nobody invoke_check /usr/lib/nagios/plugins/missing-maintainer-keys diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..abde6ef --- /dev/null +++ b/debian/rules @@ -0,0 +1,5 @@ +#!/usr/bin/make -f + +%: + dh $@ + diff --git a/missing-maintainer-keys b/missing-maintainer-keys deleted file mode 100755 index 988e4c0..0000000 --- a/missing-maintainer-keys +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/env python - -""" -This script checks, if for each maintainer (defined in the hostinfo data) -a public ssh key is available in the bcfg2 repository. -""" - -import os -import sys -import yaml -import argparse -import logging -import nagiosplugin - -class MissingMaintainerKeys(nagiosplugin.Resource): - def __init__(self, hostinfo, repo): - self.hostinfo = hostinfo - self.repo = repo - - @property - def name(self): - return "missing_maintainer_keys" - - def _get_all_hosts(self): - hosts = list() - hosts_path = os.path.join(self.hostinfo, 'metadata', 'hosts') - with open(hosts_path) as hosts_file: - hostlist = yaml.load(hosts_file) - hosts = hostlist['hosts'] - return hosts - - def _get_all_maintainers(self, hosts): - maintainers = set() - for host in hosts: - data = dict() - with open(os.path.join(self.hostinfo, host)) as host_file: - data = yaml.load(host_file) - - if 'maintainers' in data and data['maintainers'] is not None: - for maintainer in data['maintainers']: - if type(maintainer) is dict: - maintainers |= set(maintainer.values()) - else: - maintainers |= set([maintainer]) - return maintainers - - 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: - keyfile = os.path.join(self.repo, 'SSHKeys', maintainer + '.pub') - if not os.path.exists(keyfile): - errors.append(maintainer) - - yield nagiosplugin.Metric('missing', errors, context='missing') - -class MissingMaintainerKeysContext(nagiosplugin.Context): - def __init__(self, name, result_cls=nagiosplugin.Result): - super(MissingMaintainerKeysContext, self).__init__( - name, - result_cls=result_cls) - - def describe(self, metric): - if len(metric.value) > 0: - return ("missing keys: %s" % ', '.join(metric.value)) - - return "all keys available" - - def evaluate(self, metric, resource): - if len(metric.value) > 0: - 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='missing', - value=len(metric.value), - 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]) - print("%s %s" % (self, version.get_git_version())) - sys.exit(nagiosplugin.Unknown.code) - -@nagiosplugin.guarded -def main(): - basepath = '/usr/local/share/hostinfo' - repopath = '/var/lib/bcfg2/' - if 'HOSTINFO_PATH' in os.environ and os.environ['HOSTINFO_PATH'] != '': - basepath = os.environ['HOSTINFO_PATH'] - - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument("-p", "--path", default=basepath, - help="set the path to the hostinfo data") - parser.add_argument("-r", "--repo", default=repopath, - help="set the path to the bcfg2 repo") - parser.add_argument("-V", "--version", action="store_true", - help="only print the version number and exit") - parser.add_argument("-v", "--verbose", action="count", default=0, - help="increase output verbosity (use up to 3 times)") - args = parser.parse_args() - - if args.version: - print_version() - - if not os.path.exists(args.path): - raise Exception("hostinfo data not found in '%s'" % args.path) - - if not os.path.exists(args.repo): - raise Exception("bcfg2 repo not found in '%s'" % args.repo) - - check = nagiosplugin.Check( - MissingMaintainerKeys(args.path, args.repo), - MaintainersContext('count'), - MissingMaintainerKeysContext('missing')) - check.main(verbose=args.verbose) - -if __name__ == '__main__': - main() diff --git a/missing-maintainer-keys.in b/missing-maintainer-keys.in new file mode 100755 index 0000000..594b20d --- /dev/null +++ b/missing-maintainer-keys.in @@ -0,0 +1,155 @@ +#!/usr/bin/env python + +""" +This script checks, if for each maintainer (defined in the hostinfo data) +a public ssh key is available in the bcfg2 repository. +""" + +import os +import sys +import yaml +import argparse +import logging +import nagiosplugin + +class MissingMaintainerKeys(nagiosplugin.Resource): + def __init__(self, hostinfo, repo): + self.hostinfo = hostinfo + self.repo = repo + + @property + def name(self): + return "missing_maintainer_keys" + + def _get_all_hosts(self): + hosts = list() + hosts_path = os.path.join(self.hostinfo, 'metadata', 'hosts') + with open(hosts_path) as hosts_file: + hostlist = yaml.load(hosts_file) + hosts = hostlist['hosts'] + return hosts + + def _get_all_maintainers(self, hosts): + maintainers = set() + for host in hosts: + data = dict() + with open(os.path.join(self.hostinfo, host)) as host_file: + data = yaml.load(host_file) + + if 'maintainers' in data and data['maintainers'] is not None: + for maintainer in data['maintainers']: + if type(maintainer) is dict: + maintainers |= set(maintainer.values()) + else: + maintainers |= set([maintainer]) + return maintainers + + 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: + keyfile = os.path.join(self.repo, 'SSHKeys', maintainer + '.pub') + if not os.path.exists(keyfile): + errors.append(maintainer) + + yield nagiosplugin.Metric('missing', errors, context='missing') + +class MissingMaintainerKeysContext(nagiosplugin.Context): + def __init__(self, name, result_cls=nagiosplugin.Result): + super(MissingMaintainerKeysContext, self).__init__( + name, + result_cls=result_cls) + + def describe(self, metric): + if len(metric.value) > 0: + return ("missing keys: %s" % ', '.join(metric.value)) + + return "all keys available" + + def evaluate(self, metric, resource): + if len(metric.value) > 0: + 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='missing', + value=len(metric.value), + 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(): + self = os.path.basename(sys.argv[0]) + print("%s __VERSION__" % self) + sys.exit(nagiosplugin.Unknown.code) + +@nagiosplugin.guarded +def main(): + basepath = '/usr/local/share/hostinfo' + repopath = '/var/lib/bcfg2/' + if 'HOSTINFO_PATH' in os.environ and os.environ['HOSTINFO_PATH'] != '': + basepath = os.environ['HOSTINFO_PATH'] + + parser = argparse.ArgumentParser( + description=__doc__, + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument("-p", "--path", default=basepath, + help="set the path to the hostinfo data") + parser.add_argument("-r", "--repo", default=repopath, + help="set the path to the bcfg2 repo") + parser.add_argument("-V", "--version", action="store_true", + help="only print the version number and exit") + parser.add_argument("-v", "--verbose", action="count", default=0, + help="increase output verbosity (use up to 3 times)") + args = parser.parse_args() + + if args.version: + print_version() + + if not os.path.exists(args.path): + raise Exception("hostinfo data not found in '%s'" % args.path) + + if not os.path.exists(args.repo): + raise Exception("bcfg2 repo not found in '%s'" % args.repo) + + check = nagiosplugin.Check( + MissingMaintainerKeys(args.path, args.repo), + MaintainersContext('count'), + MissingMaintainerKeysContext('missing')) + check.main(verbose=args.verbose) + +if __name__ == '__main__': + main() diff --git a/version.py b/version.py deleted file mode 100644 index 498ce51..0000000 --- a/version.py +++ /dev/null @@ -1,42 +0,0 @@ -# -*- coding: utf-8 -*- -# To use this script, simply import it your setup.py file, and use the -# results of get_git_version() as your package version: -# -# from version import * -# -# setup( -# version=get_git_version(), -# . -# . -# . -# ) - -__all__ = ["get_git_version"] - -import os -import re -from subprocess import Popen, PIPE - -OWN_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) - -def call_git_describe(abbrev=4): - try: - p = Popen(['git', 'describe', '--abbrev=%d' % abbrev, - '--tags', '--dirty'], - cwd=OWN_DIR, stdout=PIPE, stderr=PIPE) - p.stderr.close() - line = p.stdout.readlines()[0] - return line.strip() - - except: - return None - -def get_git_version(abbrev=4): - version = call_git_describe(abbrev) - if version is None: - raise ValueError("Cannot find the version number!") - - return re.sub('^debian/', '', version) - -if __name__ == "__main__": - print get_git_version() -- cgit v1.2.3-1-g7c22