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