nouveau format de tableau, utilisation dans la gestion de la surveillance du
rseau darcs-hash:20051103235738-4ec08-4cbc92f43c8eb43da17d910d09e5d5597e9d781c.gz
This commit is contained in:
parent
ba62565f57
commit
92fa0abe2a
3 changed files with 132 additions and 78 deletions
|
@ -16,10 +16,12 @@ import commands
|
|||
import sys
|
||||
from pyPgSQL import PgSQL
|
||||
sys.path.append('/usr/scripts/gestion')
|
||||
sys.path.append('/usr/scripts/surveillance')
|
||||
import config
|
||||
import smtplib
|
||||
import socket
|
||||
from analyse import stats
|
||||
from affich_tools import tableau_ng
|
||||
|
||||
######################
|
||||
# Fonctions à la con #
|
||||
|
@ -50,34 +52,29 @@ mail = smtplib.SMTP('localhost')
|
|||
|
||||
# Adhérents avertis :
|
||||
#####################
|
||||
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"
|
||||
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"
|
||||
curseur.execute(requete)
|
||||
hard = curseur.fetchall()
|
||||
liste_upload = '| upload | download | machine |\n'
|
||||
liste_upload += '|----------|----------|------------------------------|\n'
|
||||
for IP,upload,download in hard:
|
||||
hostname = socket.gethostbyaddr("%s"%IP)[0]
|
||||
liste_upload += '| %7so | %7so | %28s |\n' % (humanise(upload),humanise(download),hostname)
|
||||
liste_upload = tableau_ng( data = [ [l[1], l[2], socket.gethostbyaddr(str(l[0]))[0]] for l in curseur.fetchall() ],
|
||||
titre = ['upload','download','machine'],
|
||||
largeur = [10, 10, 30],
|
||||
format = ['o','o','s'],
|
||||
alignement = ['d','d','c']).encode('iso-8859-15')
|
||||
|
||||
|
||||
# Upload exemptés :
|
||||
###################
|
||||
requete = "SELECT ip_crans,sum(upload) AS somme , sum(download) FROM upload WHERE ip_crans IN ( SELECT ip_crans from exemptes) and date > timestamp 'now' - interval '1 day' GROUP BY ip_crans order by somme"
|
||||
requete = "SELECT ip_crans,sum(upload) AS somme , sum(download) FROM upload WHERE ip_crans IN ( SELECT ip_crans from exemptes) and date > timestamp 'now' - interval '1 day' GROUP BY ip_crans ORDER BY somme DESC"
|
||||
curseur.execute(requete)
|
||||
exemptes = curseur.fetchall()
|
||||
liste_exemptes = '| upload | download | machine |\n'
|
||||
liste_exemptes += '|----------|----------|------------------------------|\n'
|
||||
for IP,upload,download in exemptes:
|
||||
if upload < config.upload.soft :
|
||||
continue
|
||||
hostname = socket.gethostbyaddr("%s"%IP)[0]
|
||||
liste_exemptes += '| %7so | %7so | %28s |\n' % (humanise(upload),humanise(download),hostname)
|
||||
liste_exemptes = tableau_ng( data = [ [l[1],l[2],socket.gethostbyaddr(str(l[0]))[0] ] for l in curseur.fetchall() ],
|
||||
titre = ['upload','download','machine'],
|
||||
largeur = [10, 10, 30],
|
||||
format = ['o','o','s'],
|
||||
alignement = ['d','d','c']).encode('iso-8859-15')
|
||||
|
||||
|
||||
# Upload des serveurs :
|
||||
#######################
|
||||
liste_serveurs = '| upload | download | machine |\n'
|
||||
liste_serveurs += '|----------|----------|------------------------------|\n'
|
||||
liste_serveurs = []
|
||||
for i in (10,1,3,4,7,8,9,11):
|
||||
IP='138.231.136.%d' % i
|
||||
hostname = socket.gethostbyaddr("%s"%IP)[0]
|
||||
|
@ -86,7 +83,13 @@ for i in (10,1,3,4,7,8,9,11):
|
|||
traffic=curseur.fetchone()
|
||||
if traffic == [None, None] :
|
||||
continue
|
||||
liste_serveurs += '| %7so | %7so | %28s |\n' % (humanise(traffic[0]),humanise(traffic[1]),str(hostname))
|
||||
liste_serveurs.append([traffic[0],traffic[1],hostname])
|
||||
|
||||
liste_serveurs = tableau_ng( data = liste_serveurs,
|
||||
titre = ['upload','download','serveur'],
|
||||
largeur = [10, 10, 30],
|
||||
format = ['o','o','s'],
|
||||
alignement = ['d','d','c']).encode('iso-8859-15')
|
||||
|
||||
|
||||
# statistiques des gros uploads depuis les serveurs
|
||||
|
@ -116,27 +119,33 @@ for serveur in serveurs :
|
|||
requete = "SELECT DISTINCT ip_crans FROM avertis_virus"
|
||||
curseur.execute(requete)
|
||||
infections = [ x[0] for x in curseur.fetchall() ]
|
||||
liste_virus=""
|
||||
liste_virus=[]
|
||||
for IP in infections:
|
||||
try:
|
||||
hostname = socket.gethostbyaddr("%s"%IP)[0]
|
||||
except socket.herror:
|
||||
continue
|
||||
liste_virus+="%s\n"%(str(hostname))
|
||||
liste_virus.append(["%s\n"%(str(hostname))])
|
||||
|
||||
liste_virus = tableau_ng(liste_virus, titre=['machine'], largeur=[30]).encode('iso-8859-15')
|
||||
|
||||
|
||||
# Machines utilisant des protocoles P2P :
|
||||
#########################################
|
||||
requete = "SELECT ip_crans,protocole FROM avertis_p2p WHERE date>timestamp 'now' - interval '1 day'"
|
||||
curseur.execute(requete)
|
||||
liste_p2p = '|protocole | machine | nombre |\n'
|
||||
liste_p2p += '|----------|------------------------------|----------|\n'
|
||||
liste_p2p = []
|
||||
for IP, protocole in curseur.fetchall():
|
||||
hostname = socket.gethostbyaddr(IP)[0]
|
||||
requete = "SELECT COUNT(ip_src) from p2p where date > timestamp 'now' - interval '1 day' and ip_src='%s'"%IP
|
||||
curseur.execute(requete)
|
||||
paquets=curseur.fetchone()[0]
|
||||
liste_p2p += '| %8s | %28s | %8s |\n' % (protocole,hostname,str(paquets))
|
||||
liste_p2p.append([protocole,hostname,str(paquets)])
|
||||
|
||||
liste_p2p = tableau_ng( data = liste_p2p,
|
||||
titre = ['protocole','machine','nombre'],
|
||||
largeur = [12, 30, 8],
|
||||
alignement = ['g','c','d'] ).encode('iso-8859-15')
|
||||
|
||||
|
||||
#############
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue