dbut de conf pour nectaris

darcs-hash:20051008130805-4ec08-33275a41d98650e0453bfaa3a90204b9db384aa3.gz
This commit is contained in:
chove 2005-10-08 15:08:05 +02:00
parent 91d635da5a
commit 1ea8baa225

View file

@ -1,22 +1,18 @@
#! /usr/bin/env python
# -*- coding:iso-8859-15 -*-
"""
ToDo :
------
Revoir les scripts pour nut/upsmonitor
Ajouter les ports tcp/udp quand il y en a
"""
debug = 0
import sre
import sys, os
# on récupère le hostname
if debug : print 'DEBUG : Lecture de l\'hote'
host = open('/etc/hostname').readline().strip()
# est ce que c'est un systeme bsd
if host in ['nectaris'] :
bsd = True
else :
bsd = False
# fonctions utiles
##################
@ -160,9 +156,23 @@ def file_monitrc(hostname = host) :
config += ' if 3 restarts within 5 cycles then timeout\n'
config += '\n'
# apache sur nectaris
if hostname in ['nectaris'] :
config += '# apache\n'
config += 'check process apache with pidfile /var/www/logs/httpd.pid\n'
config += ' start program = "/usr/sbin/apachectl start"\n'
config += ' stop program = "/usr/sbin/apachectl stop"\n'
config += ' if failed host localhost port 80 protocol http %s then restart\n' % timeout
config += ' if failed host localhost port 443 type tcpssl protocol http %s then restart\n' % timeout
config += ' if cpu is greater than 60% for 2 cycles then alert\n'
config += ' if cpu > 80% for 5 cycles then restart\n'
config += ' if children > 100 then restart\n'
config += ' if loadavg(5min) greater than 10 for 8 cycles then restart\n'
config += ' if 3 restarts within 5 cycles then timeout\n'
config += '\n'
# at
if True :
if not bsd :
config += '# at\n'
config += 'check process at with pidfile /var/run/atd.pid\n'
config += ' start program = "/etc/init.d/atd start"\n'
@ -179,6 +189,23 @@ def file_monitrc(hostname = host) :
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# bind
if hostname in ['nectaris'] and False :
config += '# bind\n'
config += 'check process bind with pidfile /var/run/named.pid\n'
config += ' start program = "???"\n'
config += ' stop program = "/bin/kill `cat /var/run/named.pid`"\n'
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
if hostname in ['rouge','sila','ultra-adsl'] :
config += '# bind\n'
config += 'check process bind with pidfile /var/run/bind/run/named.pid\n'
config += ' start program = "/etc/init.d/bind9 start"\n'
config += ' stop program = "/etc/init.d/bind9 stop"\n'
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# cups
if hostname in ['zamok'] :
config += '# cups\n'
@ -189,15 +216,25 @@ def file_monitrc(hostname = host) :
config += '\n'
# cron
if True :
if bsd :
config += '# cron\n'
config += 'check process cron with pidfile /var/run/cron.pid\n'
config += ' start program = "/usr/sbin/cron"\n'
config += ' stop program = "/bin/kill `cat /var/run/cron.pid`"\n'
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
else :
config += '# cron\n'
config += 'check process cron with pidfile /var/run/crond.pid\n'
config += ' start program = "/etc/init.d/cron start"\n'
config += ' stop program = "/etc/init.d/cron stop"\n'
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# dhcp
if hostname in ['nectaris'] :
pass
# freeradius
if hostname in ['zamok','pegase'] :
config += '# freeradius\n'
@ -216,6 +253,15 @@ def file_monitrc(hostname = host) :
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# isakmpd
if hostname in ['nectaris'] :
config += '# isakmpd\n'
config += 'check process isakmpd with pidfile /var/run/isakmpd.pid\n'
config += ' start program = "/sbin/isakmpd -d"\n'
config += ' stop program = "/bin/kill `cat /var/run/isakmpd.pid`"\n'
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# mailman
if hostname in ['rouge'] :
config += '# mailman\n'
@ -226,7 +272,7 @@ def file_monitrc(hostname = host) :
config += '\n'
# munin-node
if True :
if not bsd :
config += '# munin-node\n'
config += 'check process munin-node with pidfile /var/run/munin/munin-node.pid\n'
config += ' start program = "/etc/init.d/munin-node start"\n'
@ -244,7 +290,7 @@ def file_monitrc(hostname = host) :
config += '\n'
# nscd
if True :
if not bsd :
config += '# nscd\n'
config += 'check process nscd with pidfile /var/run/nscd.pid\n'
config += ' start program = "/etc/init.d/nscd start"\n'
@ -272,7 +318,7 @@ def file_monitrc(hostname = host) :
config += '\n'
# postfix
if True :
if not bsd :
config += '# postfix\n'
config += 'check process postfix with pidfile /var/spool/postfix/pid/master.pid\n'
config += ' start program = "/etc/init.d/postfix start"\n'
@ -312,6 +358,16 @@ def file_monitrc(hostname = host) :
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# rsync
if hostname in ['nectaris'] and False :
config += '# rsyncd\n'
config += 'check process rsyncd with pidfile /var/run/rsyncd.pid\n'
config += ' start program = "???"\n'
config += ' stop program = "/bin/kill `cat /var/run/rsyncd.pid`"\n'
config += ' if failed port 873 %s then restart\n' % timeout
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# slapd
if hostname in ['pegase','sila','vert'] :
config += '# slapd\n'
@ -340,18 +396,18 @@ def file_monitrc(hostname = host) :
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# squid
#if hostname in ['sila'] :
# config += '# squid\n'
# config += 'check process squid with pidfile /var/run/squid.pid\n'
# config += ' start program = "/etc/init.d/squid start"\n'
# config += ' stop program = "/etc/init.d/squid stop"\n'
# config += ' if failed host %s.crans.org port 3128 then restart\n' % hostname
# config += ' if 5 restarts within 15 cycles then timeout\n'
# config += '\n'
# squid / redémare tout le temps
if False :
config += '# squid\n'
config += 'check process squid with pidfile /var/run/squid.pid\n'
config += ' start program = "/etc/init.d/squid start"\n'
config += ' stop program = "/etc/init.d/squid stop"\n'
config += ' if failed host %s.crans.org port 3128 then restart\n' % hostname
config += ' if 5 restarts within 15 cycles then timeout\n'
config += '\n'
# ssh
if True :
if not bsd :
config += '# ssh\n'
config += 'check process ssh with pidfile /var/run/sshd.pid\n'
config += ' start program = "/etc/init.d/ssh start"\n'
@ -360,8 +416,17 @@ def file_monitrc(hostname = host) :
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# syslog
if bsd :
config += '# syslog\n'
config += 'check process syslog with pidfile /var/run/syslog.pid\n'
config += ' start program = "/usr/local/bin/rsync --daemon --config /etc/rsyncd.conf"\n'
config += ' stop program = "/bin/kill `cat /var/run/syslog.pid`"\n'
config += ' if 5 restarts within 5 cycles then timeout\n'
config += '\n'
# syslog-ng
if hostname not in ['ultra-adsl'] :
if hostname not in ['ultra-adsl'] and not bsd :
config += '# syslog-ng\n'
config += 'check process syslog-ng with pidfile /var/run/syslog-ng.pid\n'
config += ' start program = "/etc/init.d/syslog-ng start"\n'
@ -404,10 +469,6 @@ def file_monitrc(hostname = host) :
return config
if debug : print 'DEBUG : Fin de la création de la fonction file_monitrc'
if debug : print 'DEBUG : Création de la fonction file_default'
def file_default (hostname = host) :
config = '# Configuration de monit sur %s\n' % hostname
config += '# généré par monit.py\n'
@ -420,47 +481,38 @@ def file_default (hostname = host) :
return config
if debug : print 'DEBUG : Fin de la création de la fonction file_default'
# corps du programme
####################
# vérification de l'uid
#if debug : 'DEBUG : Vérification de l\'uid'
if os.getuid() :
print 'Il faut être root !'
sys.exit(1)
if len(sys.argv) <= 1 :
commit = 'Mise à jour'
else :
commit = sys.argv[1]
# le fichier de cron
f = open('/etc/cron.d/monit','w')
f.write('* * * * * root /usr/sbin/monit status > /usr/scripts/monit/status/%s\n' % host)
f.close()
if bsd :
print "Système bsd, crontab non mis à jour"
else :
f = open('/etc/cron.d/monit','w')
f.write('* * * * * root /usr/sbin/monit status > /usr/scripts/monit/status/%s\n' % host)
f.close()
# génération du monitrc
if debug : print 'DEBUG : Ouverture de monitrc'
f = open('/etc/monit/monitrc','w')
if debug : print 'DEBUG : Ecriture de monitrc'
if bsd :
f = open('/etc/monitrc','w')
else :
f = open('/etc/monit/monitrc','w')
f.write(file_monitrc())
if debug : print 'DEBUG : Fermeture de monitrc'
f.close()
if debug : print 'DEBUG : Commit de monitrc'
#os.system('cvs commit -m "%s" /etc/monit/monitrc' % commit )
# génération du default
if debug : print 'DEBUG : Ouverture de default/monit'
f = open('/etc/default/monit','w')
if debug : print 'DEBUG : Ecriture de default/monit'
f.write(file_default())
if debug : print 'DEBUG : Fermeture de default/monit'
f.close()
if debug : print 'DEBUG : Commit de default/monit'
#os.system('cvs commit -m "%s" /etc/default/monit' % commit )
if not bsd :
f = open('/etc/default/monit','w')
f.write(file_default())
f.close()
os.system('/etc/init.d/monit restart')
if debug : print 'DEBUG : Sortie du programme'
# redémarage de monit
if bsd :
pass
else :
os.system('/etc/init.d/monit restart')