#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             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.

# <<<windows_os_bonding:sep(58)>>>
# Team Name: LAN
# Bonding Mode: Dynamic
# Status: Up
# Speed: 20 Gbps
#
# Slave Name: NIC1
# Slave Interface: Ethernet_14
# Slave Description: Intel(R) Ethernet 10G 2P X520-k bNDC #2
# Slave Status: Up
# Slave Speed: 10 Gbps
# Slave MAC address: 18-A9-9B-9F-AD-28
#
# Slave Name: NIC2
# Slave Interface: Ethernet_10
# Slave Description: Intel(R) Ethernet 10G 2P X520-k bNDC
# Slave Status: Up
# Slave Speed: 10 Gbps
# Slave MAC address: 18-A9-9B-9F-AD-2A


def parse_windows_os_bonding(info):
    bonds = {}

    for line in info:
        if len(line) > 1:
            item = line[1].lstrip()
        if line[0] == "Team Name":
            bond = item
            bonds[bond] = {}
            bonds[bond]["interfaces"] = {}
        elif line[0] == "Bonding Mode":
            bonds[bond]["mode"] = item
        elif line[0] == "Status":
            bonds[bond]["status"] = item.lower()
        elif line[0] == "Speed":
            bonds[bond]["speed"] = item
        elif line[0] == "Slave Name":
            slave = item
            bonds[bond]["interfaces"][slave] = {}
        elif line[0] == "Slave Status":
            bonds[bond]["interfaces"][slave]["status"] = item.lower()
        elif line[0] == "Slave MAC address":
            bonds[bond]["interfaces"][slave]["hwaddr"] = item.lower().replace("-", ":")
    return bonds


check_info['windows_os_bonding'] = {
    "parse_function": parse_windows_os_bonding,
    "check_function": check_bonding,
    "inventory_function": inventory_bonding,
    "service_description": "Bonding Interface %s",
    "default_levels_variable": "bonding_default_levels",
    "group": "bonding",
    "includes": ["bonding.include"],
}
