#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from cmk.base.check_legacy_includes.couchbase import *  # pylint: disable=wildcard-import,unused-wildcard-import

# "ports":{
#      "proxy": 11213,
#      "direct": 11212
#  },


def inv_couchbase_nodes_ports(info, inventory_tree, status_data_tree):
    parsed = parse_couchbase_lines(info)

    for node_name, data in parsed.items():
        name = node_name.replace(".", "-").replace(":", "-")
        path = "software.applications.couchbase.nodes.%s.ports." % name
        inventory_ports = inventory_tree.get_dict(path)
        inventory_ports.update(data.get("ports", {}))


inv_info["couchbase_nodes_ports"] = {  # pylint: disable=undefined-variable
    "inv_function": inv_couchbase_nodes_ports,
}
