#!/usr/bin/python
import MySQLdb,time,datetime
from socket import *
host = '172.16.0.45'
port = 514
addr = (host,port)
s = socket(AF_INET,SOCK_DGRAM)
s.bind(addr)
db = MySQLdb.connect('172.16.0.45','rsyslog','p@ssw0rd','Syslog')
cursor = db.cursor()
cursor.execute('select version()')
data = cursor.fetchone()
print 'data ver is ', data
Mothlist = {'Jan':1,'Feb':2,'Mar':3,'Apr':4,'May':5,'Jun':6,'Jul':7,'Aug':8,'Sep':9,'Oct':10,'Nov':11,'Dec':12}
while 1:
client_data,client_addr = s.recvfrom(8092)
print 'got connection from ',client_addr
if '172.16.201.' not in str(client_addr):
print 'can not connect from except 172.16.201.0/24',str(client_addr)
continue
#file = open('log.txt','a')
#file.write(client_data + '\n')
#file.close()
datalist = client_data.split(' ')
print 'datalist = ',datalist
Moth = datalist[0][-3:]
Year = datalist[2]
Day = datalist[1]
SWtime = datalist[3].split('+')[0]
templist = datalist[5].split('/')
print 'templist = ',templist
Facility = templist[0]
Priority = templist[1]
ReportTime = Year + '-' + str(Mothlist[Moth]) + '-' + Day +' '+ SWtime
RecvTime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
FromHost = datalist[4]
client_ip = client_addr[0]
SysLogTag = templist[2]
Message = ''
#print datalist
for m in range(0,len(datalist)):