Ejemplo n.º 1
0
def _load_structured_data_tree(
        tree_type: Literal["inventory", "status_data"],
        hostname: Optional[HostName]) -> Optional[StructuredDataNode]:
    """Load data of a host, cache it in the current HTTP request"""
    if not hostname:
        return None

    inventory_tree_cache = g.setdefault(tree_type, {})
    if hostname in inventory_tree_cache:
        inventory_tree = inventory_tree_cache[hostname]
    else:
        if '/' in hostname:
            # just for security reasons
            return None

        tree_store = StructuredDataStore(
            Path(cmk.utils.paths.inventory_output_dir) if tree_type ==
            "inventory" else Path(cmk.utils.paths.status_data_dir))

        try:
            inventory_tree = tree_store.load(host_name=hostname)
        except Exception as e:
            if config.debug:
                html.show_warning("%s" % e)
            raise LoadStructuredDataError()
        inventory_tree_cache[hostname] = inventory_tree
    return inventory_tree
Ejemplo n.º 2
0
def _load_inventory_tree(hostname):
    # Load data of a host, cache it in the current HTTP request
    if not hostname:
        return

    inventory_tree_cache = g.setdefault("inventory", {})
    if hostname in inventory_tree_cache:
        inventory_tree = inventory_tree_cache[hostname]
    else:
        if '/' in hostname:
            # just for security reasons
            return
        cache_path = "%s/inventory/%s" % (cmk.utils.paths.var_dir, hostname)
        inventory_tree = StructuredDataTree().load_from(cache_path)
        inventory_tree_cache[hostname] = inventory_tree
    return inventory_tree
Ejemplo n.º 3
0
def _load_inventory_tree(hostname):
    # Load data of a host, cache it in the current HTTP request
    if not hostname:
        return

    inventory_tree_cache = g.setdefault("inventory", {})
    if hostname in inventory_tree_cache:
        inventory_tree = inventory_tree_cache[hostname]
    else:
        if '/' in hostname:
            # just for security reasons
            return
        cache_path = "%s/inventory/%s" % (cmk.utils.paths.var_dir, hostname)
        try:
            inventory_tree = StructuredDataTree().load_from(cache_path)
        except Exception as e:
            if config.debug:
                html.show_warning(e)
            raise LoadStructuredDataError()
        inventory_tree_cache[hostname] = inventory_tree
    return inventory_tree
Ejemplo n.º 4
0
def _git_messages():
    """Initializes the request global data structure and returns it"""
    return g.setdefault("wato_git_messages", [])