From 67edc088e73a3417180aa1f68d732eadac217a13 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Sat, 28 Mar 2009 16:20:22 +0100 Subject: [PATCH] =?UTF-8?q?[munin/scripts]=20Am=C3=A9liorations=20diverses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore-this: caad836e0dfeafe6da1f30b6cf74ec63 darcs-hash:20090328152022-ffbb2-79e3736d738365780ba14d263f2cf83016164234.gz --- munin/scripts/hosts_plugins.py | 27 ++++++++----- munin/scripts/link_plugins.py | 74 ++++++++++++++++++++++++---------- 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/munin/scripts/hosts_plugins.py b/munin/scripts/hosts_plugins.py index ce4231e8..d2668c8f 100755 --- a/munin/scripts/hosts_plugins.py +++ b/munin/scripts/hosts_plugins.py @@ -4,7 +4,7 @@ # # Copyright © 2009 Nicolas Dandrimont # -# Licence: Domaine public (qui voudrait de ça de toute façon...) +# Licence: MIT import sys as _sys _sys.path.append("/usr/scripts/gestion") @@ -43,16 +43,13 @@ hosts_plugins = { "iptables_mangle": "iptables_", "iptables_nat": "iptables_", "machines": "machines", - "webalizer_dixans": "webalizer_", - "webalizer_install-party": "webalizer_", - "webalizer_news": "webalizer_", - "webalizer_trophee": "webalizer_", - "webalizer_webmail": "webalizer_", - "webalizer_wiki": "webalizer_", - "webalizer_www": "webalizer_", - "wiki_pages": "wiki_pages", - "wiki_themes": "wiki_themes", - "wiki_users": "wiki_users", + # "webalizer_dixans": "webalizer_", + # "webalizer_install-party": "webalizer_", + # "webalizer_news": "webalizer_", + # "webalizer_trophee": "webalizer_", + # "webalizer_webmail": "webalizer_", + # "webalizer_wiki": "webalizer_", + # "webalizer_www": "webalizer_", }, "komaz": { "iptables_filter": "iptables_", @@ -66,6 +63,14 @@ hosts_plugins = { "iptables_mangle": "iptables_", "iptables_nat": "iptales_", }, + "xmpp": { + "jabber": "jabeer", + }, + "niomniom": { + "wiki_pages": "wiki_pages", + "wiki_themes": "wiki_themes", + "wiki_users": "wiki_users", + }, "munin": { "audimat": "audimat", "batiments": "batiments", diff --git a/munin/scripts/link_plugins.py b/munin/scripts/link_plugins.py index 6e500040..96235c84 100755 --- a/munin/scripts/link_plugins.py +++ b/munin/scripts/link_plugins.py @@ -12,7 +12,9 @@ # Licence: MIT # +import optparse import os +import shutil import socket import subprocess import sys @@ -37,6 +39,9 @@ if sys.version_info < (2, 5): return True return False +def register_quirk(f): + QUIRKS.append(f) + def get_munin_plugins(): """Liste les plugins munin créés par le système @@ -102,10 +107,16 @@ def get_all_plugins(): return result -def link_all_plugins(directory, plugins): - """Lie tous les plugins du dictionnaire plugins dans le répertoire +def list_plugins(plugins, directory): + """Liste les plugins comme s'ils allaient être liés dans directory""" + for name, path in sorted(plugins.items()): + print os.path.join(directory, name), '->', path + +def link_plugins(plugins, directory): + """Lie les plugins dans le répertoire directory""" + for name, path in plugins.iteritems(): os.symlink(path, os.path.join(directory, name)) @@ -117,14 +128,14 @@ def add_plugin(plugin): plugins[plugin] = os.path.join(MUNIN_PATH, plugin) return f - -QUIRKS.append(add_plugin("uptime")) # Coucou MoSaN -QUIRKS.append(add_plugin("netstat")) +register_quirk(add_plugin("uptime")) # Coucou MoSaN +register_quirk(add_plugin("netstat")) # Hacks sales -def add_wicked_ifaces_if_no_ifaces(plugins): - """Ajoute les interfaces moisies (p.ex. `crans') aux plugins si - munin n'a pas trouvé d'interface""" +@register_quirk +def add_ifaces(plugins): + """Ajoute les interfaces à la liste des plugins si munin n'a pas + trouvé d'interface (ou si elles ont été filtrées)""" if not any(plugin.startswith('if_') for plugin in plugins): # Liste les interfaces configurées sur le système @@ -133,25 +144,46 @@ def add_wicked_ifaces_if_no_ifaces(plugins): try: interfaces_file = file('/etc/network/interfaces', 'r') for line in interfaces_file: - line = line.strip() + line = line.split() # Recherche d'une ligne type "iface eth0 inet static" - if line.startswith('iface'): - if line.endswith("static"): - interface_name = line.split()[1] - # on dégage les interfaces sur vlan spéciaux et aliasées - if not set('.:') & set(interface_name): - interfaces.append(interface_name) + if line and line[0] == 'iface' and line[-1] == 'static': + interface_name = line[1] + # on dégage les interfaces sur vlan spéciaux et + # aliasées (leur nom contient ':' ou '.') + if not set('.:') & set(interface_name): + interfaces.append(interface_name) finally: if interfaces_file is not None: interfaces_file.close() for interface in interfaces: - plugins['if_%s' % interface] = os.path.join(MUNIN_PATH, 'if_') + plugins['if_%s' % interface] = os.path.join(MUNIN_PATH,'if_') plugins['if_err_%s' % interface] = os.path.join(MUNIN_PATH, 'if_err_') -QUIRKS.append(add_wicked_ifaces_if_no_ifaces) - if __name__ == "__main__": - tmpdir = tempfile.mkdtemp() - print tmpdir - link_all_plugins(tmpdir, get_all_plugins()) + parser = optparse.OptionParser() + parser.add_option('-d', '--directory', + help = 'Write plugin symlinks to DIR', + metavar = 'DIR', + default = '/etc/munin/plugins' + ) + parser.add_option('-f', '--force', + action = 'store_true', + help = 'Remove destination directory' + ) + parser.add_option('-p', '--pretend', + action = 'store_true', + help = 'Do not actually make links' + ) + (options, args) = parser.parse_args() + + plugins = get_all_plugins() + + if options.pretend: + list_plugins(plugins, options.directory) + else: + if options.force: + shutil.rmtree(options.directory) + os.mkdir(options.directory) + link_plugins(plugins, options.directory) +