#!/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.


def inv_ibm_mq_queues(parsed, inventory_tree, status_data_tree):
    path = "software.applications.ibm_mq.queues:"
    inv_node = inventory_tree.get_list(path)
    for item in sorted(parsed):
        if ':' not in item:
            # Do not show queue manager in inventory
            continue
        attrs = parsed[item]
        qmname, qname = item.split(":")
        inv_node.append({
            "qmgr": qmname,
            "name": qname,
            "maxdepth": attrs["MAXDEPTH"],
            "maxmsgl": attrs.get("MAXMSGL", "n/a"),
            "created":
                (attrs.get("CRDATE", "n/a") + " " + (attrs.get("CRTIME", "").replace(".", ":"))),
            "altered":
                (attrs.get("ALTDATE", "n/a") + " " + (attrs.get("ALTTIME", "").replace(".", ":"))),
            "monq": attrs.get("MONQ", "n/a"),
        })


inv_info['ibm_mq_queues'] = {
    'inv_function': inv_ibm_mq_queues,
}
