#!/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
# <<<lnx_video>>>
# 05:00.0 VGA compatible controller: Advanced Micro Devices [AMD] nee ATI Cape Verde PRO [Radeon HD 7700 Series] (prog-if 00 [VGA controller])
#        Subsystem: Hightech Information System Ltd. Device 200b
#        Flags: bus master, fast devsel, latency 0, IRQ 58
#        Memory at d0000000 (64-bit, prefetchable) [size=256M]
#        Memory at fe8c0000 (64-bit, non-prefetchable) [size=256K]
#        I/O ports at c000 [size=256]
#        Expansion ROM at fe8a0000 [disabled] [size=128K]
#        Capabilities: [48] Vendor Specific Information: Len=08 <?>
#        Capabilities: [50] Power Management version 3
#        Capabilities: [58] Express Legacy Endpoint, MSI 00
#        Capabilities: [a0] MSI: Enable+ Count=1/1 Maskable- 64bit+
#        Capabilities: [100] Vendor Specific Information: ID=0001 Rev=1 Len=010 <?>
#        Capabilities: [150] Advanced Error Reporting
#        Capabilities: [270] #19
#        Kernel driver in use: fglrx_pci


def inv_lnx_video(info):
    node = inv_tree("hardware.video:")
    array = {}
    for line in info:
        if len(line) > 1:
            if re.search("VGA compatible controller", line[1]):
                array["name"] = line[2]
            elif line[0] == "Subsystem":
                array["subsystem"] = line[1]
            elif line[0] == "Kernel driver in use":
                array["driver"] = line[1]
    node.append(array)


inv_info['lnx_video'] = {
   "inv_function"           : inv_lnx_video,
}
