Example #1
0
SUBNET = '192.168.2.'
logPath = '/home/trafdata/net-acct.log'

#***************************************************

db = DATABASES['default']
conn = psycopg2.connect(('dbname = %s user = %s password = %s host = %s') % \
                        (db['NAME'], db['USER'], db['PASSWORD'], db['HOST']))
cur = conn.cursor()

if os.access(logPath, os.F_OK):
    os.rename(logPath, logPath + '.work')
    wfHandler = open(logPath + '.work', 'r')
    for line in wfHandler:
        line = line.split('\t')
        date = timestampFromDate(dateFromTimestamp(int(line[0])))
        srcIp = line[2]
        srcPort = int(line[3])
        dstIp = line[4]
        dstPort = int(line[5])
        byte = int(line[6])
        inByte = outByte = 0
        if SUBNET in srcIp:
            inByte = byte
            ip = srcIp
            port = dstPort
            flag = True
        elif SUBNET in dstIp:
            outByte = byte
            ip = dstIp
            port = srcPort
Example #2
0
 def __transformDateInRec(self, rec):
     rec['_date'] = utils.dateFromTimestamp(rec['_date'], False,
             'mm/dd/yyyy')
     return rec