class CauldronToPlugin(Thread,Countable): def __init__(self,name,cauldronAddr,plugin,inFilter,log,outFilter=None): Thread.__init__(self,name="%s (in)" % (name)) Countable.__init__(self) self.daemon=True self.cauldronAddr=cauldronAddr self.plugin=plugin self.allowCache={} self.accu=set() self.inFilter=re.compile(inFilter) self.log=log if outFilter: self.outFilter=re.compile(outFilter) else: self.outFilter=None def run(self): self.running=True self.log("running") self.cauldron=CauldronReceiver(self.cauldronAddr,self) while self.running: self.cauldron.receive_shuttle() def handle_shuttle(self,shuttle): if not self.running: return for (label,value) in shuttle: try: allow=self.allowCache[label] except KeyError: self.count('new_labels_per_second',1) allow= (( self.inFilter.search(label)!=None) and (( self.outFilter==None or not ( self.outFilter.search(label))))) self.allowCache[label]=allow if allow: self.labels_allowed+=1 if allow: self.accu.add("%s=%s" % (label,value)) if len(self.accu)>0: try: databytes=(bytes('%s\n\n' % ('\n'.join(self.accu)),'utf-8')) self.plugin.write(databytes) self.count('bytes_per_second',len(databytes)) self.count('shuttles_per_second',1) self.count('records_per_second',len(self.accu)) self.accu.clear() except IOError: self.running=False def stop(self): self.running=False
class CauldronToPlugin(Thread, Countable): def __init__(self, name, cauldronAddr, plugin, log, inFilter, inValueFilter=None, outFilter=None, outValueFilter=None, loopProtected=False): Thread.__init__(self, name="%s (in)" % (name)) Countable.__init__(self) self.daemon = True self.cauldronAddr = cauldronAddr self.plugin = plugin self.allowCache = {} self.accu = set() self.inFilter = re.compile(inFilter) self.log = log self.loopProtected = loopProtected if outFilter: self.outFilter = re.compile(outFilter) else: self.outFilter = None if inValueFilter: self.inValueFilter = re.compile(inValueFilter) else: self.inValueFilter = None if outValueFilter: self.outValueFilter = re.compile(outValueFilter) else: self.outValueFilter = None def run(self): self.running = True self.log("running") self.cauldron = CauldronReceiver(self.cauldronAddr, self) while self.running: self.cauldron.receive_shuttle() def handle_shuttle(self, shuttle): if not self.running: return for (label, value) in shuttle: try: allow = self.allowCache[label] except KeyError: self.count('new_labels_per_second', 1) if self.loopProtected: allowLabel = self.inFilter.search(label) != None else: allowLabel = (((self.inFilter.search(label) != None) and (( (self.outFilter == None or not (self.outFilter.search(label) != None)))))) if self.inValueFilter == None: allowValueIn = True else: allowValueIn = self.inValueFilter.match(value) != None if self.outValueFilter == None: allowValueOut = True else: allowValueOut = self.outValueFilter.match(value) != None allow = allowLabel and allowValueIn and allowValueOut self.allowCache[label] = allow if allow: self.labels_allowed += 1 if allow: self.accu.add("%s=%s" % (label, value)) if len(self.accu) > 0: try: databytes = (bytes('%s\n\n' % ('\n'.join(self.accu)), 'utf-8')) self.plugin.write(databytes) self.count('bytes_per_second', len(databytes)) self.count('shuttles_per_second', 1) self.count('records_per_second', len(self.accu)) self.accu.clear() except IOError: self.running = False def stop(self): self.running = False