Exemplo n.º 1
0
def current_helper_config_serial() -> ConfigSerial:
    serial: int = store.load_object_from_file(
        cmk.utils.paths.core_helper_config_dir / "serial.mk",
        default=0,
        lock=True,
    )
    return ConfigSerial(str(serial))
Exemplo n.º 2
0
 def from_str(command: str) -> "Command":
     raw_serial, host_name, mode_name, timeout = command.split(sep=";", maxsplit=3)
     return Command(
         serial=ConfigSerial(raw_serial),
         host_name=host_name,
         mode=Mode.CHECKING if mode_name == "checking" else Mode.DISCOVERY,
         timeout=int(timeout),
     )
Exemplo n.º 3
0
    def test_create_success_replace_latest_link(self, store, serial):
        prev_serial = ConfigSerial("1")
        prev_path = cmk.utils.paths.core_helper_config_dir / prev_serial
        prev_path.mkdir(parents=True, exist_ok=True)
        store.latest_path.symlink_to(prev_serial)
        assert store.latest_path.exists()

        with store.create():
            assert store.serial_path.exists()

        assert store.serial_path.exists()
        assert store.latest_path.resolve().name == serial
Exemplo n.º 4
0
def new_helper_config_serial() -> ConfigSerial:
    """Acquire and return the next helper config serial

    This ID is used to identify a core helper configuration generation. It is used to store the
    helper config on the file system below var/check_mk/core/helper_config/[serial]. It needs to
    be unique compared to all currently known serials (the ones that exist in the directory
    mentioned above).
    """
    serial_file = cmk.utils.paths.core_helper_config_dir / "serial.mk"

    serial: int = store.load_object_from_file(serial_file, default=0, lock=True)
    serial += 1

    store.save_object_to_file(serial_file, serial)
    return ConfigSerial(str(serial))
Exemplo n.º 5
0
def process_command(raw_command: str, observer: ABCResourceObserver) -> None:
    with _confirm_command_processed():
        serial: ConfigSerial = ConfigSerial("")
        host_name: Optional[HostName] = None
        try:
            command = Command.from_str(raw_command)
            serial = command.serial
            host_name = command.host_name
            global_config = load_global_config(command.serial)
            logging.getLogger().setLevel(global_config.log_level)
            SNMPFetcher.plugin_store = global_config.snmp_plugin_store
            run_fetchers(**command._asdict())
            observer.check_resources(raw_command)
        except Exception as e:
            crash_info = create_fetcher_crash_dump(serial=serial, host=host_name)
            logger.critical("Exception is '%s' (%s)", e, crash_info)
            sys.exit(15)
Exemplo n.º 6
0
def test_new_helper_config_serial():
    assert core_config.new_helper_config_serial() == ConfigSerial("1")
    assert core_config.new_helper_config_serial() == ConfigSerial("2")
    assert core_config.new_helper_config_serial() == ConfigSerial("3")
Exemplo n.º 7
0
 def prev_prev_serial(self, prev_serial):
     return ConfigSerial(str(int(prev_serial) - 1))
Exemplo n.º 8
0
 def test_given_serial_path(self):
     store = core_config.HelperConfig(serial=ConfigSerial("42"))
     assert store.serial_path == cmk.utils.paths.core_helper_config_dir / "42"
Exemplo n.º 9
0
 def test_global_config_path(self):
     assert make_global_config_path(
         serial=ConfigSerial("_serial_")
     ) == core_helper_config_dir / "_serial_" / "fetchers" / "global_config.json"
Exemplo n.º 10
0
 def test_local_config_path(self):
     assert make_local_config_path(
         serial=ConfigSerial("_serial_"),
         host_name="buzz",
     ) == (core_helper_config_dir / "_serial_" / "fetchers" / "hosts" /
           "buzz.json")
Exemplo n.º 11
0
def fixture_serial() -> ConfigSerial:
    return ConfigSerial("42")
Exemplo n.º 12
0
 def test_build_json_global_config_file_path(self):
     assert build_json_global_config_file_path(
         serial=ConfigSerial("_serial_")
     ) == core_helper_config_dir / "_serial_" / "fetchers" / "global_config.json"
Exemplo n.º 13
0
 def test_build_json_file_path(self):
     assert build_json_file_path(
         serial=ConfigSerial("_serial_"),
         host_name="buzz") == (core_helper_config_dir / "_serial_" /
                               "fetchers" / "hosts" / "buzz.json")
Exemplo n.º 14
0
def current_core_config_serial() -> ConfigSerial:
    # TODO: Needs to be changed (increased?) on every invokation
    return ConfigSerial(str(13))