Trees | Indices | Help |
|
---|
|
1 ########################################################################### 2 # 3 # This program is part of Zenoss Core, an open source monitoring platform. 4 # Copyright (C) 2007, Zenoss Inc. 5 # 6 # This program is free software; you can redistribute it and/or modify it 7 # under the terms of the GNU General Public License version 2 as published by 8 # the Free Software Foundation. 9 # 10 # For complete information please visit: http://www.zenoss.com/oss/ 11 # 12 ########################################################################### 13 import sys 14 import os 15 import socket 16 import time 17 import Globals 18 from Products.ZenUtils.Utils import zenPath 19 defaultInfile = zenPath("log/origsyslog.log") 20 21 from Products.ZenUtils.CmdBase import CmdBase 22 23 SYSLOG_PORT = socket.getservbyname('syslog', 'udp') 2426 2755 5629 CmdBase.__init__(self) 30 self.host = socket.gethostbyname(self.options.host) 31 self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)32 3335 self.log.info("sending messages to host %s", self.host) 36 count = 0 37 start = time.time() 38 def linefilt(line): 39 line = line.strip() 40 return line and not line.startswith("#")41 lines = filter(linefilt, open(self.options.infile).readlines()) 42 rate = self.options.rate 43 nextsec = time.time() + .9 44 for line in lines: 45 #self.log.debug(line) 46 if count%rate==0 and nextsec>time.time(): 47 while nextsec>time.time(): pass 48 nextsec = time.time() + .9 49 count+=1 50 self.sock.sendto(line, (self.host, SYSLOG_PORT)) 51 sendtime = time.time()-start 52 arate = count/sendtime 53 self.log.info("sent %d events in %.2f secs rate %.2f ev/sec", 54 count, time.time()-start, arate)58 CmdBase.buildOptions(self) 59 self.parser.add_option('--infile', 60 dest='infile', default=defaultInfile, 61 help="file from which to draw events") 62 63 self.parser.add_option('--rate', 64 dest='rate', type="int", default=80, 65 help="events per sec to send") 66 67 self.parser.add_option('-H', '--host', 68 dest='host', default='localhost', 69 help="host to send to")70 71 72 if __name__ == "__main__": 73 sender = ZenSendSyslog() 74 sender.run() 75
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:28 2007 | http://epydoc.sourceforge.net |