コード例 #1
0
def main(args):
    # type: (List[str]) -> int
    arguments = parse_arguments(args)

    try:
        log.setup_console_logging()
        log.logger.setLevel(log.verbosity_to_log_level(arguments.verbose))
        logger = logging.getLogger("cmk.update_config")
        if arguments.debug:
            cmk.utils.debug.enable()

        logger.debug("parsed arguments: %s", arguments)

        UpdateConfig(logger, arguments).run()

    except Exception as e:
        if arguments.debug:
            raise
        if logger:
            logger.exception(
                "ERROR: Please repair this and run \"cmk-update-config -v\"")
        else:
            print("ERROR: %s" % e)
        return 1
    return 0
コード例 #2
0
ファイル: main.py プロジェクト: troelsarvin/checkmk
def setup_logging(arguments: argparse.Namespace) -> None:
    log.setup_console_logging()
    log.logger.setLevel(log.verbosity_to_log_level(arguments.verbose))

    # TODO: Fix this cruel hack caused by our funny mix of GUI + console
    # stuff. Currently, we just move the console handler to the top, so
    # both worlds are happy. We really, really need to split business logic
    # from presentation code... :-/
    if log.logger.handlers:
        console_handler = log.logger.handlers[0]
        del log.logger.handlers[:]
        logging.getLogger().addHandler(console_handler)
コード例 #3
0
ファイル: update_config.py プロジェクト: chill-uk/checkmk
def main(args: List[str]) -> int:
    arguments = parse_arguments(args)
    log.setup_console_logging()
    log.logger.setLevel(log.verbosity_to_log_level(arguments.verbose))
    logger = logging.getLogger("cmk.update_config")
    if arguments.debug:
        cmk.utils.debug.enable()
    logger.debug("parsed arguments: %s", arguments)

    try:
        UpdateConfig(logger, arguments).run()
    except Exception:
        if arguments.debug:
            raise
        logger.exception("ERROR: Please repair this and run \"cmk-update-config -v\" "
                         "BEFORE starting the site again.")
        return 1
    return 0
コード例 #4
0
ファイル: __init__.py プロジェクト: LinuxHaus/checkmk
    def execute(self, cmd: str, args: List[str]) -> Any:
        self._handle_generic_arguments(args)

        try:
            try:
                automation = self._automations[cmd]
            except KeyError:
                raise MKAutomationError("Automation command '%s' is not implemented." % cmd)

            if automation.needs_checks:
                with redirect_stdout(open(os.devnull, "w")):
                    log.setup_console_logging()
                    config.load_all_agent_based_plugins(
                        check_api.get_check_api_context,
                        inventory_plugins.load_legacy_inventory_plugins,
                    )

            if automation.needs_config:
                config.load(validate_hosts=False)

            result = automation.execute(args)

        except (MKAutomationError, MKTimeout) as e:
            console.error("%s\n" % e)
            if cmk.utils.debug.enabled():
                raise
            return 1

        except Exception as e:
            if cmk.utils.debug.enabled():
                raise
            console.error("%s\n" % e)
            return 2

        finally:
            profiling.output_profile()

        out.output(result.serialize())
        out.output("\n")

        return 0
コード例 #5
0
def test_setup_console_logging(capsys):
    out, err = capsys.readouterr()
    assert out == ""
    assert err == ""

    logging.getLogger("cmk.test").info("test123")

    out, err = capsys.readouterr()
    assert out == ""
    assert err == ""

    log.setup_console_logging()
    l = logging.getLogger("cmk.test")
    l.info("test123")

    # Cleanup handler registered with log.setup_console_logging()
    log.logger.handlers.pop()

    out, err = capsys.readouterr()
    assert out == "test123\n"
    assert err == ""
コード例 #6
0
if sys.version_info[0] >= 3:
    from pathlib import Path  # pylint: disable=import-error
else:
    from pathlib2 import Path  # pylint: disable=import-error

import cmk.utils
import cmk.utils.paths
import cmk.utils.translations
import cmk.utils.store as store
from cmk.utils.exceptions import MKGeneralException
from cmk.utils.render import Age
from cmk.utils.regex import regex
import cmk.utils.log as log
from cmk.utils.log import VERBOSE

log.setup_console_logging()
logger = logging.getLogger("cmk.base")

PiggybackFileInfo = NamedTuple('PiggybackFileInfo', [
    ('source_hostname', str),
    ('file_path', Path),
    ('successfully_processed', bool),
    ('reason', Text),
    ('reason_status', int),
])

PiggybackRawDataInfo = NamedTuple('PiggybackRawData', [
    ('source_hostname', str),
    ('file_path', str),
    ('successfully_processed', bool),
    ('reason', Text),