Beispiel #1
0
 def __init__(self, usage, description, section=None, options=list(), actions=list()):
     ActionBase.__init__(self)
     self.settings = Settings(usage=usage, description=description, section=section)
     self.options = options
     self.actions = actions
     self.callback = None
     self._init(self.settings, self.options, self.actions)
Beispiel #2
0
class ActionMap(ActionBase):

    def __init__(self, usage, description, section=None, options=list(), actions=list()):
        ActionBase.__init__(self)
        self.settings = Settings(usage=usage, description=description, section=section)
        self.options = options
        self.actions = actions
        self.callback = None
        self._init(self.settings, self.options, self.actions)

    def parse(self, *args, **kwargs):
        ns = self.settings.parse(*args, **kwargs)
        action = self
        name = ns.popStack()
        while name is not None:
            action = action.children[name]
            name = ns.popStack()
        callback = action.callback
        if callback is None:
            raise ConfigureError("no action specified.  see --help for usage.")
        return callback(ns)
Beispiel #3
0
def run_main():
    settings = Settings(
        usage="[OPTIONS...] PIPELINE",
        description="Run the specified pipeline",
        section="run")
    try:
        settings.addLongOption("log-config",
            override="log config file", help="use logging configuration file FILE", metavar="FILE"
            )
        settings.addSwitch("d", "debug",
            override="debug", help="Print debugging information"
            )
        # load configuration
        ns = settings.parse()
        # create the Runner and run it
        runner = Runner()
        runner.configure(ns)
        return runner.run()
    except ConfigureError, e:
        print >> sys.stderr, "%s: %s" % (settings.appname, e)
Beispiel #4
0
def console_main():
    try:
        settings = Settings(usage="[OPTIONS...] [QUERY]")
        settings.addOption("H",
                           "--host",
                           "console",
                           "host",
                           help="Connect to terane server HOST",
                           metavar="HOST")
        settings.addOption("u",
                           "username",
                           "console",
                           "username",
                           help="Authenticate with username USER",
                           metavar="USER")
        settings.addOption("p",
                           "password",
                           "console",
                           "password",
                           help="Authenticate with password PASS",
                           metavar="PASS")
        settings.addSwitch("P",
                           "prompt-password",
                           "console",
                           "prompt password",
                           help="Prompt for a password")
        settings.addOption("e",
                           "execute",
                           "console",
                           "execute command",
                           help="Execute CMD after startup",
                           metavar="CMD")
        settings.addOption('',
                           "log-config",
                           "console",
                           "log config file",
                           help="use logging configuration file FILE",
                           metavar="FILE")
        settings.addSwitch("d",
                           "debug",
                           "console",
                           "debug",
                           help="Print debugging information")
        settings.load()
        console.configure(settings)
        return console.run()
    except ConfigureError, e:
        print >> sys.stderr, "%s: %s" % (settings.appname, e)
Beispiel #5
0
def console_main():
    try:
        settings = Settings(usage="[OPTIONS...] [QUERY]")
        settings.addOption("H", "--host", "console", "host",
            help="Connect to terane server HOST", metavar="HOST"
            )
        settings.addOption("u", "username", "console", "username",
            help="Authenticate with username USER", metavar="USER"
            )
        settings.addOption("p", "password", "console", "password",
            help="Authenticate with password PASS", metavar="PASS"
            )
        settings.addSwitch("P", "prompt-password", "console", "prompt password",
            help="Prompt for a password"
            )
        settings.addOption("e","execute", "console", "execute command",
            help="Execute CMD after startup", metavar="CMD"
            )
        settings.addOption('', "log-config", "console", "log config file",
            help="use logging configuration file FILE", metavar="FILE"
            )
        settings.addSwitch("d", "debug", "console", "debug",
            help="Print debugging information"
            )
        settings.load()
        console.configure(settings)
        return console.run()
    except ConfigureError, e:
        print >> sys.stderr, "%s: %s" % (settings.appname, e)
Beispiel #6
0
def search_main():
    settings = Settings(
        usage="[OPTIONS...] QUERY",
        description="Search a terane cluster",
        section="search")
    try:
        settings.addOption("H", "host",
            override="host", help="Connect to terane server HOST", metavar="HOST"
            )
        settings.addOption("u", "username",
            override="username", help="Authenticate with username USER", metavar="USER"
            )
        settings.addOption("p", "password",
            override="password", help="Authenticate with password PASS", metavar="PASS"
            )
        settings.addSwitch("P", "prompt-password",
            override="prompt password", help="Prompt for a password"
            )
        settings.addOption("s", "store",
            override="store", help="Search the specified STORE", metavar="STORE"
            )
        settings.addSwitch("v", "verbose",
            override="long format", help="Display more information about each event"
            )
        settings.addSwitch("r", "reverse",
            override="display reverse", help="Display events in reverse order (newest first)"
            )
        settings.addOption("l", "limit",
            override="limit", help="Display the first LIMIT results", metavar="LIMIT"
            )
        settings.addOption("f", "fields",
            override="display fields", help="Display only the specified FIELDS (comma-separated)", metavar="FIELDS"
            )
        settings.addOption("t", "timezone",
            override="timezone", help="Convert timestamps to specified timezone", metavar="TZ"
            )
        settings.addLongOption("log-config",
            override="log config file", help="use logging configuration file FILE", metavar="FILE"
            )
        settings.addSwitch("d", "debug",
            override="debug", help="Print debugging information"
            )
        # load configuration
        ns = settings.parse()
        # create the Searcher and run it
        searcher = Searcher()
        searcher.configure(ns)
        return searcher.run()
    except ConfigureError, e:
        print >> sys.stderr, "%s: %s" % (settings.appname, e)
Beispiel #7
0
def etl_main():
    settings = Settings(
        usage="[OPTIONS...] PIPELINE [ - | FILE...]",
        description="Process the specified ETL pipeline",
        section="etl")
    try:
        settings.addOption("H", "host",
            override="host", help="connect to syslog server HOST", metavar="HOST"
            )
        settings.addOption("f", "filters",
            override="filters", help="use filter pipeline SPEC", metavar="SPEC"
            )
        settings.addOption("s", "sink",
            override="sink", help="publish events to the specified STORE", metavar="STORE"
            )
        settings.addLongOption("log-config",
            override="log config file", help="use logging configuration file FILE", metavar="FILE"
            )
        settings.addSwitch("d", "debug",
            override="debug", help="Print debugging information"
            )
        # load configuration
        ns = settings.parse()
        # create the ETL and run it
        etl = ETL()
        etl.configure(ns)
        return etl.run()
    except ConfigureError, e:
        print >> sys.stderr, "%s: %s" % (settings.appname, e)
Beispiel #8
0
def search_main():
    try:
        settings = Settings(usage="[OPTIONS...] QUERY")
        settings.addOption("H", "host", "search", "host",
            help="Connect to terane server HOST", metavar="HOST"
            )
        settings.addOption("u", "username", "search", "username",
            help="Authenticate with username USER", metavar="USER"
            )
        settings.addOption("p", "password", "search", "password",
            help="Authenticate with password PASS", metavar="PASS"
            )
        settings.addSwitch("P", "prompt-password", "search", "prompt password",
            help="Prompt for a password"
            )
        settings.addOption("i", "use-indices", "search", "use indices",
            help="Search only the specified INDICES (comma-separated)", metavar="INDICES"
            )
        settings.addSwitch("v", "verbose", "search", "long format",
            help="Display more information about each event"
            )
        settings.addSwitch("r", "reverse", "search", "display reverse",
            help="Display events in reverse order (newest first)"
            )
        settings.addOption("l", "limit", "search", "limit",
            help="Display the first LIMIT results", metavar="LIMIT"
            )
        settings.addOption("f", "fields", "search", "display fields",
            help="Display only the specified FIELDS (comma-separated)", metavar="FIELDS"
            )
        settings.addOption("t", "timezone", "search", "timezone",
            help="Convert timestamps to specified timezone", metavar="TZ"
            )
        settings.addOption('', "log-config", "search", "log config file",
            help="use logging configuration file FILE", metavar="FILE"
            )
        settings.addSwitch("d", "debug", "search", "debug",
            help="Print debugging information"
            )
        # load configuration
        settings.load()
        # create the Searcher and run it
        searcher = Searcher()
        searcher.configure(settings)
        return searcher.run()
    except ConfigureError, e:
        print >> sys.stderr, "%s: %s" % (settings.appname, e)
Beispiel #9
0
def server_main():
    try:
        settings = Settings(usage="[OPTIONS...]")
        settings.addSwitch("d", "debug", "server", "debug",
            help="do not fork into the background, log to stderr",
            )
        settings.addOption("f", "log-file", "server", "log file",
            help="log messages to FILE (--debug overrides this)", metavar="FILE"
            )
        settings.addOption('', "log-config", "server", "log config file",
            help="use logging configuration file FILE", metavar="FILE"
            )
        settings.addOption("p", "pid-file", "server", "pid file",
            help="write PID to FILE", metavar="FILE"
            )
        # load settings from command line arguments, config file
        settings.load(needsconfig=True)
        # configure the server
        server = Server()
        server.configure(settings)
        # start the server
        status = server.run()
        return
    except (ConfigureError,ServerError), e:
        print >> sys.stderr, "%s: %s" % (settings.appname, e)
Beispiel #10
0
def grok_main():
    try:
        settings = Settings(usage="[OPTIONS...] COMMAND")
        # declare global options
        settings.addOption("H","host", "grok", "host",
            help="Connect to terane server HOST", metavar="HOST"
            )
        settings.addOption("u", "username", "grok", "username",
            help="Authenticate with username USER", metavar="USER"
            )
        settings.addOption("p", "password", "grok", "password",
            help="Authenticate with password PASS", metavar="PASS"
            )
        settings.addSwitch("P", "prompt-password", "grok", "prompt password",
            help="Prompt for a password"
            )
        settings.addOption('',"log-config", "grok", "log config file",
            help="use logging configuration file FILE", metavar="FILE"
            )
        settings.addSwitch("d","debug", "grok", "debug",
            help="Print debugging information"
            )
        # declare list-indices command
        settings.addSubcommand("list-indices", usage="",
            description="List available indices", handler=commands.ListIndices
            )
        # declare show-index command
        settings.addSubcommand("show-index", usage="[OPTIONS...] INDEX",
            description="Show index statistics", handler=commands.ShowIndex
            )
        # declare show-stats command
        subcommand = settings.addSubcommand("show-stats", usage="[OPTIONS...] STAT",
            description="Display server statistics", handler=commands.ShowStats
            )
        subcommand.addSwitch("r", "recursive", "show-stats", "recursive",
            help="Recursively display all stats"
            )
        # declare flush-stats command
        subcommand = settings.addSubcommand("flush-stats", usage="[OPTIONS...]",
            description="Reset server statistics", handler=commands.FlushStats
            )
        subcommand.addSwitch("a", "all", "flush-stats", "flush all",
            help="Reset persistent statistics as well"
            )
        # load configuration
        settings.load()
        # create the Searcher and run it
        handler = settings.getHandler()
        command = handler()
        command.configure(settings)
        return command.run()
    except ConfigureError, e:
        print >> sys.stderr, "%s: %s" % (settings.appname, e)