def _run(): """Initializes the state for the script based on command line input.""" arg_parser = argparse.ArgumentParser() args = _setup_args(arg_parser) if args.logfile: c42api.set_log_file(args.logfile) if args.output or args.logfile: c42api.set_log_level(logging.DEBUG) else: c42api.set_log_level(logging.ERROR) server = argutil.server_from_args(args) is_json = args.format == 'json' params = { 'active': 'true', 'incBackupUsage': args.backup, 'incHistory': args.backup } with c42api.common.smart_open(args.output, overwrite=True) as out: if is_json: c42api.write_json( out, c42api.fetch_computers(server, params, insert_schema_version=True)) else: c42api.write_csv(out, c42api.fetch_computers( server, params, insert_schema_version=True), args.header, shallow=True)
def _run(): """Initializes the state for the script based on command line input.""" arg_parser = argparse.ArgumentParser() args = _setup_args(arg_parser) if args.logfile: c42api.set_log_file(args.logfile) if args.output or args.logfile: c42api.set_log_level(logging.DEBUG) else: c42api.set_log_level(logging.ERROR) server = argutil.server_from_args(args) is_json = args.format == 'json' with c42api.common.smart_open(args.output, overwrite=True) as out: if is_json: c42api.write_json(out, c42api.fetch_users(server)) else: c42api.write_csv(out, c42api.fetch_users(server), args.header, shallow=True)
def _run(): """Initializes the state for the script based on command line input.""" arg_parser = argparse.ArgumentParser() args = _setup_args(arg_parser) if args.logfile: c42api.set_log_file(args.logfile) if args.output or args.logfile: c42api.set_log_level(logging.DEBUG) else: c42api.set_log_level(logging.ERROR) server = argutil.server_from_args(args) is_json = args.format == 'json' params = {'active': 'true', 'incBackupUsage': args.backup, 'incHistory': args.backup} with c42api.common.smart_open(args.output, overwrite=True) as out: if is_json: c42api.write_json(out, c42api.fetch_computers(server, params, insert_schema_version=True)) else: c42api.write_csv(out, c42api.fetch_computers(server, params, insert_schema_version=True), args.header, shallow=True)
def _run(): """Initializes the state for the script based on command line input.""" arg_parser = argparse.ArgumentParser() args = _setup_args(arg_parser) if args.logfile: c42api.set_log_file(args.logfile) if args.output or args.logfile: c42api.set_log_level(logging.DEBUG) else: c42api.set_log_level(logging.ERROR) server = argutil.server_from_args(args) is_json = args.format == 'json' device_guids = c42api.devices(server, args.device) def generate_detection_events(): """ Since write_json() wants to take a generator and fetch_detection_events() returns tuples, where the detection events are an array in the tuple, we use this auxilary function to allow us to stream the events to write_json() """ event_filters = [ c42api.create_filter_by_utc_datetime(args.min_date, args.max_date) ] * len(device_guids) guids_and_filters = zip(device_guids, event_filters) for _, _, detection_events in c42api.fetch_detection_events( server, guids_and_filters): for event in detection_events: yield event with c42api.common.smart_open(args.output, overwrite=True) as out: if is_json: c42api.write_json(out, generate_detection_events()) else: c42api.write_csv(out, generate_detection_events(), args.header, shallow=True)
def _run(): """Initializes the state for the script based on command line input.""" arg_parser = argparse.ArgumentParser() args = _setup_args(arg_parser) if not args.device: raise ValueError("Device is required.") if args.format != 'custom' and not args.output: # Writing non-custom output to STDOUT, so boost the log message level. c42api.set_log_level(logging.ERROR) _outline(args) server = argutil.server_from_args(args) devices = c42api.devices(server, args.device) if len(devices) != 1: raise ValueError("*** THIS SCRIPT ONLY SUPPORTS A SINGLE DEVICE ***") events = c42api.calculate_delta(server, devices[0], args.date1, args.date2) with c42api.common.smart_open(args.output, overwrite=True) as out: if args.format == 'custom': _custom_output(out, events, allow_color=args.color) elif args.format == 'json': c42api.write_json(out, events) elif args.format == 'csv': c42api.write_csv(out, events, header=args.header)