2 # Generate a traffic model from a traffic summary file
4 # Copyright (C) Catalyst IT Ltd. 2017
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 sys.path.insert(0, "bin/python")
23 from samba.emulate import traffic
25 from samba.logger import get_samba_logger
26 logger = get_samba_logger(name=__name__, level=20)
31 parser = argparse.ArgumentParser(description=__doc__,
32 formatter_class=argparse.RawDescriptionHelpFormatter)
33 parser.add_argument('-o', '--out',
34 help="write model here")
35 parser.add_argument('--dns-mode', choices=['inline', 'count'],
36 help='how to deal with DNS', default='count')
37 parser.add_argument('SUMMARY_FILE', nargs='*', type=argparse.FileType('r'),
39 help="read from this file (default STDIN)")
40 args = parser.parse_args()
43 error("No output file was specified to write the model to.")
44 error("Please specify a filename using the --out option.")
48 outfile = open(args.out, 'w')
50 error("could not open %s" % args.out)
54 if args.SUMMARY_FILE is sys.stdin:
55 info("reading from STDIN...")
60 dns_counts) = traffic.ingest_summaries(args.SUMMARY_FILE,
61 dns_mode=args.dns_mode)
63 model = traffic.TrafficModel()
64 info("learning model")
65 if args.dns_mode == 'count':
66 model.learn(conversations, dns_counts)
68 model.learn(conversations)