#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# tails. You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

# Example output:
# <<<netapp_api_info:sep(9)>>>
# ### 7Mode
# system-name netapp-host
# system-id   4082367488
# system-model    SIMBOX
# system-machine-type SIMBOX
# vendor-id   NetApp
# system-serial-number    4082367488
# board-speed 2933
# board-type  NetApp VSim
# cpu-serial-number   999999
# number-of-processors    2
# memory-size 1599
# cpu-processor-id    0x206c2
# cpu-microcode-version   21
# maximum-aggregate-size  2199023255552
# maximum-flexible-volume-size    17592186044416

# ### Clustermode
# node clu1-02  cpu-microcode-version 21    prod-type FAS   system-model SIMBOX memory-size 8192    board-speed 2933

def inv_netapp_api_info(info):
    info_dict = dict((x[0], x[1]) for x in info if x[0] != "node")

    sw_os = inv_tree("software.os.")
    hw_chassis = inv_tree("hardware.chassis.")
    hw_system = inv_tree("hardware.system.")
    hw_cpu= inv_tree("hardware.cpu.")

    # General data
    for what, name, where_to in [("backplane-serial-number",    "serial",   hw_chassis),
                                 ("system-model",               "model",    hw_system),
                                 ("system-machine-type",        "product",  hw_system),
                                 ("system-serial-number",       "serial",   hw_system),
                                 ("system-id",                  "id",       hw_system),
# TODO: find good location for the configurable system name
#                                 ("system-name",                "system_name",     sw_os),
                                 ("vendor-id",                  "vendor",   sw_os),
                                 ("number-of-processors",       "cores",    hw_cpu),
                                 ("cpu-processor-type",         "model",    hw_cpu)]:
        if what in info_dict:
            where_to[name] = info_dict[what]


# TODO: Clustermode inventory data. Clarify the correct subtrees
#    # Node specific data
#    node_dict = {}
#    for line in info:
#        if line[0].startswith("node"):
#            node = line[0].split(" ", 1)[1]
#            node_dict.setdefault(node, {})
#            for entry in line[1:]:
#                tokens = entry.split(" ", 1)
#                node_dict[node][tokens[0]] = tokens[1]
#

inv_info['netapp_api_info'] = {
   "inv_function"           : inv_netapp_api_info,
}
