diff --git a/surveillance/statistiques.py b/surveillance/statistiques.py index de1db039..ebb42970 100755 --- a/surveillance/statistiques.py +++ b/surveillance/statistiques.py @@ -33,6 +33,12 @@ pgsql = PgSQL.connect(host='/var/run/postgresql', database='filtrage', user='cra curseur = pgsql.cursor() mail = smtplib.SMTP('localhost') +# Probablement à mettre ailleurs +def gethostname(s): + try: + return socket.gethostbyaddr(s)[0] + except: + return s ########################### # Statistiques d'upload : # @@ -42,9 +48,11 @@ mail = smtplib.SMTP('localhost') # Liste des uploads : ##################### -requete = "SELECT ip_crans,sum(upload) as somme,sum(download) FROM upload WHERE ip_crans IN (SELECT ip_crans FROM avertis_upload where hard='1' or soft='1') and date > timestamp 'now' - interval '1 day' GROUP BY ip_crans ORDER BY somme DESC" +requete = "SELECT ip_crans,sum(upload) as somme,sum(download) FROM upload WHERE date > timestamp 'now' - interval '1 day' GROUP BY ip_crans ORDER BY somme DESC" curseur.execute(requete) -liste_upload = tableau(data = [ [l[1], l[2], socket.gethostbyaddr(str(l[0]))[0]] for l in curseur.fetchall() ], +liste_upload = tableau(data = [ (l[1], l[2], gethostname(str(l[0]))) + for l in curseur.fetchall() + if int(l[1]) > 100*1024*1024 ], titre = ['upload', 'download', 'machine'], largeur = [10, 10, 30], format = ['o', 'o', 's'],