Dans affich_tools, tableau_ng remplace dornavant tableau.
darcs-hash:20060326160011-68412-d87c57d6e2edf22dd78fd5c78e07793a19421ff5.gz
This commit is contained in:
parent
821905a295
commit
7428178ab9
5 changed files with 101 additions and 123 deletions
|
@ -5,9 +5,9 @@ import socket
|
|||
import sys, re
|
||||
from pyPgSQL import PgSQL
|
||||
sys.path.append('/usr/scripts/gestion/')
|
||||
from affich_tools import tableau_ng
|
||||
from affich_tools import tableau
|
||||
|
||||
def stats (ip_crans=[], ip_ext=[], show=['ip_crans','ip_ext','port_crans','port_ext'], upload_mini=0, show_limit=10, begin_time=24, end_time=0):
|
||||
def stats(ip_crans=[], ip_ext=[], show=['ip_crans','ip_ext','port_crans','port_ext'], upload_mini=0, show_limit=10, begin_time=24, end_time=0):
|
||||
"""
|
||||
Retourne une chaine de caratères formatée avec le tableau de statistiques
|
||||
d'upload de l'ip fourni
|
||||
|
@ -91,16 +91,16 @@ def stats (ip_crans=[], ip_ext=[], show=['ip_crans','ip_ext','port_crans','port_
|
|||
|
||||
# on modifie les ip en noms de machine et les ports en noms
|
||||
def nom_de_machine (ip) :
|
||||
try :
|
||||
try:
|
||||
return socket.gethostbyaddr(ip)[0]
|
||||
except :
|
||||
except:
|
||||
return ip
|
||||
|
||||
port_to_service = {}
|
||||
for service,port in [ re.split('[ \t]+',x.strip().replace('/tcp','').replace('/udp',''))[:2] for x in open('/etc/services').readlines() if x[0] not in ['\n','#'] ] :
|
||||
port_to_service[port]=service
|
||||
|
||||
for champ in select :
|
||||
for champ in select:
|
||||
if champ == 'ip_ext':
|
||||
col = select.index(champ)
|
||||
results = [ x[:col] + [nom_de_machine(x[col])] + x[col+1:] for x in results ]
|
||||
|
@ -113,7 +113,7 @@ def stats (ip_crans=[], ip_ext=[], show=['ip_crans','ip_ext','port_crans','port_
|
|||
col = select.index(champ)
|
||||
results = [ x[:col] + [port_to_service.get(x[col],x[col])] + x[col+1:] for x in results ]
|
||||
|
||||
return tableau_ng(results, titre=titre, largeur=largeur, alignement=alignement, format=format)
|
||||
return tableau(results, titre=titre, largeur=largeur, alignement=alignement, format=format)
|
||||
|
||||
if __name__ == '__main__' :
|
||||
|
||||
|
@ -261,5 +261,5 @@ Exemples :
|
|||
# affichage du résultat
|
||||
#######################
|
||||
#print stats(ip_crans, group, upload_mini, limit, heures)
|
||||
print stats (ip_crans, ip_ext, show, upload_mini, limit, begin_time, end_time)
|
||||
print stats(ip_crans, ip_ext, show, upload_mini, limit, begin_time, end_time)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import smtplib
|
|||
import socket
|
||||
import time, random, md5
|
||||
from analyse import stats
|
||||
from affich_tools import tableau_ng
|
||||
from affich_tools import tableau
|
||||
from ldap_crans import AssociationCrans
|
||||
|
||||
###############################
|
||||
|
@ -44,22 +44,22 @@ mail = smtplib.SMTP('localhost')
|
|||
#####################
|
||||
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)
|
||||
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')
|
||||
liste_upload = tableau(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')
|
||||
|
||||
|
||||
# Traffic exempté :
|
||||
###################
|
||||
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)
|
||||
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')
|
||||
liste_exemptes = tableau(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 :
|
||||
|
@ -75,11 +75,11 @@ for i in (10,1,3,4,7,8,9,11):
|
|||
continue
|
||||
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')
|
||||
liste_serveurs = tableau(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
|
||||
|
@ -103,7 +103,7 @@ for IP in infections:
|
|||
continue
|
||||
liste_virus.append(["%s" % (str(hostname))])
|
||||
|
||||
liste_virus = tableau_ng(liste_virus, titre=['machine'], largeur=[30]).encode('iso-8859-15')
|
||||
liste_virus = tableau(liste_virus, titre=['machine'], largeur=[30]).encode('iso-8859-15')
|
||||
|
||||
# Machines ayant fait des attaques virus dans la journée :
|
||||
##########################################################
|
||||
|
@ -113,10 +113,10 @@ liste_virus2 = []
|
|||
for IP, compteur in curseur.fetchall():
|
||||
hostname = socket.gethostbyaddr(IP)[0]
|
||||
liste_virus2.append([hostname, compteur])
|
||||
liste_virus2 = tableau_ng(data = liste_virus2,
|
||||
titre = ['machine', 'nombre'],
|
||||
largeur = [30, 12],
|
||||
alignement = ['c', 'd']).encode('iso-8859-15')
|
||||
liste_virus2 = tableau(data = liste_virus2,
|
||||
titre = ['machine', 'nombre'],
|
||||
largeur = [30, 12],
|
||||
alignement = ['c', 'd']).encode('iso-8859-15')
|
||||
|
||||
|
||||
# Machines ayant fait de attaques flood dans la journée :
|
||||
|
@ -127,10 +127,10 @@ liste_virus3 = []
|
|||
for IP, compteur in curseur.fetchall():
|
||||
hostname = socket.gethostbyaddr(IP)[0]
|
||||
liste_virus3.append([hostname, compteur])
|
||||
liste_virus3 = tableau_ng(data = liste_virus3,
|
||||
titre = ['machine', 'nombre'],
|
||||
largeur = [30, 12],
|
||||
alignement = ['c', 'd']).encode('iso-8859-15')
|
||||
liste_virus3 = tableau(data = liste_virus3,
|
||||
titre = ['machine', 'nombre'],
|
||||
largeur = [30, 12],
|
||||
alignement = ['c', 'd']).encode('iso-8859-15')
|
||||
|
||||
|
||||
# Machines ayant utilisé des protocoles P2P dans la journée :
|
||||
|
@ -161,10 +161,10 @@ for IP, protocole, compteur, blackliste in curseur.fetchall():
|
|||
'*%d*' % config.p2p.limite[protocole]])
|
||||
else:
|
||||
liste_p2p.append([hostname, protocole, compteur, config.p2p.limite[protocole]])
|
||||
liste_p2p = tableau_ng(data = liste_p2p,
|
||||
titre = ['machine', 'protocole', 'nombre', 'limite'],
|
||||
largeur = [32, 14, 10, 8],
|
||||
alignement = ['c', 'c', 'd', 'd']).encode('iso-8859-15')
|
||||
liste_p2p = tableau(data = liste_p2p,
|
||||
titre = ['machine', 'protocole', 'nombre', 'limite'],
|
||||
largeur = [32, 14, 10, 8],
|
||||
alignement = ['c', 'c', 'd', 'd']).encode('iso-8859-15')
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue