# -*- encoding: utf-8 -*- info["owner"] = "root" info["group"] = "root" info["mode"] = 0644 header() include('ip') def has_shared_scripts(client): """Est-ce que `client` a /usr/scripts en nfs ?""" return ('external' not in client.groups) and ( ('nfs' in client.groups) or ('crans-nfs' in client.groups)) cron_tpl_nfs = "* * * * * root " + \ "%(monit_path)s status > %(status_path)s/%(host)s 2> /dev/null" # On reproduit le même comportement en non-nfs: pas de màj du fichier de # status si injoinable cron_tpl_nonfs = "* * * * * root " + \ "( /usr/bin/wget --config=/etc/crans/wgetrc_monit " +\ "http://%(host)s.adm.crans.org:2812/_status -O /tmp/%(host)s.status && " +\ "test -f /tmp/%(host)s.status && " +\ "mv /tmp/%(host)s.status %(status_path)s/%(host)s )" data = { 'host': hostname, 'status_path': '/usr/scripts/var/monit/status', 'monit_path': '/usr/bin/monit', } # Si ce serveur possède un nfs, on génère le cron qui écrit dedans if has_shared_scripts(metadata): comment("Copie de `monit status` sur le nfs") out(cron_tpl_nfs % data) # Pour les autres serveurs, c'est le serveur autostatus qui récupère if has('autostatus'): comment("Seveurs ne possedant pas de nfs :") for client in metadata.query.all(): if not has_shared_scripts(client): data['host'] = client.hostname.split('.', 1)[0] out(cron_tpl_nonfs % data)