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

# Example output:
# <<<netapp_api_disk:sep(9)>>>
# disk 4E455441:50502020:56442D39:3030304D:422D465A:2D353230:38383633:32303037:00000000:00000000  used-space 9458679808   serial-number 88632007  raid-type pending vendor-id ..


def inv_netapp_api_disk(info):
    node = inv_tree_list("hardware.storage.disks:")
    for line in info:
        disk = {}
        line_dict = dict(x.split(" ", 1) for x in line)

        for what, inv_name in [("serial-number", "serial"), ("vendor-id", "vendor")]:
            if line_dict.get(what):
                disk[inv_name] = line_dict[what]
        if line_dict.get("bay") not in [None, "?"]:
            disk["bay"] = line_dict["bay"]

        node.append(disk)


inv_info['netapp_api_disk'] = {
    "inv_function": inv_netapp_api_disk,
}
