...
[alex.git] / supervision / checkdisk.py
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # checkdisk
5 # script de supervision
6
7 import sys,os,statvfs,socket,smtplib,syslog,errno
8 from email.MIMEText import MIMEText
9 from email.Utils import COMMASPACE
10
11 send_to= ['alexandre.domont@auf.org']
12 partitions = ['/','/bck1','/bck2']
13 limite = 90 # 90% espace occupé
14
15 def sendmail(sujet):
16 mail = MIMEText("Reste : " + str(total) + " Go" + " sur " + element )
17 mail['From'] = "supervision"
18 mail['Subject'] = sujet
19 mail['To'] = COMMASPACE.join(send_to)
20 smtp = smtplib.SMTP()
21 smtp.connect()
22 smtp.sendmail("supervision", send_to, mail.as_string())
23 smtp.close()
24
25 try:
26
27 for element in partitions:
28 f = os.statvfs(element)
29 total = (f[statvfs.F_BAVAIL] * f[statvfs.F_FRSIZE])/ 1024
30 capa = (f[statvfs.F_BSIZE] * f[statvfs.F_BLOCKS]) / 1024
31 capa = ((capa) / 1024 ) / 1024
32 total = ((total) / 1024 ) / 1024
33 seuil = 100 - ((total*100) / capa )
34 if seuil > limite:
35 sendmail('Alerte disque sur ' + socket.gethostname() + " partition " + element )
36
37 except:
38 syslog.syslog(syslog.LOG_ERR, 'Erreur script supervision checkdisk')
39
40