1
2
3
4
5
6
7
8
9
10
11 import socket
12 import time
13 import Globals
14 from Products.ZenUtils.Utils import zenPath
15 defaultInfile = zenPath("log/origsyslog.log")
16
17 from Products.ZenUtils.CmdBase import CmdBase
18
19 SYSLOG_PORT = socket.getservbyname('syslog', 'udp')
20
22
23
28
29
31 self.log.info("sending messages to host %s", self.host)
32 count = 0
33 start = time.time()
34 def linefilt(line):
35 line = line.strip()
36 return line and not line.startswith("#")
37 lines = filter(linefilt, open(self.options.infile).readlines())
38 rate = self.options.rate
39 nextsec = time.time() + .9
40 for line in lines:
41
42 if count%rate==0 and nextsec>time.time():
43 while nextsec>time.time(): pass
44 nextsec = time.time() + .9
45 count+=1
46 self.sock.sendto(line, (self.host, SYSLOG_PORT))
47 sendtime = time.time()-start
48 arate = count/sendtime
49 self.log.info("sent %d events in %.2f secs rate %.2f ev/sec",
50 count, time.time()-start, arate)
51
52
54 CmdBase.buildOptions(self)
55 self.parser.add_option('--infile',
56 dest='infile', default=defaultInfile,
57 help="file from which to draw events")
58
59 self.parser.add_option('--rate',
60 dest='rate', type="int", default=80,
61 help="events per sec to send")
62
63 self.parser.add_option('-H', '--host',
64 dest='host', default='localhost',
65 help="host to send to")
66
67
68 if __name__ == "__main__":
69 sender = ZenSendSyslog()
70 sender.run()
71