def clone(args): config = load_config_env(args.file, args.env) target = load_config_env(args.file, args.target) if config["token"] is None or config["token"] == "": raise Exception( "Token not provided, cannot retrieve information from the origin to clone" ) if target["token"] is None or target["token"] == "": raise Exception( "Token not provided, cannot retrieve information of the destination to override" ) if config["kind"] != target["kind"]: raise Exception("Origin and destination env types are not compatible") if config["kind"] == "monitor": origin = SdMonitorClient(config["token"], config["url"]) destination = SdMonitorClient(target["token"], target["url"]) ok = clone_all_monitor(origin, destination) if ok: print("Clone complete") if config["kind"] == "secure": origin = SdSecureClient(config["token"], config["url"]) origin = SdSecureClient(target["token"], target["url"]) ok = clone_all_secure(origin, destination)
def check(args): if not os.path.isdir(args.path): raise NotADirectoryError(f"{args.path} is not a correct directory") print("Checking if there are remote changes...") config = load_config_env(args.file, args.env) token = config["token"] kind = config["kind"] url = config["url"] if token is None or token == "": raise Exception("Token not provided, can't perform check") if kind == "monitor": something_changed = check_monitor(SdMonitorClient(token, url), args.path) exit(0 if not something_changed else 1) if kind == "secure": something_changed = check_secure(SdSecureClient(token, url), args.path) exit(0 if not something_changed else 1) print(f"unknown kind of remote environment: {kind}") exit(2)
def dashboards(args): config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token not provided, cannot retrieve dashboards") sdmonitor = SdMonitorClient(config["token"], config["url"]) get_dashboards(sdmonitor, args.ids, args.format)
def policy(args): config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token was not provided") if config["kind"] != "secure": raise Exception("Selected environment is not Sysdig Secure") sdsecure = SdSecureClient(config["token"], config["url"]) show_policies(sdsecure)
def user(args): config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token not provided, cannot delete a user") sdmonitor = SdMonitorClient(config["token"], config["url"]) res = delete_user(sdmonitor, email=args.email) if res == EXIT_CODES.OK: print(f"Deleted user {args.email}")
def policies(args): config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token not provided, cannot delete policies") if config["kind"] != "secure": raise Exception("Selected environment is not Sysdig Secure") sdsecure = SdSecureClient(config["token"], config["url"]) res = delete_policies(sdsecure, ids=args.ids) if res == EXIT_CODES.OK: print(f"Deleted policies: {args.ids}")
def dashboards(args): config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token not provided, cannot delete a dashboard") if config["kind"] != "monitor": raise Exception("Selected environment is not Sysdig Monitor") sdmonitor = SdMonitorClient(config["token"], config["url"]) res = delete_dashboards(sdmonitor, ids=args.ids) if res == EXIT_CODES.OK: print(f"Deleted dashboards: {args.ids}")
def user(args): config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token not provided, cannot create a user") sdmonitor = SdMonitorClient(config["token"], config["url"]) res = create_user(sdmonitor, email=args.email, first_name=args.first_name, last_name=args.last_name, system_role=args.system_role) if res == EXIT_CODES.OK: print(f"Created user {args.email}") else: print(f"There has been an error creating the user")
def dashboards(args): config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token not provided, cannot create a user") sdmonitor = SdMonitorClient(config["token"], config["url"]) if not os.path.isfile(args.input_file): raise Exception( f"File {args.input_file} does not exist or is not a file.") with open(args.input_file, "r") as file: res = create_dashboards_from_file(sdmonitor, file) if res == EXIT_CODES.OK: print("Dashboards created") else: print("Error creating dashboards")
def backup(args): if not os.path.isdir(args.path): raise NotADirectoryError(f"{args.path} is not a correct directory") config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token not provided, can't perform Backup") if config["kind"] == "monitor": sdmonitor = SdMonitorClient(config["token"], config["url"]) if backup_monitor(sdmonitor, args.path) != EXIT_CODES.OK: print("There has been an error creating the Monitor backup") return if config["kind"] == "secure": sdsecure = SdSecureClient(config["token"], config["url"]) if backup_secure(sdsecure, args.path) != EXIT_CODES.OK: print("There has been an error creating the Secure backup") return raise Exception(f"Unknown kind {config['kind']}")
def restore(args): if not os.path.isdir(args.path): raise NotADirectoryError(f"{args.path} is not a correct directory") config = load_config_env(args.file, args.env) if config["token"] is None: raise Exception("Token not provided, can't perform restore") if config["kind"] == "monitor": sdmonitor = SdMonitorClient(config["token"], config["url"]) if restore_monitor(sdmonitor, args.path, all_users=args.all_users) != EXIT_CODES.OK: print("There has been an error restoring Monitor") return if config["kind"] == "secure": sdsecure = SdSecureClient(config["token"], config["url"]) if restore_secure(sdsecure, args.path) != EXIT_CODES.OK: print("There has been an error restoring Secure") return raise Exception(f"Unknown kind {config['kind']}")
def dashboard(args): config = load_config_env(args.file, args.env) if config["token"] is None or config["token"] == "": raise Exception("Token was not provided") sdmonitor = SdMonitorClient(config["token"], config["url"]) show_dashboards(sdmonitor)