From a322862f8476f51bf515a963cae361838a8ac532 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Sun, 29 Mar 2009 21:18:17 +0200 Subject: [PATCH] =?UTF-8?q?[munin/scripts/hosts=5Fplugins.py]=20Cr=C3=A9at?= =?UTF-8?q?ion=20des=20lignes=20cron=20pour=20les=20plugins=20custom=20+?= =?UTF-8?q?=20factorisation=20des=20firewall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore-this: e0cdc6d5356b513e3f72048318f0670b darcs-hash:20090329191817-ffbb2-4efb0e46ff6f03dc515af9420637e0b6636ba04c.gz --- munin/scripts/hosts_plugins.py | 61 ++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/munin/scripts/hosts_plugins.py b/munin/scripts/hosts_plugins.py index d2668c8f..3ab57479 100755 --- a/munin/scripts/hosts_plugins.py +++ b/munin/scripts/hosts_plugins.py @@ -13,13 +13,24 @@ del _sys import annuaires import config -__all__ = ["hosts_plugins"] +__all__ = ["hosts_plugins", "munin_fw", "cron_plugins", "hosts_crons"] + +# Lignes cron correspondant aux plugins customs +cron_plugins = { + # plugin: (utilisateur, commande), + # %s est remplacé par le lien dans /etc/munin/plugins + "audimat": ("munin", "nice -n 14 %s generate 2> /dev/null"), + "batiments": ("munin", "nice -n 14 %s fichier 2> /dev/null"), + "stats-ip_": ("munin", "nice -n 14 %s fichier 2> /dev/null"), + "stats-ip": ("munin", "nice -n 14 %s fichier 2> /dev/null"), + "wiki_pages": ("www-data", "%s fichier > /dev/null"), + } + +# Hôtes pour lesquels le firewall est muninisé +munin_fw = sorted(["zamok", "rouge", "komaz", "sable"]) hosts_plugins = { "zamok": { - "iptables_filter": "iptables_", - "iptables_mangle": "iptables_", - "iptables_nat": "iptables_", "laserjet_car": "laserjet_", "laserjet_car-p": "laserjet_", "laserjet__etat": "laserjet__etat", @@ -39,9 +50,6 @@ hosts_plugins = { }, "rouge": { "amavis": "amavis", - "iptables_filter": "iptables_", - "iptables_mangle": "iptables_", - "iptables_nat": "iptables_", "machines": "machines", # "webalizer_dixans": "webalizer_", # "webalizer_install-party": "webalizer_", @@ -52,16 +60,10 @@ hosts_plugins = { # "webalizer_www": "webalizer_", }, "komaz": { - "iptables_filter": "iptables_", - "iptables_mangle": "iptables_", - "iptables_nat": "iptales_", "machines": "machines", }, "sable": { "blacklist": "blacklist", - "iptables_filter": "iptables_", - "iptables_mangle": "iptables_", - "iptables_nat": "iptales_", }, "xmpp": { "jabber": "jabeer", @@ -102,3 +104,36 @@ for switch in annuaires.all_switchs(): switch = switch[:switch.index('.')] switch = switch.replace('-', '_') hosts_plugins["munin"]["ping_%s.adm" % switch] = "ping_bat_" + +######### +# Muninisation des firewalls +# +for host in munin_fw: + hosts_plugins[host].update({ + "iptables_filter": "iptables_", + "iptables_mangle": "iptables_", + "iptables_nat": "iptables_", + }) + +# format de la ligne cron +CRON_FORMAT = "%s-%s/%s * * * * %s %s" +# fréquence +FREQ = 15 +# lignes cron par hôte +hosts_crons = {} +for host, plugins in hosts_plugins.items(): + minute = 1 + hosts_crons[host] = [] + for path, plugin in plugins.items(): + if plugin in cron_plugins: + path = "/etc/munin/plugins/" + path + user, line = cron_plugins[plugin] + hosts_crons[host].append(CRON_FORMAT % (minute, + 60 - FREQ + minute, + FREQ, + user, + line % path)) + minute = (minute + 4) % FREQ + + if not hosts_crons[host]: + del hosts_crons[host]