Package Products :: Package ZenEvents :: Module zensendsyslog
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenEvents.zensendsyslog

 1  ############################################################################## 
 2  #  
 3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
 4  #  
 5  # This content is made available according to terms specified in 
 6  # License.zenoss under the directory where your Zenoss product is installed. 
 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   
21 -class ZenSendSyslog(CmdBase):
22 23
24 - def __init__(self):
25 CmdBase.__init__(self) 26 self.host = socket.gethostbyname(self.options.host) 27 self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
28 29
30 - def run(self):
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 #self.log.debug(line) 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
53 - def buildOptions(self):
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