From 0277cb5da4f3fcc963e3a410d6ac7efb9f20fb19 Mon Sep 17 00:00:00 2001 From: Antoine Durand-Gasselin Date: Mon, 17 Aug 2009 11:23:29 +0200 Subject: [PATCH] [monit/services] python plus lisible darcs-hash:20090817092329-bd074-0128bb6a3cd830e7eda4c097943966b251bf7b13.gz --- Python/etc/monit/services | 42 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Python/etc/monit/services b/Python/etc/monit/services index 85fe1e7..0956a49 100644 --- a/Python/etc/monit/services +++ b/Python/etc/monit/services @@ -1,6 +1,6 @@ # -*- coding: utf-8; mode: python -*- -import sre +import re include("ip") @@ -10,26 +10,28 @@ info["perms"] = 0644 header() import sys -def service(group, - name=None, - init=None, - pidf=None, - pidp=None, - extra=[], - max_restart=5): +def service(group, **kw): + """Permet de définir un service monit. + + Les arguments supplémentaires peuvent être: + name (par défault le nom du groupe) + init (le nom du script de démarrage dans /etc/init.d, (par défaut name)) + pidp (le nom du fichier de pid (par défaut /var/run/.pid)) + extra (des lignes supplémentaires)""" + if group == None or has(group): - name = name or group - init = init or name - pidf = pidf or name - pidp = pidp or "/var/run/%s.pid" % pidf + name = kw.get('name', group) + init = kw.get('init', name) + pidp = kw.get('pidp', "/var/run/%s.pid" % kw.get('pidf', name)) + start_cmd = kw.get('start_cmd', '/etc/init.d/%s start' % init) + stop_cmd = kw.get('stop_cmd', '/etc/init.d/%s stop' % init) print ('''# %(name)s check process %(name)s with pidfile %(pidp)s - start program = "/etc/init.d/%(init)s start" - stop program = "/etc/init.d/%(init)s stop"''' % - { "name": name, - "pidp": pidp, - "init": init }) - for line in extra: + start program = "%(start_cmd)" + stop program = "%(stop_cmd)"''' % locals()) + + max_restart = kw.get('max_restart', 5) + for line in kw.get('extra', []): if line: print " ", line print " if %d restarts within 5 cycles then timeout" % max_restart @@ -182,7 +184,7 @@ for i in range(0,dernierecarte): name = "mumudvb%d" % i, init = "mumudvb", pidf = "mumudvb/mumudvb_carte%d" % i) - + @check file file/var/log/syslog with path /var/log/syslog @ if timestamp > 15 minutes then alert @ @@ -202,7 +204,7 @@ for line in metadata.Probes["fstab_local"].splitlines(): continue # on découpe la ligne - [fs, mntpoint, type, options, dump, pass_] = sre.split('[ \t]*',line) + [fs, mntpoint, type, options, dump, pass_] = re.split('[ \t]*',line) options = options.split(",") # on saute si c'est une partition non montée au démarrage