Пример #1
0
def test_builtin_vs_plugin_hooks():
    hooks.register_builtin("bla", lambda: True)
    assert hooks.registered("bla") == True

    hooks.register_from_plugin("blub", lambda: True)
    assert hooks.registered("blub") == True

    hooks.load_plugins(force=True)

    assert hooks.registered("bla") == True
    assert hooks.registered("blub") == False
Пример #2
0
def call_hook_activate_changes():
    if hooks.registered("activate-changes"):
        # TODO: Cleanup this local import
        import cmk.gui.watolib.hosts_and_folders  # pylint: disable=redefined-outer-name

        hooks.call("activate-changes",
                   cmk.gui.watolib.hosts_and_folders.collect_all_hosts())
Пример #3
0
 def activate(self):
     if getattr(config, "mkeventd_enabled", False):
         mkeventd.execute_command("RELOAD", site=config.omd_site())
         log_audit(None, "mkeventd-activate",
                   _("Activated changes of event console configuration"))
         if hooks.registered('mkeventd-activate-changes'):
             hooks.call("mkeventd-activate-changes")
Пример #4
0
 def activate(self, settings: Optional[SerializedSettings] = None) -> ConfigurationWarnings:
     if getattr(config, "mkeventd_enabled", False):
         mkeventd.execute_command("RELOAD", site=omd_site())
         log_audit("mkeventd-activate", _("Activated changes of event console configuration"))
         if hooks.registered("mkeventd-activate-changes"):
             hooks.call("mkeventd-activate-changes")
     return []
Пример #5
0
def test_hook_registration():
    assert hooks.hooks == {}

    # pre 1.6 API
    hooks.register("bla", lambda: True)
    assert hooks.get("bla")[0].is_builtin == False

    hooks.register_builtin("blub", lambda: True)
    hooks.register_from_plugin("blub", lambda: False)
    assert hooks.get("blub")[0].is_builtin == True
    assert hooks.get("blub")[1].is_builtin == False

    assert hooks.registered("bla") == True
    assert hooks.registered("blub") == True
    assert hooks.registered("bli") == False

    assert len(hooks.get("bla")) == 1
    assert len(hooks.get("blub")) == 2
    assert len(hooks.get("bli")) == 0
Пример #6
0
 def _pre_activate_changes(self):
     # TODO: Cleanup this local import
     import cmk.gui.watolib.hosts_and_folders  # pylint: disable=redefined-outer-name
     try:
         if hooks.registered('pre-distribute-changes'):
             hooks.call("pre-distribute-changes",
                        cmk.gui.watolib.hosts_and_folders.collect_all_hosts())
     except Exception as e:
         logger.exception()
         if config.debug:
             raise
         raise MKUserError(None, _("Can not start activation: %s") % e)