...
[alex.git] / supervision / checkdisk.py
CommitLineData
38c0c7c2
AD
1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# checkdisk
5# script de supervision
6
7import sys,os,statvfs,socket,smtplib,syslog,errno
8from email.MIMEText import MIMEText
9from email.Utils import COMMASPACE
10
11send_to= ['alexandre.domont@auf.org']
12partitions = ['/','/bck1','/bck2']
13limite = 90 # 90% espace occupé
14
15def 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
25try:
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
37except:
38 syslog.syslog(syslog.LOG_ERR, 'Erreur script supervision checkdisk')
39
40