Factorisation

darcs-hash:20080210234700-41f88-99a8f3505fc5237de30899edea18e93207bef0f4.gz
This commit is contained in:
Jérémie Dimino 2008-02-11 00:47:00 +01:00
parent 08cd541ea1
commit 113b1222d0
2 changed files with 130 additions and 248 deletions

View file

@ -2,291 +2,163 @@
import sre
include("ip")
info["owner"] = "root"
info["group"] = "root"
info["perms"] = 0644
header()
import sys
def service(group,
name=None,
init=None,
pidf=None,
pidp=None,
extra=[],
max_restart=5):
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
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:
if line:
print " ", line
print " if %d restarts within 5 cycles then timeout" % max_restart
print
if has("apache"):
@# Apache2
@check process apache2 with pidfile /var/run/apache2.pid
@ start program = "/etc/init.d/apache2 start"
@ stop program = "/etc/init.d/apache2 stop"
if has("http-server"):
@ if failed host localhost port 80 protocol http timeout 30 seconds then restart
if has("intranet-server"):
@ if failed host intranet.crans.org port 443 type tcpssl protocol http timeout 30 seconds then restart
if has("https-server"):
@ if failed host localhost port 443 type tcpssl protocol http timeout 30 seconds then restart
@ if cpu is greater than 60% for 2 cycles then alert
@ if cpu > 80% for 5 cycles then restart
@ if totalmem > 500.0 MB for 5 cycles then restart
@ if children > 250 then restart
@ if loadavg(5min) greater than 10 for 8 cycles then restart
@ if 3 restarts within 5 cycles then timeout
@
service("apache",
name="apache2",
extra=[ has("http-server") and "if failed host localhost port 80 protocol http timeout 30 seconds then restart",
has("https-server") and "if failed host localhost port 443 type tcpssl protocol http timeout 30 seconds then restart",
has("intranet-server") and "if failed host intranet.crans.org port 443 type tcpssl protocol http timeout 30 seconds then restart",
"if cpu is greater than 60% for 2 cycles then alert",
"if cpu > 80% for 5 cycles then restart",
"if totalmem > 500.0 MB for 5 cycles then restart",
"if children > 250 then restart",
"if loadavg(5min) greater than 10 for 8 cycles then restart",
],
max_restart=3)
@# at
@check process at with pidfile /var/run/atd.pid
@ start program = "/etc/init.d/atd start"
@ stop program = "/etc/init.d/atd stop"
@ if 5 restarts within 5 cycles then timeout
@
service("at",
init="atd",
pidf="atd")
if has("cherrypy"):
@# intranet (CherryPy)
@check process intranet with pidfile /var/run/intranet.pid
@ start program = "/etc/init.d/intranet start"
@ stop program = "/etc/init.d/intranet stop"
@ if 5 restarts within 5 cycles then timeout
@
service("cherrypy",
name="intranet")
if has("backuppc-server"):
@# backuppc
@check process backuppc with pidfile /var/run/backuppc/BackupPC.pid
@ start program = "/etc/init.d/backuppc start"
@ stop program = "/etc/init.d/backuppc stop"
@ if 5 restarts within 5 cycles then timeout
@
service("backuppc-server",
name="backuppc",
pidf="backuppc/BackupPC")
if has("bind"):
@# Bind 9
@check process bind with pidfile /var/run/bind/run/named.pid
@ start program = "/etc/init.d/bind9 start"
@ stop program = "/etc/init.d/bind9 stop"
@ if 5 restarts within 5 cycles then timeout
@
service("bind",
init="bind9",
pidf="bind/run/named")
if has("cups"):
@# cups
@check process cups with pidfile /var/run/cups/cupsd.pid
@ start program = "/etc/init.d/cupsys start"
@ stop program = "/etc/init.d/cupsys stop"
@ if 5 restarts within 5 cycles then timeout
@
service("cups",
init="cupsys",
pidf="cups/cupsd")
@# cron
@check process cron with pidfile /var/run/crond.pid
@ start program = "/etc/init.d/cron start"
@ stop program = "/etc/init.d/cron stop"
@ if 5 restarts within 5 cycles then timeout
@
service("cron",
pidf="crond")
if has("firewall"):
@# netacct
@check process netacct with pidfile /var/run/nacctd.pid
@ start program = "/etc/init.d/net-acct start"
@ stop program = "/etc/init.d/net-acct stop"
@ if 5 restarts within 5 cycles then timeout
@
@# filtrage netacct
@check process filtrage_netacct with pidfile /var/run/filtrage_netacct.pid
@ start program = "/etc/init.d/filtrage_netacct start"
@ stop program = "/etc/init.d/filtrage_netacct stop"
@ if 5 restarts within 5 cycles then timeout
@
@# filtrage firewall
@check process filtrage_firewall with pidfile /var/run/filtrage_firewall.pid
@ start program = "/etc/init.d/filtrage_firewall start"
@ stop program = "/etc/init.d/filtrage_firewall stop"
@ if 5 restarts within 5 cycles then timeout
@
service(None,
name="netacct",
pidf="nacctd",
init="net-acct")
service(None,
name="filtrage_netacct")
service(None,
name="filtrage_firewall")
if has("dhcp-detect"):
@# dhcp-detect
@check process dhcp-detect with pidfile /var/run/dhcp-detect.pid
@ start program = "/etc/init.d/dhcp-detect start"
@ stop program = "/etc/init.d/dhcp-detect stop"
@ if 5 restarts within 5 cycles then timeout
@
service("dhcp-detect")
if has("freeradius"):
@# freeradius
@check process freeradius with pidfile /var/run/freeradius/freeradius.pid
@ start program = "/etc/init.d/freeradius start"
@ stop program = "/etc/init.d/freeradius stop"
@ if 5 restarts within 5 cycles then timeout
@
service("freeradius")
if has("inn"):
@# inn
@check process inn with pidfile /var/run/news/innd.pid
@ start program = "/etc/init.d/inn2 start"
@ stop program = "/etc/init.d/inn2 stop"
@ if 5 restarts within 5 cycles then timeout
@
service("inn",
pidf="news/innd",
init="inn2")
if has("mailman"):
@# mailman
@check process mailman with pidfile /var/run/mailman/mailman.pid
@ start program = "/etc/init.d/mailman start"
@ stop program = "/etc/init.d/mailman stop"
@ if 5 restarts within 5 cycles then timeout
@
service("mailman")
if has("monit-ovh"):
@# monit-ovh
@check process monit-ovh with pidfile /var/run/monit-ovh.pid
@ start program = "/etc/init.d/monit-ovh start"
@ stop program = "/etc/init.d/monit-ovh stop"
@ if 5 restarts within 5 cycles then timeout
@
service("monit-ovh")
@# munin-node
@check process munin-node with pidfile /var/run/munin/munin-node.pid
@ start program = "/etc/init.d/munin-node start"
@ stop program = "/etc/init.d/munin-node stop"
@ if 5 restarts within 5 cycles then timeout
@
service("mysql",
pidf="mysqld/mysqld")
if has("mysql"):
@# mysql
@check process mysql with pidfile /var/run/mysqld/mysqld.pid
@ start program = "/etc/init.d/mysql start"
@ stop program = "/etc/init.d/mysql stop"
@ if 5 restarts within 5 cycles then timeout
@
service("munin-node")
@# nscd
@check process nscd with pidfile /var/run/nscd/nscd.pid
@ start program = "/etc/init.d/nscd start"
@ stop program = "/etc/init.d/nscd stop"
@ if 5 restarts within 5 cycles then timeout
@ if failed unixsocket /var/run/nscd/socket then restart
@
service("nscd",
pidf="nscd/nscd",
extra=["if failed unixsocket /var/run/nscd/socket then restart"])
if has("openvpn-ovh"):
@# openvpn ovh
@check process openvpn with pidfile /var/run/openvpn.ovh.pid
@ start program = "/etc/init.d/openvpn start ovh"
@ stop program = "/etc/init.d/openvpn stop ovh"
@ if 5 restarts within 5 cycles then timeout
@
service("postfix",
pidp="/var/spool/postfix/pid/master.pid",
extra=["if failed port 25 protocol smtp timeout 30 seconds then restart"])
if has("openvpn-komaz"):
@# openvpn komaz
@check process openvpn-komaz with pidfile /var/run/openvpn.komaz.pid
@ start program = "/etc/init.d/openvpn start komaz"
@ stop program = "/etc/init.d/openvpn stop komaz"
@ if 5 restarts within 5 cycles then timeout
@
service("openvpn-ovh",
pidf="openvpn.ovh",
init="openvpn")
if has("openvpn-freebox"):
@# openvpn freebox
@check process openvpn-freebox with pidfile /var/run/openvpn.freebox.pid
@ start program = "/etc/init.d/openvpn start freebox"
@ stop program = "/etc/init.d/openvpn stop freebox"
@ depends on openvpn-komaz
@ if 5 restarts within 5 cycles then timeout
@
service("openvpn-komaz",
pidf="openvpn.komaz",
init="openvpn")
@# postfix
@check process postfix with pidfile /var/spool/postfix/pid/master.pid
@ start program = "/etc/init.d/postfix start"
@ stop program = "/etc/init.d/postfix stop"
@ if failed port 25 protocol smtp timeout 30 seconds then restart
@ if 5 restarts within 5 cycles then timeout
@
service("openvpn-freebox",
pidf="openvpn.freebox",
init="openvpn",
extra=["depends on openvpn-komaz"])
if has("pgsql-sqlgrey") or has("pgsql"):
@# postgresql
@check process postgresql with pidfile /var/lib/postgres/data/postmaster.pid
@ start program = "/etc/init.d/postgresql-7.4 start"
@ stop program = "/etc/init.d/postgresql-7.4 stop"
@ if failed port 5432 timeout 30 seconds then restart
@ if 5 restarts within 5 cycles then timeout
@
service("pgsql",
name="postgresql",
init="postgresql-7.4",
pidp="/var/lib/postgres/data/postmaster.pid",
extra=["if failed port 5432 timeout 30 seconds then restart"])
if has("privoxy"):
@# privoxy
@check process privoxy with pidfile /var/run/privoxy.pid
@ start program = "/etc/init.d/privoxy start"
@ stop program = "/etc/init.d/privoxy stop"
@ if failed host localhost port 8117 timeout 30 seconds then restart
@ if 5 restarts within 5 cycles then timeout
@
service("privoxy",
extra=["if failed host localhost port 8117 timeout 30 seconds then restart"])
if has("proftpd"):
@# proftpd
@check process proftpd with pidfile /var/run/proftpd.pid
@ start program = "/etc/init.d/proftpd start"
@ stop program = "/etc/init.d/proftpd stop"
@ if failed port 21 protocol ftp timeout 30 seconds then restart
@ if 5 restarts within 5 cycles then timeout
@
service("proftpd",
extra=["if failed port 21 protocol ftp timeout 30 seconds then restart"])
if has("rsync"):
@# rsync
@check process rsync with pidfile /var/run/rsync.pid
@ start program = "/etc/init.d/rsync start"
@ stop program = "/etc/init.d/rsync stop"
@ if 5 restarts within 5 cycles then timeout
@
service("rsync")
if has("slapd"):
@# slapd
@check process slapd with pidfile /var/run/slapd/slapd.pid
@ start program = "/etc/init.d/slapd start"
@ stop program = "/etc/init.d/slapd stop"
@ if failed host localhost port 389 protocol ldap3 timeout 30 seconds then restart
@ if 5 restarts within 5 cycles then timeout
@
service("slapd",
extra=["if failed host localhost port 389 protocol ldap3 timeout 30 seconds then restart"])
if has("spamassassin"):
@# spamd
@check process spamd with pidfile /var/run/spamd.pid
@ start program = "/etc/init.d/spamassassin start"
@ stop program = "/etc/init.d/spamassassin stop"
@ if 5 restarts within 5 cycles then timeout
@
service("spamassassin",
name="spamd",
init="spamassassin")
if has("sqlgrey"):
@# sqlgrey
@check process sqlgrey with pidfile /var/run/sqlgrey.pid
@ start program = "/etc/init.d/sqlgrey start"
@ stop program = "/etc/init.d/sqlgrey stop"
@ if 5 restarts within 5 cycles then timeout
@
service("sqlgrey")
@# ssh
@check process ssh with pidfile /var/run/sshd.pid
@ start program = "/etc/init.d/ssh start"
@ stop program = "/etc/init.d/ssh stop"
@ if failed port 22 protocol ssh timeout 30 seconds then restart
@ if children > 200 then restart
@ if 5 restarts within 5 cycles then timeout
@
service("ssh",
pidf="sshd",
extra=["if failed port 22 protocol ssh timeout 30 seconds then restart",
"if children > 200 then restart"])
service("syslog-ng",
extra=["depend on file/var/log/syslog"])
service("vsftpd",
extra=["if failed host %s port 21 protocol ftp timeout 30 seconds then restart" % pubip()])
service("vsftpd-federez",
extra=["if failed host 138.231.136.129 port 21 protocol ftp timeout 30 seconds then restart"])
@# syslog-ng
@check process syslog-ng with pidfile /var/run/syslog-ng.pid
@ start program = "/etc/init.d/syslog-ng start"
@ stop program = "/etc/init.d/syslog-ng stop"
@ if 5 restarts within 5 cycles then timeout
@ depend on file/var/log/syslog
@
@check file file/var/log/syslog with path /var/log/syslog
@ if timestamp > 15 minutes then alert
@
if has("vsftpd"):
@# vsftpd
@check process vsftpd with pidfile /var/run/vsftpd/vsftpd.pid
@ start program = "/etc/init.d/vsftpd start"
@ stop program = "/etc/init.d/vsftpd stop"
@ if failed host 138.231.136.10 port 21 protocol ftp timeout 30 seconds then restart
@ if 5 restarts within 5 cycles then timeout
@
if has("vsftpd-federez"):
@# vsftpd-federez
@check process vsftpd-federez with pidfile /var/run/vsftpd/vsftpd-federez.pid
@ start program = "/etc/init.d/vsftpd-federez start"
@ stop program = "/etc/init.d/vsftpd-federez stop"
@ if failed host 138.231.136.129 port 21 protocol ftp timeout 30 seconds then restart
@ if 5 restarts within 5 cycles then timeout
@
# on ne monitore pas les disques de canard
if hostname in ['canard'] :
done()