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