def monitor(file_name='.'): global file file = open(file_name, 'r') st_results = os.stat(file_name) st_size = st_results[6] file.seek(st_size) wm = WatchManager() notifier = Notifier(wm) wm.watch_transient_file(file_name, IN_MODIFY, ProcessTransientFile) print('now starting monitor %s' % file_name) notifier.loop()
def __init__(s, nodename): Thread.__init__(s) # Init logger s.log = logging.getLogger('Connector-{0}'.format(s.name)) # Init new database session s._sess = s.Session() # Init firewall tables s.f = Firewall(s.log, s._sess) # Init DNS daemon s.dns = DNSDaemon(s.log, s._sess) # Init database connection status table s.connections = ConnectionStatus(s.log, s._sess, nodename) # Make inotify watcher wm = WatchManager() ## OpenVPN status update handler class PUpdateStatus(ProcessEvent): ## Close file event method def process_IN_MODIFY(self, event): # Update status and firewall rules s.updateStatus() # Make notificator s.notifier = Notifier(wm, PUpdateStatus()) # Add OpenVPN status file watcher wm.watch_transient_file(OPENVPN_STATUS_FILE, IN_MODIFY, PUpdateStatus) s._sess.close()