Refactoring: Changed all check parameters starting with a 'g' or 'h' to new rulespec...
[check_mk.git] / inventory / win_networkadapter
blob16cb1d2357ccd471286b6a2903987b053dd05e80
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2017 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # Example output:
28 # <<<win_networkadapter:sep(58)>>>
29 # AdapterType: Ethernet 802.3
30 # DeviceID: 7
31 # MACAddress: 08:00:27:9C:F8:39
32 # Name: Intel(R) PRO/1000 MT-Desktopadapter
33 # NetworkAddresses:
34 # ServiceName: E1G60
35 # Speed: 1000000000
36 # Address: 192.168.178.26
37 # Subnet: 255.255.255.0
38 # DefaultGateway: 192.168.178.1
41 def inv_win_networkadapter(info):
42 node = inv_tree_list("hardware.nwadapter:")
43 array = {}
44 first_varname = None
45 addrtypes = {}
46 for line in info:
47 if len(line) > 2:
48 line = [line[0], ":".join(line[1:])]
49 varname, value = line
50 varname = re.sub(" *", "", varname)
51 value = re.sub("^ ", "", value)
53 if not value:
54 continue
56 if first_varname and varname == first_varname:
57 # Looks like we have a new instance
58 node.append(array)
59 array = {}
61 if not first_varname:
62 first_varname = varname
64 if varname == "Name":
65 array["name"] = value
66 elif varname == "AdapterType":
67 array["type"] = value
68 elif varname == "MACAddress":
69 array["macaddress"] = value
70 elif varname == "Speed":
71 array["speed"] = int(value)
72 elif varname == "Address":
73 for address in value.split(' '):
74 addrtype = "ipv4"
75 if ':' in address:
76 addrtype = "ipv6"
77 addrtypes.setdefault(addrtype + "_address", []).append(address)
78 elif varname == "Subnet":
79 for address in value.split(' '):
80 addrtype = "ipv6"
81 if '.' in address:
82 addrtype = "ipv4"
83 #addrtypes.setdefault(addrtype, {}).setdefault("subnet", []).append(address)
84 addrtypes.setdefault(addrtype + "_subnet", []).append(address)
85 elif varname == "DefaultGateway":
86 array["gateway"] = value
88 for addrtype in addrtypes:
89 array[addrtype] = ', '.join(addrtypes[addrtype])
90 #for type in addrtypes[addrtype]:
91 # array[addrtype + '_' + type] = ', '.join(addrtypes[addrtype][type])
92 node.append(array)
95 inv_info['win_networkadapter'] = {
96 "inv_function": inv_win_networkadapter,