예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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}")
예제 #6
0
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}")
예제 #7
0
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}")
예제 #8
0
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")
예제 #9
0
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")
예제 #10
0
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']}")
예제 #11
0
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']}")
예제 #12
0
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)