checkdisk...
authorAlexandre Domont <alexandre.domont@auf.org>
Tue, 24 May 2011 15:00:48 +0000 (17:00 +0200)
committerAlexandre Domont <alexandre.domont@auf.org>
Tue, 24 May 2011 15:00:48 +0000 (17:00 +0200)
checkdisk.py [new file with mode: 0755]

diff --git a/checkdisk.py b/checkdisk.py
new file mode 100755 (executable)
index 0000000..99ba90b
--- /dev/null
@@ -0,0 +1,40 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# checkdisk
+# script de supervision 
+
+import sys,os,statvfs,socket,smtplib,syslog,errno
+from email.MIMEText import MIMEText
+from email.Utils import COMMASPACE
+
+send_to= ['alexandre.domont@auf.org']
+partitions = ['/','/bck1','/bck2']
+limite = 90  # 90%  espace occupé
+
+def sendmail(sujet):
+        mail = MIMEText("Reste : " + str(total) + " Go" + " sur " + element )
+        mail['From'] = "supervision"
+        mail['Subject'] = sujet
+        mail['To'] = COMMASPACE.join(send_to)
+        smtp = smtplib.SMTP()
+        smtp.connect()
+        smtp.sendmail("supervision", send_to, mail.as_string())
+        smtp.close()
+
+try:
+
+       for element in partitions:
+               f = os.statvfs(element)
+               total = (f[statvfs.F_BAVAIL] *  f[statvfs.F_FRSIZE])/ 1024 
+               capa =  (f[statvfs.F_BSIZE] * f[statvfs.F_BLOCKS]) / 1024
+               capa = ((capa) / 1024 ) / 1024
+               total = ((total) / 1024 ) / 1024
+               seuil =  100 - ((total*100) / capa )
+               if seuil > limite:
+                       sendmail('Alerte disque sur ' + socket.gethostname() + " partition " + element )
+
+except:
+       syslog.syslog(syslog.LOG_ERR, 'Erreur script supervision checkdisk')
+
+