-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.py
38 lines (35 loc) · 1.29 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- encoding: utf-8 -*-
# AUTHOR: Jonathan Arias G - 2018
import subprocess
import smtplib
from email.mime.text import MIMEText
problems = False
df_usage = subprocess.Popen("df -h --output=pcent -x tmpfs -x devtmpfs", stdout=subprocess.PIPE, shell=True)
df_full = subprocess.Popen("df -h --output=source,pcent -x tmpfs -x devtmpfs", stdout=subprocess.PIPE, shell=True)
usage=df_usage.stdout.read()
full=df_full.stdout.read()
disk2 = usage.split()
for item in disk2:
if item != 'Uso%' and item != 'Usage%':
if item >= '70%':
problems = True
if problems == True:
hostname = subprocess.Popen("cat /etc/hostname", stdout=subprocess.PIPE, shell=True)
hostname = hostname.stdout.read().split()
message = "¡Hola! Actualmente hay una partición del equipo <<"+ hostname[0] +">> con más del 70% de uso: \n\n" + full
msg = MIMEText(message)
msg['Subject'] = 'Partition checker'
msg['From'] = 'Partition checker'
msg['To'] = '[email protected]'
username = '[email protected]'
password = 'xxx'
try:
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail('[email protected]', email_list, msg.as_string() )
server.quit()
#print ("Envio realizado correctamente")
except Exception as e:
print e