#!/usr/bin/python3 # for configuration, please refer to fail2ban-cluster.conf import zmq,sys,time,signal,syslog from configparsing import ConfigParsing from daemon import daemon from publisher import Publisher global publisherconfig publisherconfig=ConfigParsing().Section(section='publisher') syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_AUTH) class f2bPublisherDaemon(daemon): def __sigTERMhandler(self,signum,frame): syslog.syslog("fail2ban-zmq-tools Publisher: Caught signal %d. Initiating shutdown..." % signum) self.quit() def run(self): syslog.syslog("fail2ban-zmq-tools Publisher starting") signal.signal(signal.SIGTERM,self.__sigTERMhandler) signal.signal(signal.SIGINT,self.__sigTERMhandler) self.publisher = Publisher(publisherconfig=publisherconfig) self.publisher.start() syslog.syslog("fail2ban-zmq-tools Publisher running. Main process waiting for termination signal. Threads working.") signal.pause() syslog.syslog("fail2ban-zmq-tools Publisher exiting.") def quit(self): signal.signal(signal.SIGTERM,signal.SIG_IGN) syslog.syslog("fail2ban-zmq-tools Publisher: Stopping threads...") self.publisher.join()
self.dq.put(["ok", jail, action, attacker]) sys.stdout.flush() # self.zmqRequester('BYEBYE','BYEBYE','BYEBYE','BYEBYE') sys.stdout.flush() def join(self, timeout=None): """ Stop the thread """ sys.stdout.flush() for i in range(len(self.ntPool)): self.dq.put(["stop", 0, 0, 0]) sys.stdout.flush() sys.stdout.flush() while self.ntPool: time.sleep(1) sys.stdout.flush() for index, the_thread in enumerate(self.ntPool): if the_thread.isAlive(): continue else: del self.ntPool[index] break self._stopevent.set() threading.Thread.join(self, timeout) if __name__ == "__main__": from configparsing import ConfigParsing monitorconfig = ConfigParsing().Section(section='monitor') monitoreo = Monitor(monitorconfig=monitorconfig)
#!/usr/bin/env python3 # for configuration, please refer to fail2ban-cluster.conf import zmq import sys import time import signal import syslog from configparsing import ConfigParsing from daemon import daemon from subscriber import Subscriber global subscriberconfig subscriberconfig = ConfigParsing().Section(section='subscriber') syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_AUTH) class f2bSubscriberDaemon(daemon): def __sigTERMhandler(self, signum, frame): syslog.syslog("fail2ban-zmq-tools Subscriber: Caught signal %d.\ Initiating shutdown..." % signum) self.quit() def run(self): syslog.syslog("fail2ban-zmq-tools Subscriber starting") signal.signal(signal.SIGTERM, self.__sigTERMhandler) signal.signal(signal.SIGINT, self.__sigTERMhandler) self.subscriber = Subscriber(subscriberconfig=subscriberconfig) self.subscriber.start() syslog.syslog("fail2ban-zmq-tools Subscriber running.\