Commit 615fac78 authored by Pierre-Elliott Bécue's avatar Pierre-Elliott Bécue

[comptage_upload] deconnexion.py avec la bonne requête, enfin j'espère

parent 650991d3
......@@ -198,6 +198,8 @@ demenagement_delai = 8
# komaz car c'est la route par défaut mais aussi pour zamok et sable
# à cause de leur firewall et de leur patte wifi.
plage_ens = '138.231.0.0/16'
# NETs_primaires contient une bijection entre des types de machines
# et les plages d'ip qui vont bien. NETs_secondaires contient des
# clefs qui cassent la bijectivité, mais qui peuvent servir.
......
......@@ -20,7 +20,7 @@ import commands
import sys
import psycopg2
sys.path.append('/usr/scripts/gestion')
from config import upload, virus, NETs
from config import upload, virus, NETs, plage_ens, prefix
import config.mails.upload
import ipt
import smtplib
......@@ -100,72 +100,45 @@ def reperage_chambre(mac):
################################################################################
# upload par entité (adhérent/club/machine crans)
upload4="""SELECT
'upload', sum(upload)/1024/1024 AS total, ip_crans
FROM
upload
WHERE
upload > download
AND date > timestamp 'now' - interval '1 day'
AND date < 'now'
AND NOT EXISTS
(
SELECT 1
FROM exemptes
WHERE upload.ip_crans <<= exemptes.ip_crans
AND upload.ip_ext <<= exemptes.ip_dest
)
GROUP BY
ip_crans
"""
upload6 = """SELECT
'upload', sum(upload)/1024/1024 AS total, ip_crans
FROM
(
SELECT DISTINCT * FROM
upload="""SELECT
SUM((agregat.total) as tot_upload, machines.type, machines.id
FROM (
SELECT
'upload', sum(bytes)/1024/1024 AS total, mac_src
FROM
upload
WHERE
stamp_updated > now() - interval '1 day'
AND stamp_updated < now()
AND NOT (ip_dst <<= inet%(plage_ens)s OR ip_dst <<= inet%(plage_ipv6)s OR ip_dst <<= inet%(appt)s)
AND (ip_src <<= inet%(allone)s OR ip_src <<= inet%(alltwo)s OR ip_src <<= inet%(plage_ipv6)s OR ip_src <<= inet%(appt)s)
AND NOT EXISTS
(
SELECT
upload6.date, mac_ip.mac AS ip_crans, upload6.ip_ext, upload6.id, upload6.port_crans, upload6.port_ext, upload6.download, upload6.upload
FROM mac_ip,upload6
WHERE
upload6.ip_crans = mac_ip.ip
AND upload6.date > mac_ip.date
AND upload6.date - interval '1 day' < mac_ip.date
AND upload6.date > timestamp 'now' - interval '1 day'
AND upload6.date < 'now'
AND upload6.upload > upload6.download
AND NOT EXISTS
(
SELECT 1
FROM exemptes
WHERE mac_ip.mac <<= exemptes.ip_crans
AND upload6.ip_ext <<= exemptes.ip_dest
)
) AS upload
) AS upload
WHERE
upload > download
GROUP BY
ip_crans
"""
requete = """SELECT
round(total) AS total, machines.type AS type, machines.id AS id
FROM
(
(%s) UNION (%s)
)
AS
upload
SELECT 1
FROM exemptes
WHERE upload.ip_src <<= exemptes.ip_crans
AND upload.ip_dst <<= exemptes.ip_dest
)
AND NOT EXISTS
(
SELECT 1
FROM exemptes6
WHERE upload.mac_src = exemptes6.mac_crans
AND upload.ip_dst <<= exemptes6.ip_dest
)
GROUP BY
mac_src
) AS agregat
INNER JOIN
machines
machines
ON
machines.ip = upload.ip_crans
WHERE
total >= 250
machines.mac_addr = agregat.mac_src
GROUP BY
total, type, id
;""" % (upload4, upload6)
curseur.execute(requete)
machines.type, machines.id
ORDER BY
tot_upload;
"""
curseur.execute(requete, {'plage_ens':plage_ens, 'allone':NETs['all'][0], 'alltwo':NETs['all'][1], 'plage_ipv6':prefix['subnet'][0], 'appt':NETs['personnel-ens'][0],})
uploadeurs = curseur.fetchall()
......@@ -201,7 +174,7 @@ for elupload, eltype, elid in uploadeurs:
proprio = ldap.search('aid=%d'%elid, 'w')['adherent']
else:
continue
if len(proprio) != 1:
print 'Erreur : Proprio non trouvé (%s) %d'%(eltype, elid)
......@@ -212,12 +185,12 @@ for elupload, eltype, elid in uploadeurs:
# a vu les machines du proprio pour la dernière fois
####################################################
machines = proprio.machines()
macs_dates_chambres = []
for machine in machines:
if isinstance(machine, MachineFixe):
mac = machine.mac()
date, chambre = reperage_chambre(mac)
mac = machine.mac()
date, chambre = reperage_chambre(mac)
macs_dates_chambres.append([mac, date, chambre])
mdcf = tableau(macs_dates_chambres, ('mac', 'date', 'chambre'), (20, 21, 7), ('c', 'c', 'c'))
......
......@@ -12,11 +12,11 @@ DELETE FROM upload6 WHERE date< timestamp 'now' - interval '5 days';
-- DELETE FROM flood where date< timestamp 'now' - interval '2 days';
-- suppression complète des entrées
VACUUM;
VACUUM FULL;
-- réindexation des tables
REINDEX TABLE upload;
REINDEX TABLE upload6;
-- REINDEX TABLE virus;
-- REINDEX TABLE flood; -- flood n'a pas d'index
REINDEX TABLE p2p;
-- REINDEX TABLE p2p;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment