Exemple #1
0
    def setUp(self):
        print ""
        print "setting up ..."

        alignak_webui.app.config['HOST'] = '127.0.0.1'
        alignak_webui.app.config['PORT'] = 80
        alignak_webui.app.config['DEBUG'] = False

        alignak_webui.app.config['TESTING'] = True

        cfg_file = "settings.cfg"
        print 'Required configuration file:', cfg_file
        sett = Settings(alignak_webui.app)
        found_cfg_files = sett.read(cfg_file, {})
        if not found_cfg_files:
            print "Required configuration file not found."
            sys.exit(1)
        print 'Found configuration file:', cfg_file

        # Initialize backend communication ...
        frontend.configure(alignak_webui.app.config.get('ui.backend', 'http://localhost:5000'))
        print "Frontend: %s", frontend.url_endpoint_root

        # Configure users' management backend
        User.set_backend(frontend)

        helper = Helper(alignak_webui.app)

        self.app = alignak_webui.app.test_client()
def setup_module(module):
    print ("")  # this is to get a newline after the dots
    print ("setup_module before anything in this file")

    app.testing = True

    # Load application settings
    sett = Settings(app)
    found_cfg_files = sett.read("settings.cfg", {})

    # Initialize backend communication ...
    frontend.configure(app.config.get("ui.backend", "http://localhost:5000"))
    print "Frontend: %s", frontend.url_endpoint_root

    # Configure users' management backend
    User.set_backend(frontend)

    # Application current directory, find plugins directory ...
    app_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))

    # Load application plugins
    plugins = Plugins(app)
    plugins_dir = os.path.join(
        os.path.join(app_dir, manifest["name"].lower()), app.config.get("ui.plugins_dir", "plugins")
    )
    plugins.load_plugins(plugins_dir)

    helper = Helper(alignak_webui.app)
    def test_2(self):
        print 'Settings fixed (2)'

        # Get configuration from only one file ...
        print ("read configuration")
        cfg = Settings(
            os.path.join(os.path.abspath(os.path.dirname(__file__)), 'settings.fr')
        )
        found_cfg_files = cfg.read('Alignak-WebUI')
        assert found_cfg_files
        alignak_webui.set_app_config(cfg)

        # Application configuration is loaded
        self.config = alignak_webui.get_app_config()
        assert self.config
        # Not defined in settings.fr
        assert self.config.get('alignak_backend', 'default_value') == 'default_value'
        # Defined in settings.fr
        assert self.config.get('locale', 'en_US') == 'fr_FR'
        # Variable defined in the settings.cfg test file ...
        assert self.config.get('test_mode') == '1'

        # Alignak-WebUI object is initialized
        self.alignak_webui = get_app_webui()
        assert self.alignak_webui
Exemple #4
0
def setup_module(module):
    print ("") # this is to get a newline after the dots
    print ("setup_module before anything in this file")

    alignak_webui.app.config['HOST'] = '127.0.0.1'
    alignak_webui.app.config['PORT'] = 80
    alignak_webui.app.config['DEBUG'] = False

    alignak_webui.app.config['TESTING'] = True

    # Load application settings
    sett = Settings(app)
    found_cfg_files = sett.read("settings.cfg", {})

    # Initialize backend communication ...
    frontend.configure(app.config.get('ui.backend', 'http://localhost:5000'))
    print "Frontend: %s", frontend.url_endpoint_root

    # Configure users' management backend
    User.set_backend(frontend)

    # Application current directory, find plugins directory ...
    app_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))

    # Load application plugins
    plugins = Plugins(app)
    plugins_dir = os.path.join(
        os.path.join(app_dir, manifest['name'].lower()),
        app.config.get('ui.plugins_dir', 'plugins')
    )
    plugins.load_plugins(plugins_dir)
    def test_2(self):
        print('Settings fixed (2)')

        # Get configuration from only one file ...
        print("read configuration")
        cfg = Settings(
            os.path.join(os.path.abspath(os.path.dirname(__file__)),
                         'settings.fr'))
        found_cfg_files = cfg.read('Alignak-WebUI')
        assert found_cfg_files
        alignak_webui.set_app_config(cfg)

        # Application configuration is loaded
        self.config = alignak_webui.get_app_config()
        assert self.config
        # Not defined in settings.fr
        assert self.config.get('alignak_backend',
                               'default_value') == 'default_value'
        # Defined in settings.fr
        assert self.config.get('locale', 'en_US') == 'fr_FR'
        # Variable defined in the settings.cfg test file ...
        assert self.config.get('test_mode') == '1'

        # Alignak-WebUI object is initialized
        self.alignak_webui = get_app_webui()
        assert self.alignak_webui
Exemple #6
0
def setup_module(module):
    print ("")

    # Get configuration from only one file ...
    print ("read configuration")
    cfg = Settings("settings.cfg")
    found_cfg_files = cfg.read('Alignak-WebUI')
    assert found_cfg_files
    set_app_config(cfg)
Exemple #7
0
def setup_module():
    print("")

    # Get configuration from only one file ...
    print("read configuration")
    cfg = Settings("settings.cfg")
    found_cfg_files = cfg.read('Alignak-WebUI')
    assert found_cfg_files
    set_app_config(cfg)
Exemple #8
0
def setup_module(module):
    print ("")

    # Get configuration from only one file ...
    print ("read configuration")
    cfg = Settings(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'settings.cfg'))
    found_cfg_files = cfg.read('Alignak-WebUI')
    assert found_cfg_files
    set_app_config(cfg)
Exemple #9
0
def setup_module(module):
    print("")

    # Get configuration from only one file ...
    print("read configuration")
    cfg = Settings(
        os.path.join(os.path.abspath(os.path.dirname(__file__)),
                     'settings.cfg'))
    found_cfg_files = cfg.read('Alignak-WebUI')
    assert found_cfg_files
    set_app_config(cfg)
Exemple #10
0
    def test_2_found_3(self):
        print ''

        # Absolute file path - missing flask section
        cfg_file = os.path.dirname(os.path.abspath(__file__)) + "/test_settings2.cfg"
        print 'Required configuration file:', cfg_file
        sett = Settings(alignak_webui.app)
        found_cfg_files = sett.read(cfg_file, {})
        print 'Found:', found_cfg_files
        print alignak_webui.app.config
        self.assert_('HOST' in alignak_webui.app.config)
        self.assert_('PORT' in alignak_webui.app.config)
        self.assert_('SECRET_KEY' in alignak_webui.app.config)
        self.assert_(found_cfg_files)
Exemple #11
0
    def test_2_found(self):
        # Relative file path
        cfg_file = "settings.cfg"
        print('Required configuration file:', cfg_file)
        # Normal use case ... default files and application name ...
        # And get config object ...
        app_config = Settings(cfg_file)
        found_cfg_files = app_config.read('Alignak-WebUI')
        print('Found:', found_cfg_files)
        assert found_cfg_files

        print(app_config)
        self.assert_('about_name' in app_config)
        self.assert_(app_config['about_name'] == 'Alignak-WebUI')
Exemple #12
0
    def test_2_found(self):
        print ''

        # Relative file path
        cfg_file = "test_settings.cfg"
        print 'Required configuration file:', cfg_file
        sett = Settings(alignak_webui.app)
        found_cfg_files = sett.read(cfg_file, {})
        print 'Found:', found_cfg_files
        print alignak_webui.app.config
        self.assert_('HOST' in alignak_webui.app.config)
        self.assert_('PORT' in alignak_webui.app.config)
        self.assert_('SECRET_KEY' in alignak_webui.app.config)
        self.assert_(len(alignak_webui.app.config) > 10)
        self.assert_(found_cfg_files)
    def test_2_found(self):
        print ''

        # Relative file path
        cfg_file = "settings.cfg"
        print 'Required configuration file:', cfg_file
        ### Normal use case ... default files and application name ...
        # And get config object ...
        app_config = Settings(cfg_file)
        found_cfg_files = app_config.read('Alignak-WebUI')
        print 'Found:', found_cfg_files
        assert found_cfg_files

        print app_config
        self.assert_('about_name' in app_config)
        self.assert_(app_config['about_name'] == 'Alignak-WebUI')
Exemple #14
0
    def setUp(self):
        print ""
        print "setting up ..."

        alignak_webui.app.config['HOST'] = '127.0.0.1'
        alignak_webui.app.config['PORT'] = 80
        alignak_webui.app.config['DEBUG'] = False

        alignak_webui.app.config['TESTING'] = True

        cfg_file = "settings.cfg"
        print 'Required configuration file:', cfg_file
        sett = Settings(alignak_webui.app)
        found_cfg_files = sett.read(cfg_file, {})
        if not found_cfg_files:
            print "Required configuration file not found."
            sys.exit(1)
        print 'Found configuration file:', cfg_file

        self.helper = Helper(alignak_webui.app)
Exemple #15
0
    def setUp(self):
        print ""
        print "setting up ..."

        alignak_webui.app.config["HOST"] = "127.0.0.1"
        alignak_webui.app.config["PORT"] = 80
        alignak_webui.app.config["DEBUG"] = False

        alignak_webui.app.config["TESTING"] = True

        sett = Settings(alignak_webui.app)
        found_cfg_files = sett.read("settings.cfg", {})

        self.helper = Helper(alignak_webui.app)

        # Initialize backend communication ...
        frontend.configure(alignak_webui.app.config.get("ui.backend", "http://localhost:5000"))
        print "Frontend: %s", frontend.url_endpoint_root

        # Configure users' management backend
        User.set_backend(frontend)
Exemple #16
0
    def test_1_not_found(self):
        print ''
        print 'test login/logout process'

        # Relative file path
        cfg_file = "settings2.cfg"
        print 'Required configuration file:', cfg_file
        sett = Settings(alignak_webui.app)
        found_cfg_files = sett.read(cfg_file, {})
        print 'Found:', found_cfg_files
        self.assert_(found_cfg_files == None)

        # Absolute file path
        cfg_file = os.path.dirname(os.path.abspath(__file__)) + "/settings.cfg"
        print 'Required configuration file:', cfg_file
        sett = Settings(alignak_webui.app)
        found_cfg_files = sett.read(cfg_file, {})
        print 'Found:', found_cfg_files
        self.assert_(found_cfg_files == None)

        # Absolute file path - bad formed file
        cfg_file = os.path.dirname(os.path.abspath(__file__)) + "/test_settings.py"
        print 'Required configuration file:', cfg_file
        sett = Settings(alignak_webui.app)
        found_cfg_files = sett.read(cfg_file, {})
        print 'Found:', found_cfg_files
        self.assert_(found_cfg_files == None)
Exemple #17
0
def load_config(app=None, cfg_filenames=None):
    # pylint: disable=unused-argument
    """
    Load plugin configuration
    """
    global hosts_parameters, hosts_filenames

    if not cfg_filenames:
        cfg_filenames = hosts_filenames
    else:
        hosts_filenames = cfg_filenames

    logger.info("Read plugin configuration file: %s", cfg_filenames)

    # Read configuration file
    hosts_parameters = Settings(cfg_filenames)
    config_file = hosts_parameters.read('hosts')
    logger.info("Plugin configuration read from: %s", config_file)
    if not hosts_parameters:
        return False
    logger.info("Plugin configuration: %s", hosts_parameters)
    return True
Exemple #18
0
    def test_1_found_not_found(self):
        print('test configuration file')

        # Default configuration - not found because of test directory location !
        print('Search default configuration file ...')
        found_cfg_files = Settings().read(None)
        print('Found:', found_cfg_files)
        assert found_cfg_files is None
        # Normal use case ... default files and application name ...
        # But ! do not get config object ...
        found_cfg_files = Settings().read('Alignak-WebUI')
        print('Found:', found_cfg_files)
        assert found_cfg_files

        # Relative file path
        cfg_file = "settings.cfg"
        print('Required configuration file:', cfg_file)
        found_cfg_files = Settings(cfg_file).read(None)
        print('Found:', found_cfg_files)
        assert found_cfg_files is None
        found_cfg_files = Settings(cfg_file).read('Alignak-WebUI')
        print('Found:', found_cfg_files)
        assert found_cfg_files

        # Absolute file path
        cfg_file = os.path.dirname(os.path.abspath(__file__)) + "/settings.cfg"
        print('Required configuration file:', cfg_file)
        found_cfg_files = Settings(cfg_file).read(None)
        print('Found:', found_cfg_files)
        assert found_cfg_files is None
        found_cfg_files = Settings(cfg_file).read('Alignak-WebUI')
        print('Found:', found_cfg_files)
        assert found_cfg_files

        # Absolute file path - bad formed file
        cfg_file = os.path.dirname(
            os.path.abspath(__file__)) + "/test_bad_settings.txt"
        print('Required configuration file:', cfg_file)
        found_cfg_files = Settings(cfg_file).read(None)
        print('Found:', found_cfg_files)
        assert found_cfg_files is None
        found_cfg_files = Settings(cfg_file).read('Alignak-WebUI')
        print('Found:', found_cfg_files)
        assert found_cfg_files is None
Exemple #19
0
logger = getLogger(__pkg_name__)

cfg_file = None

# Test mode for the application
if os.environ.get('TEST_WEBUI'):
    print("Application is in test mode")
else:  # pragma: no cover - tests are run in test mode...
    print("Application is in production mode")

if os.environ.get('ALIGNAK_WEBUI_CONFIGURATION_FILE'):
    cfg_file = os.environ.get('ALIGNAK_WEBUI_CONFIGURATION_FILE')
    print("Application configuration file name from environment: %s" % cfg_file)

# Read configuration file
app_config = Settings(cfg_file)
config_file = app_config.read(manifest['name'])
print("Configuration read from: %s" % config_file)
if not app_config:  # pragma: no cover, should never happen
    print("Required configuration file not found.")
    exit(1)

# Store application name in the configuration
app_config['name'] = manifest['name']

# Debug mode for the application (run Bottle in debug mode)
app_config['debug'] = (app_config.get('debug', '0') == '1')
print("Application debug mode: %s" % app_config['debug'])

if __name__ != "__main__":
    # Make the configuration available globally for the package
Exemple #20
0
def main():
    args = docopt(__doc__, help=True, options_first=True, version=manifest['version'])

    # Set application logger name
    app.logger_name = __pkg_name__

    # Set logging options for the application
    logger = logging.getLogger(app.logger_name)
    logger.setLevel(logging.WARNING)

    # Create a console handler, add a formatter and set level to DEBUG
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    ch.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))

    # Add console handler to logger
    app.logger.addHandler(ch)

    if args['--debug']:
        app.logger.setLevel(logging.DEBUG)
        app.debug = True
        app.config['DEBUG'] = True
    elif args['--verbose']:
        app.logger.setLevel(logging.INFO)

    # Set and read configuration file
    cfg_file = args['--config']
    print 'Required configuration file:', cfg_file
    sett = Settings(app)
    found_cfg_files = sett.read(cfg_file, settings)
    if not found_cfg_files:
        print "Required configuration file not found."
        sys.exit(1)
    print 'Found configuration file:', cfg_file

    # Set logs file
    if args['--logs'] != 'no application log':
        # Store logs in a daily file, keeping 6 days along ... as default!
        # Default configuration may be set in configuration file, section [logs]
        fh = TimedRotatingFileHandler(
            filename=args['--logs'],
            when=settings.get('logs.when', 'D'),
            interval=int(settings.get('logs.interval', 1)),
            backupCount=int(settings.get('logs.backupCount', 6))
        )

        fh.setFormatter(logging.Formatter(
            settings.get('logs.formatter', '[%(asctime)s] - %(name)s - %(levelname)s - %(message)s')
        ))
        app.logger.addHandler(fh)
        print "%s logs stored in rotating file: %s" % (manifest['name'].lower(), args['--logs'])

    if args['--access'] != 'no access log':
        # Store Werkzeug logs  in a daily file, keeping 6 days along ... as default!
        # Default configuration may be set in configuration file, section [logs]
        # Store logs in a daily file, keeping 6 days along ... as default!
        # Default configuration may be set in configuration file, section [logs]
        fh = TimedRotatingFileHandler(
            filename=args['--access'],
            when=settings.get('logs.when', 'D'),
            interval=int(settings.get('logs.interval', 1)),
            backupCount=int(settings.get('logs.backupCount', 6))
        )

        fh.setFormatter(logging.Formatter(
            settings.get('logs.formatter', '[%(asctime)s] - %(name)s - %(levelname)s - %(message)s')
        ))

        logger = logging.getLogger('werkzeug')
        logger.addHandler(fh)
        # Also add the handler to Flask's logger for cases
        #  where Werkzeug isn't used as the underlying WSGI server.
        # app.logger.addHandler(fh)
        # Uncommenting this line makes the application log also available in the access logs file.
        print "server logs stored in rotating file: %s" % args['--access']

    try:
        # Update application manifest
        manifest['fmw_name'] = settings['framework.name']
        manifest['fmw_version'] = settings['framework.version']
        manifest['webui_logo'] = settings.get(
            'ui.webui_logo', '/static/images/logo_webui.png'
        )
        manifest['footer_logo'] = settings.get(
            'ui.footer_logo', '/static/images/logo_webui_xxs.png'
        )
        manifest['company_logo'] = settings.get(
            'ui.company_logo', '/static/images/default_company.png'
        )
        manifest['login_text'] = settings['ui.welcome_text']

        # Application banner in log
        app.logger.info(
            "--------------------------------------------------------------------------------"
        )
        app.logger.info("%s, version %s", manifest['name'], manifest['version'])
        app.logger.info("Copyright %s", manifest['copyright'])
        app.logger.info("License %s", manifest['license'])
        app.logger.info(
            "--------------------------------------------------------------------------------"
        )
        app.logger.debug("Doc: %s", manifest['doc'])
        app.logger.debug("Release notes: %s", manifest['release'])
        app.logger.debug(
            "--------------------------------------------------------------------------------"
        )
        app.logger.debug("Framework: %s, version %s", manifest['fmw_name'], manifest['fmw_version'])
        app.logger.debug(
            "--------------------------------------------------------------------------------"
        )

        # Application configuration in log
        app.logger.info("Configuration file searched in %s", [cfg_file])
        app.logger.info("Configuration files found: %s", found_cfg_files)
        app.logger.info("Application settings: %s", app.config)

        if args['<command>'] == 'start':
            # Initialize backend communication ...
            frontend.configure(app.config.get('ui.backend', 'http://localhost:5000'))
            app.logger.info("Backend used: %s", frontend.url_endpoint_root)

            # Configure users' management backend
            User.set_backend(frontend)

            # Application current directory
            app_dir = os.path.abspath(os.path.dirname(__file__))

            # Load application plugins
            plugins = Plugins(app)
            plugins_dir = os.path.join(
                os.path.join(app_dir, manifest['name'].lower()),
                app.config.get('ui.plugins_dir', 'plugins')
            )
            plugins.load_plugins(plugins_dir)

            app.run(
                host=app.config['HOST'],
                port=app.config['PORT'],
                debug=app.config['DEBUG']
            )
    except Exception as e:
        print("Command '%s' failed, exception: %s / %s", args['<command>'], type(e), str(e))
        app.logger.error("failed to launch command '%s'", args['<command>'])
        app.logger.error("Back trace of this kill: %s", traceback.format_exc())
        sys.exit(3)
Exemple #21
0
def main():  # pragma: no cover, not mesured by coverage!
    """
        Called when this module is started from shell
    """
    global cfg_file, app_config, app_webui

    # ----------------------------------------------------------------------------------------------
    # Command line parameters
    if __name__ == "__main__":  # pragma: no cover, not mesured by coverage!
        try:
            args = docopt(__doc__, version=manifest['version'])
        except DocoptExit:
            print "Command line parsing error"
            exit(64)
    else:
        args = {
            '--debug': False,
            '--backend': None,
            '--hostname': None,
            '--port': None,
            '--exit': False
        }

    # Application settings
    # ----------------------------------------------------------------------------------------------
    # Configuration file path in command line parameters
    if '<cfg_file>' in args:
        cfg_file = args['<cfg_file>']

        if cfg_file and isinstance(cfg_file, list):
            cfg_file = cfg_file[0]

        # Read configuration file
        app_config = Settings(cfg_file)
        new_config_file = app_config.read(manifest['name'])
        print "Configuration read from: %s" % new_config_file
        if not app_config:  # pragma: no cover, should never happen
            print "Required configuration file not found."
            exit(1)

    # Store application name in the configuration
    app_config['name'] = manifest['name']

    if '--debug' in args and args['--debug']:  # pragma: no cover, not mesured by coverage!
        app_config['debug'] = '1'
        print "Application is in debug mode from command line"

    if os.environ.get('WEBUI_DEBUG'):  # pragma: no cover, not mesured by coverage!
        app_config['debug'] = '1'
        print "Application is in debug mode from environment"

    # Applications backend URL
    if args['--backend']:  # pragma: no cover, not mesured by coverage!
        app_config['alignak_backend'] = args['--backend']

    # WebUI server configuration
    if args['--hostname']:  # pragma: no cover, not mesured by coverage!
        app_config['host'] = args['--hostname']
    if args['--port']:  # pragma: no cover, not mesured by coverage!
        app_config['port'] = args['--port']

    # Make the configuration available globally for the package
    set_app_config(app_config)

    # Make the application available globally for the package
    app_webui = set_app_webui(WebUI())

    try:
        logger.info(
            "--------------------------------------------------------------------------------"
        )
        logger.info(
            "%s, listening on %s:%d (debug mode: %s)",
            app_config.get('name', 'Test'),
            app_config.get('host', '127.0.0.1'), int(app_config.get('port', '8868')),
            app_config.get('debug', '0') == '1'
        )
        logger.info(
            "%s, using applications backend on %s",
            app_config.get('name', 'Test'),
            app_config['alignak_backend']
        )
        logger.info(
            "--------------------------------------------------------------------------------"
        )

        if args['--exit']:
            print "Application exit because of command line parameter"
            exit(99)

        # Run application server...
        run(
            app=webapp,
            host=app_config.get('host', '127.0.0.1'),
            port=int(app_config.get('port', 8868)),
            debug=(app_config.get('debug', '0') == '1'),
            server=app_config.get('http_backend', 'cherrypy')
        )
    except Exception as e:
        logger.error("Application run failed, exception: %s / %s", type(e), str(e))
        logger.info("Backtrace: %s", traceback.format_exc())
        logger.info("stopping backend livestate thread...")
        exit(2)
Exemple #22
0
logger = getLogger(__pkg_name__)

cfg_file = None

# Test mode for the application
if os.environ.get('TEST_WEBUI'):
    print "Application is in test mode"
else:
    print "Application is in production mode"

if os.environ.get('TEST_WEBUI_CFG'):
    cfg_file = os.environ.get('TEST_WEBUI_CFG')
    print "Application configuration file name from environment: %s" % cfg_file

# Read configuration file
app_config = Settings(cfg_file)
config_file = app_config.read(manifest['name'])
print "Configuration read from: %s" % config_file
if not app_config:  # pragma: no cover, should never happen
    print "Required configuration file not found."
    exit(1)

# Store application name in the configuration
app_config['name'] = manifest['name']

# Debug mode for the application (run Bottle in debug mode)
app_config['debug'] = (app_config.get('debug', '0') == '1')
print "Application debug mode: %s" % app_config['debug']

if __name__ != "__main__":
    # Make the configuration available globally for the package
Exemple #23
0
def main():  # pragma: no cover, not mesured by coverage!
    # pylint: disable=redefined-variable-type, global-statement
    """
        Called when this module is started from shell
    """
    global cfg_file, app_config, app_webui

    # ----------------------------------------------------------------------------------------------
    # Command line parameters
    args = {
        '--debug': False,
        '--backend': None,
        '--hostname': None,
        '--port': None,
        '--exit': False
    }

    if __name__ == "__main__":  # pragma: no cover, not mesured by coverage!
        try:
            args = docopt(__doc__, version=manifest['version'])
        except DocoptExit:
            print("Command line parsing error")
            exit(64)
    # Application settings
    # ----------------------------------------------------------------------------------------------
    # Configuration file path in command line parameters
    if '<cfg_file>' in args:
        cfg_file = args['<cfg_file>']

        if cfg_file and isinstance(cfg_file, list):
            cfg_file = cfg_file[0]

        # Read configuration file
        app_config = Settings(cfg_file)
        new_config_file = app_config.read(manifest['name'])
        print("Configuration read from: %s" % new_config_file)
        if not app_config:  # pragma: no cover, should never happen
            print("Required configuration file not found.")
            exit(1)

    # Store application name in the configuration
    app_config['name'] = manifest['name']

    if '--debug' in args and args['--debug']:  # pragma: no cover, not mesured by coverage!
        app_config['debug'] = '1'
        print("Application is in debug mode from command line")

    if os.environ.get('WEBUI_DEBUG'):  # pragma: no cover, not mesured by coverage!
        app_config['debug'] = '1'
        print("Application is in debug mode from environment")

    # Applications backend URL
    if args['--backend']:  # pragma: no cover, not mesured by coverage!
        app_config['alignak_backend'] = args['--backend']

    # WebUI server configuration
    if args['--hostname']:  # pragma: no cover, not mesured by coverage!
        app_config['host'] = args['--hostname']
    if args['--port']:  # pragma: no cover, not mesured by coverage!
        app_config['port'] = args['--port']

    # Make the configuration available globally for the package
    set_app_config(app_config)

    # Make the application available globally for the package
    app_webui = set_app_webui(WebUI(app_config))

    try:
        if args['--exit']:
            print("Application exit because of command line parameter")
            exit(99)

        # Run application server...
        run(
            app=webapp,
            host=app_config.get('host', '127.0.0.1'),
            port=int(app_config.get('port', 5001)),
            debug=(app_config.get('debug', '0') == '1'),
            server=app_config.get('http_backend', 'cherrypy')
        )
    except Exception as e:
        logger.error("Application run failed, exception: %s / %s", type(e), str(e))
        logger.info("Backtrace: %s", traceback.format_exc())
        logger.info("stopping backend livestate thread...")
        exit(2)