action="store", dest="msg_level", choices=['error','warn','info','debug'], default='warn') parser.add_option("-l", "--logfile", help="set the fully qualified log file", action="store", dest="log_file", default=None) (options, args) = parser.parse_args() if options.run_as_daemon: # Do the necessary processing to spin off as a daemon command.daemonize('tlufm') else: # Make sure there is no other instances command.single_instance('tlufm') # Allow the user to CTRL-C application and shutdown cleanly signal.signal(signal.SIGINT, app_terminate) # CTRL-C signal.signal(signal.SIGTERM, app_terminate) # Process Termination if options.log_file is None: log_file = '$TEAL_LOG_DIR/tlufm.log' else: log_file = options.log_file try: # Set up the TEAL environment to get at the data required for logging
action="store", dest="msg_level", choices=['error','warn','info','debug'], default='warn') parser.add_option("-l", "--logfile", help="set the fully qualified log file", action="store", dest="log_file", default=None) (options, args) = parser.parse_args() if options.run_as_daemon: # Do the necessary processing to spin off as a daemon command.daemonize('teal_ll') else: # Make sure there is no other instances running command.single_instance('teal_ll') # Allow the user to CTRL-C application and shutdown cleanly signal.signal(signal.SIGINT, app_terminate) # CTRL-C if options.log_file is None: log_file = '$TEAL_LOG_DIR/teal_ll.log' else: log_file = options.log_file try: # Set up the TEAL environment to get at the data required for logging t = teal.Teal(None,
def main(): """ Main function entry point for application """ parser = optparse.OptionParser() # Common options parser.add_option('-c', '--configfile', help=_('fully qualified TEAL config file/directory - optional'), dest='config_file', default=None) parser.add_option('-l', '--logfile', help=_('fully qualified log file'), dest='log_file', default=None) parser.add_option('-m', '--msglevel', help=_('<debug | info | warning | error | critical> - optional [default: info]'), choices=['debug','info', 'warning', 'error', 'critical'], dest='msg_level', default='info') # Realtime options parser.add_option('', '--realtime', help=_('Run TEAL in realtime mode'), action='store_true', dest='realtime', default=False) parser.add_option('-d', '--daemon', help=_('run as a daemon'), action='store_true', dest='daemon', default=False) parser.add_option('-r', '--restart', help=_('<now | begin | recovery | lastproc> [default: recovery]'), choices=['now', 'begin', 'recovery', 'lastproc'], dest='restart', default=None) # Historic options parser.add_option('', '--historic', help=_('Run TEAL in historic mode'), action='store_true', dest='historic', default=False) parser.add_option('-q', '--query', type='string', action='store', dest='query', default='', help=_('Query parameters used to limit the range of events.')) parser.add_option('', '--commit', help=_('Commit alerts in historic mode [default=False]'), action='store_true', dest='commit', default=None) parser.add_option('', '--occurred', help=_('Use time occurred instead of time logged [default=False]'), action='store_true', dest='occurred', default=False) # Parse and validate options (options, args) = parser.parse_args() if args: parser.error(_("Arguments '{0}' cannot be specified").format(','.join(args))) if (options.historic and options.daemon): parser.error(_('--historic and --daemon are mutually exclusive')) if options.daemon or options.realtime: # Set default values mode = RUN_MODE_REALTIME # Test for invalid options combinations if options.query != '': parser.error(_('Query option is only valid in historic mode')) if options.commit is not None: parser.error(_('Commit option is only valid in historic mode')) else: options.commit = True if options.occurred: parser.error(_('Occurred option is only valid in historic mode')) else: # Set default values mode = RUN_MODE_HISTORIC if options.commit is None: options.commit = False # Test for invalid options combinations if options.restart is not None: parser.error(_('Restart option is only valid in realtime mode')) if options.daemon: # Do the necessary processing to spin off as a daemon command.daemonize('teal') else: if options.realtime: # Make sure there is no other instances command.single_instance('teal') # Allow the user to CTRL-C application and shutdown cleanly signal.signal(signal.SIGINT, app_terminate) # CTRL-C # Allow termination to shutdown cleanly signal.signal(signal.SIGTERM, app_terminate) # Process Termination try: # Create the TEAL object - it will start running autonomously Teal(options.config_file, logFile=options.log_file, msgLevel=options.msg_level, restart=options.restart, run_mode=mode, historic_qry=options.query, commit_alerts=options.commit, daemon_mode=options.daemon, use_time_occurred=options.occurred) # Wait for Teal to shutdown before exiting shutdown = registry.get_service(SERVICE_SHUTDOWN) shutdown.wait() except optparse.OptionValueError, ove: parser.error(ove)
action="store", dest="msg_level", choices=['error','warn','info','debug'], default='info') parser.add_option("-l", "--logfile", help="set the trace message level", action="store", dest="log_file", default=None) (options, args) = parser.parse_args() if options.run_as_daemon: # Do the necessary processing to spin off as a daemon command.daemonize('teal_bgq') else: # Allow the user to CTRL-C application and shutdown cleanly signal.signal(signal.SIGINT, app_terminate) # CTRL-C if options.log_file is None: log_file = '$TEAL_LOG_DIR/teal_bg.log' else: log_file = options.log_file # Set up the TEAL environment to get at the data required for logging t = teal.Teal(None, data_only=True, msgLevel=options.msg_level, logFile=log_file, daemon_mode=options.run_as_daemon)