Exemple #1
0
 def register_args(self, parser):
     parser.add_argument("conf",
                         metavar="FILE",
                         nargs="+",
                         type=ConfFileType("r",
                                           "load",
                                           parse_profile=PARSECONF_LOOSE),
                         help="""
         The default configuration file(s) used to determine what base settings are "
         unnecessary to keep in the target file."""
                         ).completer = conf_files_completer
     parser.add_argument("--target",
                         "-t",
                         metavar="FILE",
                         type=ConfFileType("r+",
                                           "load",
                                           parse_profile=PARSECONF_STRICT),
                         help="""
         This is the local file that you with to remove the duplicate settings from.
         By default, this file will be read and the updated with a minimized version."""
                         ).completer = conf_files_completer
     grp1 = parser.add_mutually_exclusive_group()
     grp1.add_argument("--dry-run",
                       "-D",
                       default=False,
                       action="store_true",
                       help="""
         Enable dry-run mode.
         Instead of writing the minimizing the TARGET file, preview what what be removed in
         the form of a 'diff'.""")
     grp1.add_argument("--output",
                       type=ConfFileType("w",
                                         "none",
                                         parse_profile=PARSECONF_STRICT),
                       default=None,
                       help="""
         Write the minimized output to a separate file instead of updating TARGET.
         This can be use to preview changes if dry-run produces a large diff.
         This may also be helpful in other workflows."""
                       ).completer = conf_files_completer
     parser.add_argument("--explode-default",
                         "-E",
                         default=False,
                         action="store_true",
                         help="""
         Enable minimization across stanzas as well as files for special use-cases.
         This mode will not only minimize the same stanza across multiple config files,
         it will also attempt to minimize default any values stored in the [default] or global
         stanza as well.
         Example:  Trim out cruft in savedsearches.conf by pointing to
         etc/system/default/savedsearches.conf""")
     parser.add_argument("-k",
                         "--preserve-key",
                         action="append",
                         default=[],
                         help="""
         Specify a key that should be allowed to be a duplication but should be preserved
         within the minimized output.  For example, it may be desirable keep the
         'disabled' settings in the local file, even if it's enabled by default."""
                         )
Exemple #2
0
 def register_args(self, parser):
     parser.add_argument("conf1",
                         metavar="CONF1",
                         help="Left side of the comparison",
                         type=ConfFileType("r",
                                           "load",
                                           parse_profile=PARSECONF_MID_NC)
                         ).completer = conf_files_completer
     parser.add_argument("conf2",
                         metavar="CONF2",
                         help="Right side of the comparison",
                         type=ConfFileType("r",
                                           "load",
                                           parse_profile=PARSECONF_MID_NC)
                         ).completer = conf_files_completer
     parser.add_argument(
         "-o",
         "--output",
         metavar="FILE",
         type=argparse.FileType('w'),
         default=self.stdout,
         help="File where difference is stored.  Defaults to standard out.")
     parser.add_argument(
         "--comments",
         "-C",
         action="store_true",
         default=False,
         help=
         "Enable comparison of comments.  (Unlikely to work consistently)")
Exemple #3
0
 def register_args(self, parser):
     parser.add_argument(
         "conf",
         metavar="FILE",
         nargs="+",
         type=ConfFileType("r", "load", parse_profile=PARSECONF_MID),
         help="The source configuration file to pull changes from."
     ).completer = conf_files_completer
     parser.add_argument("--target",
                         "-t",
                         metavar="FILE",
                         type=ConfFileType("r+",
                                           "none",
                                           parse_profile=PARSECONF_STRICT),
                         default=ConfFileProxy("<stdout>", "w",
                                               self.stdout),
                         help="""
         Save the merged configuration files to this target file.
         If not provided. the the merged conf is written to standard output."""
                         ).completer = conf_files_completer
     parser.add_argument("--dry-run",
                         "-D",
                         default=False,
                         action="store_true",
                         help="""
         Enable dry-run mode.
         Instead of writing to TARGET, preview changes in 'diff' format.
         If TARGET doesn't exist, then show the merged file.""")
     parser.add_argument("--banner",
                         "-b",
                         default="",
                         help="""
         A banner or warning comment added to the top of the TARGET file.
         This is pften used to warn Splunk admins from editing an auto-generated file."""
                         )
Exemple #4
0
 def register_args(self, parser):
     parser.add_argument(
         "conf",
         metavar="CONF",
         nargs="+",
         type=ConfFileType("r", "load", parse_profile=PARSECONF_LOOSE),
         help=
         "The default configuration file(s) used to determine what base or settings are. "
         "The base settings determine what is unnecessary to repeat in target file."
     ).completer = conf_files_completer
     parser.add_argument(
         "--target",
         "-t",
         metavar="TARGET",
         type=ConfFileType("r+", "load", parse_profile=PARSECONF_STRICT),
         help=
         "The local file that you wish to remove duplicate settings from.  "
         "This file will be read from and then replaced with a minimized version."
     ).completer = conf_files_completer
     grp1 = parser.add_mutually_exclusive_group()
     grp1.add_argument(
         "--dry-run",
         "-D",
         default=False,
         action="store_true",
         help="Enable dry-run mode.  "
         "Instead of writing the minimizing the TARGET file, preview what would be removed "
         "the form of a 'diff'.")
     grp1.add_argument(
         "--output",
         type=ConfFileType("w", "none", parse_profile=PARSECONF_STRICT),
         default=None,
         help=
         "Write the minimized output to a separate file instead of updating TARGET."
     ).completer = conf_files_completer
     parser.add_argument(
         "--explode-default",
         "-E",
         default=False,
         action="store_true",
         help="Enable minimization across stanzas for special use-cases.  "
         "Helpful when dealing with stanzas downloaded from a REST endpoint or "
         "``btool list`` output.")
     parser.add_argument(
         "-k",
         "--preserve-key",
         action="append",
         default=[],
         help="Specify attributes that should always be kept.")
Exemple #5
0
    def register_args(self, parser):
        # type: (ArgumentParser) -> None
        parser.add_argument("conf", metavar="CONF", nargs="+",
                            type=ConfFileType("r", "load", parse_profile=PARSECONF_LOOSE),
                            help="Configuration file(s) to export settings from."
                            ).completer = conf_files_completer
        parser.add_argument("--output", "-t", metavar="FILE",
                            type=FileType("w"), default=sys.stdout,
                            help="Save the shell script output to this file.  "
                                 "If not provided, the output is written to standard output.")

        prsout = parser.add_argument_group("Output Control")

        '''
        prsout.add_argument("--syntax", choices=["curl", "powershell"],  # curl-windows?
                            default="curl",
                            help="Pick the output syntax mode.  "
                                 "Currently only 'curl' is supported.")
        '''
        prsout.add_argument("--disable-auth-output", action="store_true", default=False,
                            help="Turn off sample login curl commands from the output.")
        prsout.add_argument("--pretty-print", "-p", action="store_true", default=False,
                            help=dedent("""\
            Enable pretty-printing.
            Make shell output a bit more readable by splitting entries across lines."""))

        parsg1 = parser.add_mutually_exclusive_group(required=False)
        parsg1.add_argument("-u", "--update", action="store_true", default=False,
                            help="Assume that the REST entities already exist.  "
                                 "By default, output assumes stanzas are being created.")
        parsg1.add_argument("-D", "--delete", action="store_true", default=False,
                            help=dedent("""\
            Remove existing REST entities.  This is a destructive operation.
            In this mode, stanza attributes are unnecessary and ignored.
            NOTE:  This works for 'local' entities only; the default folder cannot be updated.
            """))

        parser.add_argument("--url", default="https://localhost:8089",
                            help="URL of Splunkd.  Default:  %(default)s")
        parser.add_argument("--app", default="$SPLUNK_APP",
                            help="Set the namespace (app name) for the endpoint")

        parser.add_argument("--user", help="Deprecated.  Use --owner instead.")
        parser.add_argument("--owner", default="nobody",
                            help="Set the object owner.  Typically, the default of 'nobody' is "
                                 "ideal if you want to share the configurations at the app-level.")
        parser.add_argument("--conf", dest="conf_type", metavar="TYPE",
                            help=dedent("""\
            Explicitly set the configuration file type.  By default, this is derived from CONF, but
            sometimes it's helpful to set this explicitly.  Can be any valid Splunk conf file type.
            Examples include: 'app', 'props', 'tags', 'savedsearches', etc."""))

        parser.add_argument("--extra-args", action="append",
                            help=dedent("""\
            Extra arguments to pass to all CURL commands.
            Quote arguments on the command line to prevent confusion between arguments to ksconf vs
            curl."""))
Exemple #6
0
    def register_args(self, parser):
        # type: (ArgumentParser) -> None
        parser.add_argument(
            "conf",
            metavar="CONF",
            nargs="+",
            type=ConfFileType("r", "load", parse_profile=PARSECONF_LOOSE),
            help="Configuration file(s) to export settings from."
        ).completer = conf_files_completer

        parser.add_argument("--conf",
                            dest="conf_type",
                            metavar="TYPE",
                            help=dedent("""\
            Explicitly set the configuration file type.  By default, this is derived from CONF, but
            sometimes it's helpful to set this explicitly. Can be any valid Splunk conf file type.
            Examples include: 'app', 'props', 'tags', 'savedsearches', etc.""")
                            )
        parser.add_argument(
            "-m",
            "--meta",
            action="append",
            help=
            "Specify one or more ``.meta`` files to determine the desired read & "
            "write ACLs, owner, and sharing for objects in the CONF file.")

        #add_splunkd_namespace(
        #    add_splunkd_access_args(parser.add_argument("Splunkd endpoint")))

        add_splunkd_namespace(add_splunkd_access_args(parser))

        parsg1 = parser.add_mutually_exclusive_group(required=False)
        '''
        parsg1.add_argument("-u", "--update", action="store_true", default=False,
                            help="Assume that the REST entities already exist.")
        parsg1.add_argument("--update-only", action="store_true", default=False,
                            help="Only update existing entities.  "
                                 "Non-existent entries will be skipped.")
        '''
        parsg1.add_argument("-D",
                            "--delete",
                            action="store_true",
                            default=False,
                            help=dedent("""\
            Remove existing REST entities.  This is a destructive operation.
            In this mode, stanza attributes are unnecessary.
            NOTE:  This works for 'local' entities only; the default folder cannot be updated.
            """))
Exemple #7
0
    def register_args(self, parser):
        parser.add_argument(
            "conf",
            metavar="FILE",
            nargs="+",
            help="The source configuration file(s) to collect settings from."
        ).completer = conf_files_completer
        parser.add_argument("--target",
                            "-t",
                            metavar="FILE",
                            type=ConfFileType("r+",
                                              "none",
                                              parse_profile=PARSECONF_STRICT),
                            default=ConfFileProxy("<stdout>", "w",
                                                  self.stdout),
                            help=dedent("""\
            Save the merged configuration files to this target file.
            If not provided, the merged conf is written to standard output.""")
                            ).completer = conf_files_completer

        # This is helpful when writing bash expressions like MyApp/{default,local}/props.conf;
        # when either default or local may not be present.
        parser.add_argument("--ignore-missing",
                            "-s",
                            default=False,
                            action="store_true",
                            help="Silently ignore any missing CONF files.")

        parser.add_argument("--dry-run",
                            "-D",
                            default=False,
                            action="store_true",
                            help=dedent("""\
            Enable dry-run mode.
            Instead of writing to TARGET, preview changes in 'diff' format.
            If TARGET doesn't exist, then show the merged file."""))
        parser.add_argument("--banner",
                            "-b",
                            default="",
                            help=dedent("""\
            A banner or warning comment added to the top of the TARGET file.
            Used to discourage Splunk admins from editing an auto-generated file."""
                                        ))
Exemple #8
0
 def register_args(self, parser):
     parser.set_defaults(mode="ask")
     parser.add_argument(
         "source",
         metavar="SOURCE",
         type=ConfFileType("r+", "load", parse_profile=PARSECONF_STRICT_NC),
         help="The source configuration file to pull changes from. "
         "Typically the :file:`local` conf file)"
     ).completer = conf_files_completer
     parser.add_argument("target",
                         metavar="TARGET",
                         type=ConfFileType("r+",
                                           "none",
                                           accept_dir=True,
                                           parse_profile=PARSECONF_STRICT),
                         help=dedent("""\
         Configuration file or directory to push the changes into.
         (Typically the :file:`default` folder)
         """)).completer = conf_files_completer
     grp1 = parser.add_mutually_exclusive_group()
     grp1.add_argument("--batch",
                       "-b",
                       action="store_const",
                       dest="mode",
                       const="batch",
                       help=dedent("""\
         Use batch mode where all configuration settings are automatically promoted.
         All changes are removed from source and applied to target.
         The source file will be removed, unless
         ``--keep-empty`` is used."""))
     grp1.add_argument("--interactive",
                       "-i",
                       action="store_const",
                       dest="mode",
                       const="interactive",
                       help=dedent("""\
         Enable interactive mode where the user will be prompted to approve
         the promotion of specific stanzas and attributes.
         The user will be able to apply, skip, or edit the changes being promoted."""
                                   ))
     parser.add_argument(
         "--force",
         "-f",
         action="store_true",
         default=False,
         help="Disable safety checks. "
         "Don't check to see if SOURCE and TARGET share the same basename.")
     parser.add_argument("--keep",
                         "-k",
                         action="store_true",
                         default=False,
                         help=dedent("""\
         Keep conf settings in the source file.
         All changes will be copied into the target file instead of being moved there.
         This is typically a bad idea since local always overrides default."""
                                     ))
     parser.add_argument("--keep-empty",
                         action="store_true",
                         default=False,
                         help=dedent("""\
         Keep the source file, even if after the settings promotions the file has no content.
         By default, SOURCE will be removed after all content has been moved into TARGET.
         Splunk will re-create any necessary local files on the fly."""))
    def register_args(self, parser):
        # type: (argparse.ArgumentParser) -> None
        parser.set_defaults(mode="ask")
        parser.add_argument("source", metavar="SOURCE",
                            type=ConfFileType("r+", "load", parse_profile=PARSECONF_STRICT_NC),
                            help="The source configuration file to pull changes from. "
                                 "(Typically the :file:`local` conf file)"
                            ).completer = conf_files_completer
        parser.add_argument("target", metavar="TARGET",
                            type=ConfFileType("r+", "none", accept_dir=True,
                                              parse_profile=PARSECONF_STRICT), help=dedent("""\
            Configuration file or directory to push the changes into.
            (Typically the :file:`default` folder)
            """)
                            ).completer = conf_files_completer
        grp1 = parser.add_mutually_exclusive_group()
        grp1.add_argument("--batch", "-b", action="store_const",
                          dest="mode", const="batch", help=dedent("""\
            Use batch mode where all configuration settings are automatically promoted.
            All changes are removed from source and applied to target.
            The source file will be removed unless
            ``--keep-empty`` is used."""))
        grp1.add_argument("--interactive", "-i",
                          action="store_const",
                          dest="mode", const="interactive", help=dedent("""\
            Enable interactive mode where the user will be prompted to approve
            the promotion of specific stanzas and attributes.
            The user will be able to apply, skip, or edit the changes being promoted."""))
        grp1.add_argument("--summary", "-s",
                          action="store_const",
                          dest="mode", const="summary",
                          help="Summarize content that could be promoted.")

        parser.add_argument("--verbose", action="store_true", default=False,
                            help="Enable additional output.")

        pg_ftr = parser.add_argument_group("Automatic filtering options", dedent("""\
            Include or exclude stanzas to promote using these filter options.
            Stanzas selected by these filters will be promoted.

            All filter options can be provided multiple times.
            If you have a long list of filters, they can be saved in a file and
            referenced using the special ``file://`` prefix.  One entry per line."""))
        pg_ftr.add_argument("--match", "-m",
                            choices=["regex", "wildcard", "string"],
                            default="wildcard",
                            help=dedent("""\
            Specify pattern matching mode.
            Defaults to 'wildcard' allowing for ``*`` and  ``?`` matching.
            Use 'regex' for more power but watch out for shell escaping.
            Use 'string' to enable literal matching."""))
        pg_ftr.add_argument("--ignore-case", action="store_true",
                            help=dedent("""\
            Ignore case when comparing or matching strings.
            By default matches are case-sensitive."""))
        pg_ftr.add_argument("--invert-match", "-v", action="store_true",
                            help=dedent("""\
            Invert match results.
            This can be used to prevent content from being promoted."""))
        pg_ftr.add_argument("--stanza", metavar="PATTERN", action="append", default=[],
                            help=dedent("""\
            Promote any stanza with a name matching the given pattern.
            PATTERN supports bulk patterns via the ``file://`` prefix."""))

        parser.add_argument("--force", "-f",
                            action="store_true", default=False,
                            help=
            "Disable safety checks. "
            "Don't check to see if SOURCE and TARGET share the same basename.")
        parser.add_argument("--keep", "-k",
                            action="store_true", default=False, help=dedent("""\
            Keep conf settings in the source file.
            All changes will be copied into the TARGET file instead of being moved there.
            This is typically a bad idea since local always overrides default."""))
        parser.add_argument("--keep-empty",
                            action="store_true", default=False, help=dedent("""\
            Keep the source file, even if after the settings promotions the file has no content.
            By default, SOURCE will be removed after all content has been moved into TARGET.
            Splunk will re-create any necessary local files on the fly."""))
Exemple #10
0
    def register_args(self, parser):
        # type: (argparse.ArgumentParser) -> None
        parser.add_argument("conf",
                            metavar="CONF",
                            help="Input conf file",
                            nargs="+",
                            type=ConfFileType("r",
                                              parse_profile=PARSECONF_MID_NC)
                            ).completer = conf_files_completer
        parser.add_argument(
            "-o",
            "--output",
            metavar="FILE",
            type=argparse.FileType('w'),
            default=self.stdout,
            help="File where the filtered results are written.  "
            "Defaults to standard out.")
        parser.add_argument(
            "--comments",
            "-C",
            action="store_true",
            default=False,
            help="Preserve comments.  Comments are discarded by default.")
        parser.add_argument("--verbose",
                            action="store_true",
                            default=False,
                            help="Enable additional output.")

        parser.add_argument(
            "--match",
            "-m",  # metavar="MODE",
            choices=["regex", "wildcard", "string"],
            default="wildcard",
            help=dedent("""\
            Specify pattern matching mode.
            Defaults to 'wildcard' allowing for ``*`` and  ``?`` matching.
            Use 'regex' for more power but watch out for shell escaping.
            Use 'string' to enable literal matching."""))
        parser.add_argument("--ignore-case",
                            "-i",
                            action="store_true",
                            help=dedent("""\
            Ignore case when comparing or matching strings.
            By default matches are case-sensitive."""))
        parser.add_argument("--invert-match",
                            "-v",
                            action="store_true",
                            help=dedent("""\
            Invert match results.
            This can be used to show what content does NOT match,
            or make a backup copy of excluded content."""))

        pg_out = parser.add_argument_group(
            "Output mode",
            dedent("""\
            Select an alternate output mode.
            If any of the following options are used, the stanza output is not shown.
            """))
        pg_out.add_argument(
            "--files-with-matches",
            "-l",
            action="store_true",
            help="List files that match the given search criteria")
        pg_om1 = pg_out.add_mutually_exclusive_group()
        pg_om1.add_argument("--count",
                            "-c",
                            action="store_true",
                            help="Count matching stanzas")
        pg_om1.add_argument("--brief",
                            "-b",
                            action="store_true",
                            help="List name of matching stanzas")

        pg_sel = parser.add_argument_group(
            "Stanza selection",
            dedent("""\
            Include or exclude entire stanzas using these filter options.

            All filter options can be provided multiple times.
            If you have a long list of filters, they can be saved in a file and referenced using
            the special ``file://`` prefix.  One entry per line."""))

        pg_sel.add_argument("--stanza",
                            metavar="PATTERN",
                            action="append",
                            default=[],
                            help=dedent("""
            Match any stanza who's name matches the given pattern.
            PATTERN supports bulk patterns via the ``file://`` prefix."""))

        pg_sel.add_argument("--attr-present",
                            metavar="ATTR",
                            action="append",
                            default=[],
                            help=dedent("""\
            Match any stanza that includes the ATTR attribute.
            ATTR supports bulk attribute patterns via the ``file://`` prefix."""
                                        ))
        '''# Add next
        pg_sel.add_argument("--attr-eq", metavar=("ATTR", "PATTERN"), nargs=2, action="append",
                            default=[],
                            help="""
            Match any stanza that includes an attribute matching the pattern.
            PATTERN supports the special ``file://filename`` syntax.""")
        '''
        ''' # This will be more difficult
        pg_sel.add_argument("--attr-ne",  metavar=("ATTR", "PATTERN"), nargs=2, action="append",
                            default=[],
                            help="""
            Match any stanza that includes an attribute matching the pattern.
            PATTERN supports the special ``file://`` syntax.""")
        '''

        pg_con = parser.add_argument_group(
            "Attribute selection",
            dedent("""\
            Include or exclude attributes passed through.
            By default, all attributes are preserved.
            Allowlist (keep) operations are preformed before blocklist (reject) operations."""
                   ))

        pg_con.add_argument("--keep-attrs",
                            metavar="WC-ATTR",
                            default=[],
                            action="append",
                            help=dedent("""\
            Select which attribute(s) will be preserved.
            This space separated list of attributes indicates what to preserve.
            Supports wildcards."""))

        pg_con.add_argument("--reject-attrs",
                            metavar="WC-ATTR",
                            default=[],
                            action="append",
                            help=dedent("""\
            Select which attribute(s) will be discarded.
            This space separated list of attributes indicates what to discard.
            Supports wildcards."""))