def stop_tcp_logger(file_prefix='', remote_dir='', local_dir='.'): "Stop TCP logger (e.g. siftr on FreeBSD)" # get host type htype = get_type_cached(env.host_string) if htype == 'FreeBSD': run('sysctl net.inet.siftr.enabled=0') run('kldunload siftr') logfile = file_prefix + '_' + \ env.host_string.replace(':', '_') + '_siftr.log' elif htype == 'Linux': #run('killall web100_logger') run('killall web100-logger') logfile = file_prefix + '_' + \ env.host_string.replace(':', '_') + '_web10g.log' elif htype == 'Darwin': pass elif htype == 'CYGWIN': run('killall win-estats-logger') logfile = file_prefix + '_' + \ env.host_string.replace(':', '_') + '_web10g.log' if logfile == '': if remote_dir != '': logfile = remote_dir + '/' + logfile if file_prefix != '' or remote_dir != '': file_name = logfile else: file_name = bgproc.get_proc_log(env.host_string, 'tcplogger', '00') # add a small delay to allow logger to write data to disk completely time.sleep(0.5) # commented out: I think it may be confusing if the stats not match etc. # if htype == 'FreeBSD': # filter out control traffic from siftr log but # stats and flow list in last line of log is left unchanged #host = env.host_string.split(':')[0] #tmp_file = local('mktemp "tmp.XXXXXXXXXX"', capture=True) # run('cat %s | grep -v ",%s," > %s && mv %s %s' % \ # (file_name, host, tmp_file, tmp_file, file_name)) getfile(file_name, local_dir) bgproc.remove_proc(env.host_string, 'tcplogger', '00')
def stop_tcpdump(file_prefix='', remote_dir='', local_dir='.'): "Stop tcpdump instance on host" pid = bgproc.get_proc_pid(env.host_string, 'tcpdump', '0') with settings(warn_only=True): if pid != "": run('kill %s' % pid, pty=False) else: # get host type htype = get_type_cached(env.host_string) if htype == "FreeBSD" or htype == "Linux" or htype == 'Darwin': run('killall tcpdump') else: run('killall WinDump', pty=False) if file_prefix != "" or remote_dir != "": file_name = remote_dir + file_prefix + "_" + \ env.host_string.replace(":", "_") + ".dmp" else: file_name = bgproc.get_proc_log(env.host_string, 'tcpdump', '0') getfile(file_name, local_dir) bgproc.remove_proc(env.host_string, 'tcpdump', '0')
def stop_tcp_logger(file_prefix='', remote_dir='', local_dir='.'): "Stop TCP logger (e.g. siftr on FreeBSD)" # get host type htype = get_type_cached(env.host_string) if htype == 'FreeBSD': run('sysctl net.inet.siftr.enabled=0') run('kldunload siftr') logfile = file_prefix + '_' + \ env.host_string.replace(':', '_') + '_siftr.log' elif htype == 'Linux': # In fact, stop_tcp_logger is called just when Linux # and ttprobe are used (not with web10g) # but we check linux_tcp_logger type just in case # run('killall web100-logger') try: linux_tcp_logger = config.TPCONF_linux_tcp_logger except AttributeError: linux_tcp_logger = 'web10g' if linux_tcp_logger == 'ttprobe' or linux_tcp_logger == 'both': # flush ttprobe module buffer run('echo flush > /proc/net/ttprobe') time.sleep(0.5) run('echo finish > /proc/net/ttprobe') #run('pkill -f "cat /proc/net/ttprobe"') run('rmmod ttprobe') logfile = file_prefix + '_' + \ env.host_string.replace(':', '_') + '_ttprobe.log' # complete other tasks and exit from this function because ttprobe has differnt bgproce # name if file_prefix != '' or remote_dir != '': file_name = logfile else: file_name = bgproc.get_proc_log(env.host_string, 'tcploggerprobe', '00') getfile(file_name, local_dir) bgproc.remove_proc(env.host_string, 'tcploggerprobe', '00') return elif htype == 'Darwin': pass elif htype == 'CYGWIN': run('killall win-estats-logger') logfile = file_prefix + '_' + \ env.host_string.replace(':', '_') + '_web10g.log' if logfile == '': if remote_dir != '': logfile = remote_dir + '/' + logfile if file_prefix != '' or remote_dir != '': file_name = logfile else: file_name = bgproc.get_proc_log(env.host_string, 'tcplogger', '00') # add a small delay to allow logger to write data to disk completely time.sleep(0.5) # commented out: I think it may be confusing if the stats not match etc. # if htype == 'FreeBSD': # filter out control traffic from siftr log but # stats and flow list in last line of log is left unchanged #host = env.host_string.split(':')[0] #tmp_file = local('mktemp "tmp.XXXXXXXXXX"', capture=True) # run('cat %s | grep -v ",%s," > %s && mv %s %s' % \ # (file_name, host, tmp_file, tmp_file, file_name)) getfile(file_name, local_dir) bgproc.remove_proc(env.host_string, 'tcplogger', '00')