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
|
@ -171,11 +171,12 @@ def controle_interactif(quoi):
|
||||||
okc, nokc =_controle_interactif_clubs(todo_list['club'])
|
okc, nokc =_controle_interactif_clubs(todo_list['club'])
|
||||||
|
|
||||||
print coul(u'\nRécapitulatif des nouveaux contrôles +%s :' % quoi, 'violet')
|
print coul(u'\nRécapitulatif des nouveaux contrôles +%s :' % quoi, 'violet')
|
||||||
liste = [(u'Catégorie', u'OK', u'pas OK'),
|
liste = [[u'adhérents', str(oka), str(noka)]]
|
||||||
(u'adhérents', str(oka), str(noka))]
|
|
||||||
if quoi == 'p':
|
if quoi == 'p':
|
||||||
liste.append((u'clubs', str(okc), str(nokc)))
|
liste.append([u'clubs', str(okc), str(nokc)])
|
||||||
print tableau([15, 10, 10], liste)
|
print tableau(liste,
|
||||||
|
titre = [u'Catégorie', u'OK', u'pas OK'],
|
||||||
|
largeur = [15, 10, 10])
|
||||||
|
|
||||||
|
|
||||||
def formater_pour_cableur(liste):
|
def formater_pour_cableur(liste):
|
||||||
|
@ -183,15 +184,18 @@ def formater_pour_cableur(liste):
|
||||||
Formate la liste d'adhérents ou de clubs avec les dates correspondantes.
|
Formate la liste d'adhérents ou de clubs avec les dates correspondantes.
|
||||||
liste est une liste de couples (date, objet).
|
liste est une liste de couples (date, objet).
|
||||||
"""
|
"""
|
||||||
lignes = [(u'id', u'Nom', u'Date Heure')]
|
lignes = []
|
||||||
total = 0
|
total = 0
|
||||||
liste.sort(lambda x, y: cmp(x[1].nom(), y[1].nom()))
|
liste.sort(lambda x, y: cmp(x[1].nom(), y[1].nom()))
|
||||||
|
|
||||||
for date, a in liste:
|
for date, a in liste:
|
||||||
lignes.append((a.id(), a.Nom(), date))
|
lignes.append([a.id(), a.Nom(), date])
|
||||||
total += 1
|
total += 1
|
||||||
|
|
||||||
return tableau([6, 40, 18], lignes) + u'\nTotal : %d' % total
|
return tableau(lignes,
|
||||||
|
titre = [u'id', u'Nom', u'Date Heure'],
|
||||||
|
largeur = [6, 40, 18],
|
||||||
|
alignement = ['d', 'c', 'c']) + u'\nTotal : %d' % total
|
||||||
|
|
||||||
|
|
||||||
def formater_pour_bureau(dico):
|
def formater_pour_bureau(dico):
|
||||||
|
@ -199,17 +203,20 @@ def formater_pour_bureau(dico):
|
||||||
Formate la liste d'adhérents ou de clubs avec les câbleurs correspondantes
|
Formate la liste d'adhérents ou de clubs avec les câbleurs correspondantes
|
||||||
pour le mail récapitulatif envoyé à bureau.
|
pour le mail récapitulatif envoyé à bureau.
|
||||||
"""
|
"""
|
||||||
lignes = [(u'id', u'Nom', u'Câbleur', u'Date')]
|
lignes = []
|
||||||
total = 0
|
total = 0
|
||||||
|
|
||||||
liste = dico.keys()
|
liste = dico.keys()
|
||||||
liste.sort()
|
liste.sort()
|
||||||
for cableur in liste:
|
for cableur in liste:
|
||||||
for date, a in dico[cableur]:
|
for date, a in dico[cableur]:
|
||||||
lignes.append((a.id(), a.Nom(), cableur, date))
|
lignes.append([a.id(), a.Nom(), cableur, date])
|
||||||
total += 1
|
total += 1
|
||||||
|
|
||||||
return tableau([6, 40, 18, 18], lignes) + u'\nTotal : %d' % total
|
return tableau(lignes,
|
||||||
|
titre = [u'id', u'Nom', u'Câbleur', u'Date'],
|
||||||
|
largeur = [6, 40, 18, 18],
|
||||||
|
alignement = ['d', 'c', 'c', 'c']) + u'\nTotal : %d' % total
|
||||||
|
|
||||||
|
|
||||||
def qui(historique, quoi):
|
def qui(historique, quoi):
|
||||||
|
|
|
@ -86,62 +86,17 @@ ERREUR = coul('ERREUR','rouge')
|
||||||
def cprint(txt,col):
|
def cprint(txt,col):
|
||||||
print coul(txt,col)
|
print coul(txt,col)
|
||||||
|
|
||||||
def tableau(largeurs,data) :
|
|
||||||
"""
|
|
||||||
retourne une chaine formatée repésentant un tableau
|
|
||||||
largeur est la liste des largeurs des colones
|
|
||||||
data est une liste de tuples :
|
|
||||||
[ ( données entète), (données ligne1), .... ]
|
|
||||||
"""
|
|
||||||
sep_col = u'|'
|
|
||||||
|
|
||||||
# Si l'une des largeurs est '*', alors on la met la plus grande possible
|
def tableau(data, titre=None, largeur=None, alignement=None, format=None):
|
||||||
if '*' in largeurs:
|
|
||||||
rows, cols = get_screen_size()
|
|
||||||
nlargeurs = []
|
|
||||||
for n in largeurs:
|
|
||||||
if n != '*':
|
|
||||||
nlargeurs.append(n)
|
|
||||||
else:
|
|
||||||
nlargeurs.append(max(cols - sum(filter(lambda x:x!='*',largeurs)) - len(largeurs) - 1, 3))
|
|
||||||
largeurs = nlargeurs
|
|
||||||
|
|
||||||
# Ligne de séparation entète corps
|
|
||||||
s=u'\n'
|
|
||||||
for l in largeurs :
|
|
||||||
s+= sep_col + u'-'*l
|
|
||||||
s += sep_col + u'\n'
|
|
||||||
|
|
||||||
nb_cols = len(largeurs)
|
|
||||||
|
|
||||||
# Remplissage tableau
|
|
||||||
f=u''
|
|
||||||
for ligne in data :
|
|
||||||
for i in range(0, nb_cols) :
|
|
||||||
f+= sep_col
|
|
||||||
# Centrage
|
|
||||||
l = len(sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m','',ligne[i])) # Longeur sans les chaines de formatage
|
|
||||||
if l >= largeurs[i] :
|
|
||||||
f += ligne[i]
|
|
||||||
else :
|
|
||||||
n = largeurs[i] - l
|
|
||||||
f += u' '*(n/2) + ligne[i] + u' '*(n/2 + n%2)
|
|
||||||
f+= sep_col + u'\n'
|
|
||||||
|
|
||||||
# Final
|
|
||||||
f = f.replace(u'\n',s,1) # Insertion du séparateur entète - corps
|
|
||||||
return f[:-1] # Supression du \n final
|
|
||||||
|
|
||||||
def tableau_ng(data,titre=None,largeur=None,alignement=None,format=None) :
|
|
||||||
"""
|
"""
|
||||||
Retourne une chaine formatée repésentant un tableau
|
Retourne une chaine formatée repésentant un tableau.
|
||||||
|
|
||||||
data : liste de listes, chacune contenant les valeurs d'une ligne
|
data : liste de listes, chacune contenant les valeurs d'une ligne
|
||||||
|
|
||||||
titre : liste des titres
|
titre : liste des titres
|
||||||
Si none, n'affiche pas de ligne de titre
|
Si none, n'affiche pas de ligne de titre
|
||||||
|
|
||||||
largeur : liste des largeurs des colonnes, '*' met la plus grande
|
largeur : liste des largeurs des colonnes, '*' met la plus grande
|
||||||
largeur possible.
|
largeur possible.
|
||||||
Si None, réduit aux max chaque colonne
|
Si None, réduit aux max chaque colonne
|
||||||
|
|
||||||
|
@ -150,7 +105,7 @@ def tableau_ng(data,titre=None,largeur=None,alignement=None,format=None) :
|
||||||
d = droit
|
d = droit
|
||||||
Si None, met c pour chaque colonne
|
Si None, met c pour chaque colonne
|
||||||
|
|
||||||
format : liste des formats : s = string
|
format : liste des formats : s = string
|
||||||
o = octet
|
o = octet
|
||||||
Si None, s pour chaque colonne
|
Si None, s pour chaque colonne
|
||||||
"""
|
"""
|
||||||
|
@ -167,20 +122,20 @@ def tableau_ng(data,titre=None,largeur=None,alignement=None,format=None) :
|
||||||
if not format :
|
if not format :
|
||||||
format = ['s'] * nbcols
|
format = ['s'] * nbcols
|
||||||
|
|
||||||
def reformate (data, format) :
|
def reformate(data, format):
|
||||||
if format == 's' :
|
if format == 's':
|
||||||
return str(data)
|
return unicode(data)
|
||||||
|
|
||||||
elif format == 'o' :
|
elif format == 'o' :
|
||||||
data = float(data)
|
data = float(data)
|
||||||
if data > 1024**3 :
|
if data > 1024**3:
|
||||||
return str(round(data/1024**3,1))+'Go'
|
return str(round(data/1024**3, 1)) + 'Go'
|
||||||
elif data > 1024**2 :
|
elif data > 1024**2:
|
||||||
return str(round(data/1024**2,1))+'Mo'
|
return str(round(data/1024**2, 1)) + 'Mo'
|
||||||
elif data > 1024 :
|
elif data > 1024:
|
||||||
return str(round(data/1024,1))+'ko'
|
return str(round(data/1024, 1)) + 'ko'
|
||||||
else :
|
else:
|
||||||
return str(round(data,1))+'o'
|
return str(round(data, 1)) + 'o'
|
||||||
|
|
||||||
data = [ [ reformate(ligne[i],format[i]) for i in range(nbcols) ] for ligne in data ]
|
data = [ [ reformate(ligne[i],format[i]) for i in range(nbcols) ] for ligne in data ]
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ def adhers_brief(adhers) :
|
||||||
* chambre
|
* chambre
|
||||||
* machines
|
* machines
|
||||||
"""
|
"""
|
||||||
data = [ ( u'aid' , u'Prénom Nom' , u'Chbre', u'P', u'C', u'Machines' ) ]
|
data = []
|
||||||
|
|
||||||
for a in adhers :
|
for a in adhers :
|
||||||
## Etat administratif
|
## Etat administratif
|
||||||
|
@ -140,12 +140,15 @@ def adhers_brief(adhers) :
|
||||||
else : machines = coul(nom,k)
|
else : machines = coul(nom,k)
|
||||||
|
|
||||||
# Données
|
# Données
|
||||||
data.append((a.id() , a.Nom(), a.chbre(),paid,carte,machines ))
|
data.append([a.id(), a.Nom(), a.chbre(), paid, carte, machines])
|
||||||
|
|
||||||
return u"Machines en rouge = machines avec limitation de services\n" + \
|
return u"Machines en rouge = machines avec limitation de services\n" + \
|
||||||
u"P : paiement année en cours, le fond vert indique le précâblage\n" + \
|
u"P : paiement année en cours, le fond vert indique le précâblage\n" + \
|
||||||
u"C : carte d'étudiant année en cours\n" + \
|
u"C : carte d'étudiant année en cours\n" + \
|
||||||
tableau([5, 30 , 5, 1, 1, '*'], data)
|
tableau(data,
|
||||||
|
titre = [u'aid', u'Prénom Nom', u'Chbre', u'P', u'C', u'Machines'],
|
||||||
|
largeur = [5, 30, 5, 1, 1, '*'],
|
||||||
|
alignement = ['d', 'c', 'g', 'c', 'c', 'c'])
|
||||||
|
|
||||||
def machines_brief(machines) :
|
def machines_brief(machines) :
|
||||||
"""
|
"""
|
||||||
|
@ -157,7 +160,7 @@ def machines_brief(machines) :
|
||||||
* adresse MAC
|
* adresse MAC
|
||||||
* si blacklistée
|
* si blacklistée
|
||||||
"""
|
"""
|
||||||
data = [ ( u'mid' , u'Type', u'Nom de machine', u'Propriétaire', u'Chbre', u'Limitation' ) ]
|
data = []
|
||||||
|
|
||||||
for m in machines :
|
for m in machines :
|
||||||
t, bl = __bases_machines(m)
|
t, bl = __bases_machines(m)
|
||||||
|
@ -171,10 +174,13 @@ def machines_brief(machines) :
|
||||||
p = coul(p,'rouge')
|
p = coul(p,'rouge')
|
||||||
|
|
||||||
# Données
|
# Données
|
||||||
data.append((m.id() , t, m.nom().split('.')[0], p, a.chbre(), bl))
|
data.append([m.id() , t, m.nom().split('.')[0], p, a.chbre(), bl])
|
||||||
|
|
||||||
return u"Le propriétaire en rouge signale un problème administratif\n" + \
|
return u"Le propriétaire en rouge signale un problème administratif\n" + \
|
||||||
tableau([5, 4, 18, '*', 5, 10], data)
|
tableau(data,
|
||||||
|
titre = [u'mid', u'Type', u'Nom de machine', u'Propriétaire', u'Chbre', u'Limitation'],
|
||||||
|
largeur = [5, 4, 18, '*', 5, 10],
|
||||||
|
alignement = ['d', 'c', 'c', 'c', 'g', 'c'])
|
||||||
|
|
||||||
def clubs_brief(clubs) :
|
def clubs_brief(clubs) :
|
||||||
"""
|
"""
|
||||||
|
@ -184,7 +190,7 @@ def clubs_brief(clubs) :
|
||||||
* local
|
* local
|
||||||
* machines
|
* machines
|
||||||
"""
|
"""
|
||||||
data = [ ( u'cid' , u'Nom ', u'Local',u'P', u'Responsable', u'Machines' ) ]
|
data = []
|
||||||
|
|
||||||
for c in clubs :
|
for c in clubs :
|
||||||
## Etat administratif
|
## Etat administratif
|
||||||
|
@ -213,11 +219,14 @@ def clubs_brief(clubs) :
|
||||||
resp = c.responsable().Nom()
|
resp = c.responsable().Nom()
|
||||||
|
|
||||||
# Données
|
# Données
|
||||||
data.append((c.id() , c.Nom(), c.local(),paid, resp, machines ))
|
data.append([c.id() , c.Nom(), c.local(), paid, resp, machines])
|
||||||
|
|
||||||
return u"Machines en rouge = machines avec limitation de services\n" + \
|
return u"Machines en rouge = machines avec limitation de services\n" + \
|
||||||
u"P : signature charte année en cours, le fond vert indique le précâblage\n" + \
|
u"P : signature charte année en cours, le fond vert indique le précâblage\n" + \
|
||||||
tableau([5, '*' , 6, 1, 21, 15], data)
|
tableau(data,
|
||||||
|
titre = [u'cid', u'Nom ', u'Local', u'P', u'Responsable', u'Machines'],
|
||||||
|
largeur = [5, '*', 6, 1, 21, 15],
|
||||||
|
alignement = ['d', 'c', 'g', 'c', 'c', 'c'])
|
||||||
|
|
||||||
|
|
||||||
def list_machines(machines) :
|
def list_machines(machines) :
|
||||||
|
@ -230,15 +239,18 @@ def list_machines(machines) :
|
||||||
* adresse MAC
|
* adresse MAC
|
||||||
* si blacklistée
|
* si blacklistée
|
||||||
"""
|
"""
|
||||||
data = [ ( u'mid' , u'Type', u'Nom de machine', u'Adresse IP', u'Adresse MAC', u'Limitation' ) ]
|
data = []
|
||||||
|
|
||||||
for m in machines :
|
for m in machines :
|
||||||
t, bl = __bases_machines(m)
|
t, bl = __bases_machines(m)
|
||||||
|
|
||||||
# Données
|
# Données
|
||||||
data.append((m.id() , t, m.nom().split('.')[0], m.ip(), m.mac(), bl))
|
data.append([m.id(), t, m.nom().split('.')[0], m.ip(), m.mac(), bl])
|
||||||
|
|
||||||
return tableau([5, 4, '*', 17, 19, 10], data)
|
return tableau(data,
|
||||||
|
titre = [u'mid', u'Type', u'Nom de machine', u'Adresse IP', u'Adresse MAC', u'Limitation'],
|
||||||
|
largeur = [5, 4, '*', 17, 19, 10],
|
||||||
|
alignement = ['d', 'c', 'c', 'c', 'c', 'c'])
|
||||||
|
|
||||||
def list_bornes(bornes) :
|
def list_bornes(bornes) :
|
||||||
"""
|
"""
|
||||||
|
@ -252,7 +264,7 @@ def list_bornes(bornes) :
|
||||||
* canal
|
* canal
|
||||||
* lieu (la première remarque en fait)
|
* lieu (la première remarque en fait)
|
||||||
"""
|
"""
|
||||||
data = [ ( u'mid' , u'Nom', u'Adresse IP', u'Adresse MAC', u'E', u'Can' , u'P', u'Pris', u'Lieu') ]
|
data = []
|
||||||
|
|
||||||
ok = u'\x1b[1;32mu\x1b[1;0m'
|
ok = u'\x1b[1;32mu\x1b[1;0m'
|
||||||
nok = u'\x1b[1;31md\x1b[1;0m'
|
nok = u'\x1b[1;31md\x1b[1;0m'
|
||||||
|
@ -278,9 +290,13 @@ def list_bornes(bornes) :
|
||||||
else :
|
else :
|
||||||
puiss = b.puissance()
|
puiss = b.puissance()
|
||||||
|
|
||||||
data.append((b.id() , b.nom().split('.')[0], b.ip(), b.mac(), etat, b.canal(), puiss, b.prise(),l ))
|
data.append([b.id(), b.nom().split('.')[0], b.ip(), b.mac(), etat, b.canal(), puiss, b.prise(), l])
|
||||||
|
|
||||||
return u"Can=canaux, P=puissance, E=état\n" + tableau([4, 13, 15, 17, 1, 5, 3, 4, '*'], data)
|
return u"Can=canaux, P=puissance, E=état\n" + \
|
||||||
|
tableau(data,
|
||||||
|
titre = [u'mid', u'Nom', u'Adresse IP', u'Adresse MAC', u'E', u'Can', u'P', u'Pris', u'Lieu'],
|
||||||
|
largeur = [5, 13, 15, 17, 1, 5, 3, 4, '*'],
|
||||||
|
alignement = ['d', 'c', 'c', 'c', 'c', 'c', 'c', 'g', 'c'])
|
||||||
|
|
||||||
def adher_details(adher) :
|
def adher_details(adher) :
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -5,9 +5,9 @@ import socket
|
||||||
import sys, re
|
import sys, re
|
||||||
from pyPgSQL import PgSQL
|
from pyPgSQL import PgSQL
|
||||||
sys.path.append('/usr/scripts/gestion/')
|
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
|
Retourne une chaine de caratères formatée avec le tableau de statistiques
|
||||||
d'upload de l'ip fourni
|
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
|
# on modifie les ip en noms de machine et les ports en noms
|
||||||
def nom_de_machine (ip) :
|
def nom_de_machine (ip) :
|
||||||
try :
|
try:
|
||||||
return socket.gethostbyaddr(ip)[0]
|
return socket.gethostbyaddr(ip)[0]
|
||||||
except :
|
except:
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
port_to_service = {}
|
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','#'] ] :
|
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
|
port_to_service[port]=service
|
||||||
|
|
||||||
for champ in select :
|
for champ in select:
|
||||||
if champ == 'ip_ext':
|
if champ == 'ip_ext':
|
||||||
col = select.index(champ)
|
col = select.index(champ)
|
||||||
results = [ x[:col] + [nom_de_machine(x[col])] + x[col+1:] for x in results ]
|
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)
|
col = select.index(champ)
|
||||||
results = [ x[:col] + [port_to_service.get(x[col],x[col])] + x[col+1:] for x in results ]
|
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__' :
|
if __name__ == '__main__' :
|
||||||
|
|
||||||
|
@ -261,5 +261,5 @@ Exemples :
|
||||||
# affichage du résultat
|
# affichage du résultat
|
||||||
#######################
|
#######################
|
||||||
#print stats(ip_crans, group, upload_mini, limit, heures)
|
#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 socket
|
||||||
import time, random, md5
|
import time, random, md5
|
||||||
from analyse import stats
|
from analyse import stats
|
||||||
from affich_tools import tableau_ng
|
from affich_tools import tableau
|
||||||
from ldap_crans import AssociationCrans
|
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"
|
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)
|
curseur.execute(requete)
|
||||||
liste_upload = tableau_ng(data = [ [l[1], l[2], socket.gethostbyaddr(str(l[0]))[0]] for l in curseur.fetchall() ],
|
liste_upload = tableau(data = [ [l[1], l[2], socket.gethostbyaddr(str(l[0]))[0]] for l in curseur.fetchall() ],
|
||||||
titre = ['upload', 'download', 'machine'],
|
titre = ['upload', 'download', 'machine'],
|
||||||
largeur = [10, 10, 30],
|
largeur = [10, 10, 30],
|
||||||
format = ['o', 'o', 's'],
|
format = ['o', 'o', 's'],
|
||||||
alignement = ['d', 'd', 'c']).encode('iso-8859-15')
|
alignement = ['d', 'd', 'c']).encode('iso-8859-15')
|
||||||
|
|
||||||
|
|
||||||
# Traffic exempté :
|
# 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"
|
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)
|
curseur.execute(requete)
|
||||||
liste_exemptes = tableau_ng(data = [ [l[1], l[2], socket.gethostbyaddr(str(l[0]))[0] ] for l in curseur.fetchall() ],
|
liste_exemptes = tableau(data = [ [l[1], l[2], socket.gethostbyaddr(str(l[0]))[0] ] for l in curseur.fetchall() ],
|
||||||
titre = ['upload', 'download', 'machine'],
|
titre = ['upload', 'download', 'machine'],
|
||||||
largeur = [10, 10, 30],
|
largeur = [10, 10, 30],
|
||||||
format = ['o', 'o', 's'],
|
format = ['o', 'o', 's'],
|
||||||
alignement = ['d', 'd', 'c']).encode('iso-8859-15')
|
alignement = ['d', 'd', 'c']).encode('iso-8859-15')
|
||||||
|
|
||||||
|
|
||||||
# Upload des serveurs :
|
# Upload des serveurs :
|
||||||
|
@ -75,11 +75,11 @@ for i in (10,1,3,4,7,8,9,11):
|
||||||
continue
|
continue
|
||||||
liste_serveurs.append([traffic[0],traffic[1],hostname])
|
liste_serveurs.append([traffic[0],traffic[1],hostname])
|
||||||
|
|
||||||
liste_serveurs = tableau_ng( data = liste_serveurs,
|
liste_serveurs = tableau(data = liste_serveurs,
|
||||||
titre = ['upload','download','serveur'],
|
titre = ['upload','download','serveur'],
|
||||||
largeur = [10, 10, 30],
|
largeur = [10, 10, 30],
|
||||||
format = ['o','o','s'],
|
format = ['o','o','s'],
|
||||||
alignement = ['d','d','c']).encode('iso-8859-15')
|
alignement = ['d','d','c']).encode('iso-8859-15')
|
||||||
|
|
||||||
|
|
||||||
# statistiques des gros uploads depuis les serveurs
|
# statistiques des gros uploads depuis les serveurs
|
||||||
|
@ -103,7 +103,7 @@ for IP in infections:
|
||||||
continue
|
continue
|
||||||
liste_virus.append(["%s" % (str(hostname))])
|
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 :
|
# Machines ayant fait des attaques virus dans la journée :
|
||||||
##########################################################
|
##########################################################
|
||||||
|
@ -113,10 +113,10 @@ liste_virus2 = []
|
||||||
for IP, compteur in curseur.fetchall():
|
for IP, compteur in curseur.fetchall():
|
||||||
hostname = socket.gethostbyaddr(IP)[0]
|
hostname = socket.gethostbyaddr(IP)[0]
|
||||||
liste_virus2.append([hostname, compteur])
|
liste_virus2.append([hostname, compteur])
|
||||||
liste_virus2 = tableau_ng(data = liste_virus2,
|
liste_virus2 = tableau(data = liste_virus2,
|
||||||
titre = ['machine', 'nombre'],
|
titre = ['machine', 'nombre'],
|
||||||
largeur = [30, 12],
|
largeur = [30, 12],
|
||||||
alignement = ['c', 'd']).encode('iso-8859-15')
|
alignement = ['c', 'd']).encode('iso-8859-15')
|
||||||
|
|
||||||
|
|
||||||
# Machines ayant fait de attaques flood dans la journée :
|
# Machines ayant fait de attaques flood dans la journée :
|
||||||
|
@ -127,10 +127,10 @@ liste_virus3 = []
|
||||||
for IP, compteur in curseur.fetchall():
|
for IP, compteur in curseur.fetchall():
|
||||||
hostname = socket.gethostbyaddr(IP)[0]
|
hostname = socket.gethostbyaddr(IP)[0]
|
||||||
liste_virus3.append([hostname, compteur])
|
liste_virus3.append([hostname, compteur])
|
||||||
liste_virus3 = tableau_ng(data = liste_virus3,
|
liste_virus3 = tableau(data = liste_virus3,
|
||||||
titre = ['machine', 'nombre'],
|
titre = ['machine', 'nombre'],
|
||||||
largeur = [30, 12],
|
largeur = [30, 12],
|
||||||
alignement = ['c', 'd']).encode('iso-8859-15')
|
alignement = ['c', 'd']).encode('iso-8859-15')
|
||||||
|
|
||||||
|
|
||||||
# Machines ayant utilisé des protocoles P2P dans la journée :
|
# 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]])
|
'*%d*' % config.p2p.limite[protocole]])
|
||||||
else:
|
else:
|
||||||
liste_p2p.append([hostname, protocole, compteur, config.p2p.limite[protocole]])
|
liste_p2p.append([hostname, protocole, compteur, config.p2p.limite[protocole]])
|
||||||
liste_p2p = tableau_ng(data = liste_p2p,
|
liste_p2p = tableau(data = liste_p2p,
|
||||||
titre = ['machine', 'protocole', 'nombre', 'limite'],
|
titre = ['machine', 'protocole', 'nombre', 'limite'],
|
||||||
largeur = [32, 14, 10, 8],
|
largeur = [32, 14, 10, 8],
|
||||||
alignement = ['c', 'c', 'd', 'd']).encode('iso-8859-15')
|
alignement = ['c', 'c', 'd', 'd']).encode('iso-8859-15')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue