Module: check_mk
Branch: master
Commit: 17cf994749d95ac119cd8fdbb73c803d19f9cbbc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=17cf994749d95a…
Author: Marcel Schulte <ms(a)mathias-kettner.de>
Date: Thu Mar 16 13:07:10 2017 +0100
8670 win_networkadapter: added network adapters to inventory of Windows hosts
The inventory plugin now gathers information on network adapters of Windows hosts. This
information is then shown in HW/SW inventory of the host as "Hardware -> Network
Adapters."
Change-Id: I8f47a37a92990ff928e2bf0c4e998814fb837df2
---
.werks/8670 | 11 ++++
agents/windows/plugins/mk_inventory.vbs | 34 ++++++++++++
inventory/win_networkadapter | 93 +++++++++++++++++++++++++++++++++
web/plugins/views/inventory.py | 12 +++++
4 files changed, 150 insertions(+)
diff --git a/.werks/8670 b/.werks/8670
new file mode 100644
index 0000000..f993b44
--- /dev/null
+++ b/.werks/8670
@@ -0,0 +1,11 @@
+Title: win_networkadapter: added network adapters to inventory of Windows hosts
+Level: 1
+Component: inv
+Class: feature
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1489665801
+
+The inventory plugin now gathers information on network adapters of Windows hosts. This
information is then shown in HW/SW inventory of the host as "Hardware -> Network
Adapters."
diff --git a/agents/windows/plugins/mk_inventory.vbs
b/agents/windows/plugins/mk_inventory.vbs
index c0b2ee7..b5623c1 100644
--- a/agents/windows/plugins/mk_inventory.vbs
+++ b/agents/windows/plugins/mk_inventory.vbs
@@ -120,6 +120,35 @@ Sub getWMIObject2(strClass,arrVars)
Next
End Sub
+Sub getNetworkAdapter(arrVars)
+ Set objClass =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
+ Set Entries = objClass.ExecQuery("Select * from Win32_NetworkAdapter")
+ Set AdapterConfigs = objClass.ExecQuery("Select * from
Win32_NetworkAdapterConfiguration")
+
+ For Each entry in Entries
+ ' Only handle Adapters with a MAC address
+ If entry.ServiceName <> "AsyncMac" And Len(entry.MACAddress) >
0 Then
+ For Each item in entry.Properties_
+ ' if it is in arrVars
+ If UBound(filter(arrVars, item.name)) = 0 Then
+ If isArray(item.value) Then
+ outPut(item.name & ": " & join(item.value))
+ Else
+ outPut(item.name & ": " & item.value)
+ End If
+ End If
+ Next
+
+ For Each adapterCfg in AdapterConfigs
+ If entry.name = adapterCfg.Description Then
+ outPut("Address: " & join(adapterCfg.IPAddress))
+ outPut("Subnet: " & join(adapterCfg.IPSubnet))
+ outPut("DefaultGateway: " &
join(adapterCfg.DefaultIPGateway))
+ End If
+ Next
+ End If
+ Next
+End Sub
Sub RecurseForExecs(strFolderPath)
Dim objFolder : Set objFolder = fso.GetFolder(strFolderPath)
@@ -229,6 +258,11 @@ Call startSection("win_video",58,timeUntil)
adapterVars = Array( "Name", "Description", "Caption",
"AdapterCompatibility", "VideoModeDescription",
"VideoProcessor", "DriverVersion", "DriverDate",
"MaxMemorySupported")
Call getWMIObject("Win32_VideoController",adapterVars)
+' Network Adapter
+Call startSection("win_networkadapter",58,timeUntil)
+adapterVars = Array("ServiceName", "MACAddress",
"AdapterType", "DeviceID", "NetworkAddresses",
"Speed")
+Call getNetworkAdapter(adapterVars)
+
' Installed Software
Call startSection("win_wmi_software",124,timeUntil)
swVars = Array( "ProductName", "Publisher",
"VersionString", "InstallDate", "Language")
diff --git a/inventory/win_networkadapter b/inventory/win_networkadapter
new file mode 100644
index 0000000..aeaed89
--- /dev/null
+++ b/inventory/win_networkadapter
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2017 mk(a)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:
+# <<<win_networkadapter:sep(58)>>>
+# AdapterType: Ethernet 802.3
+# DeviceID: 7
+# MACAddress: 08:00:27:9C:F8:39
+# Name: Intel(R) PRO/1000 MT-Desktopadapter
+# NetworkAddresses:
+# ServiceName: E1G60
+# Speed: 1000000000
+# Address: 192.168.178.26
+# Subnet: 255.255.255.0
+# DefaultGateway: 192.168.178.1
+
+def inv_win_networkadapter(info):
+ node = inv_tree_list("hardware.nwadapter:")
+ array = {}
+ first_varname = None
+ addrtypes = {}
+ for line in info:
+ if len(line) > 2:
+ line = [ line[0], ":".join(line[1:]) ]
+ varname, value = line
+ varname = re.sub(" *","", varname)
+ value = re.sub("^ ", "", value)
+
+ if first_varname and varname == first_varname:
+ # Looks like we have a new instance
+ node.append(array)
+ array = {}
+
+ if not first_varname:
+ first_varname = varname
+
+ if varname == "Name":
+ array["name"] = value
+ elif varname == "AdapterType":
+ array["type"] = value
+ elif varname == "MACAddress":
+ array["macaddress"] = value
+ elif varname == "Speed":
+ array["speed"] = int(value)
+ elif varname == "Address":
+ for address in value.split(' '):
+ addrtype = "ipv4"
+ if ':' in address:
+ addrtype = "ipv6"
+ addrtypes.setdefault(addrtype + "_address",
[]).append(address)
+ elif varname == "Subnet":
+ for address in value.split(' '):
+ addrtype = "ipv6"
+ if '.' in address:
+ addrtype = "ipv4"
+ #addrtypes.setdefault(addrtype, {}).setdefault("subnet",
[]).append(address)
+ addrtypes.setdefault(addrtype + "_subnet", []).append(address)
+ elif varname == "DefaultGateway":
+ array["gateway"] = value
+
+ for addrtype in addrtypes:
+ array[addrtype] = ', '.join(addrtypes[addrtype])
+ #for type in addrtypes[addrtype]:
+ # array[addrtype + '_' + type] = ',
'.join(addrtypes[addrtype][type])
+ node.append(array)
+
+
+inv_info['win_networkadapter'] = {
+ "inv_function" : inv_win_networkadapter,
+}
diff --git a/web/plugins/views/inventory.py b/web/plugins/views/inventory.py
index 263256a..cb95f9f 100644
--- a/web/plugins/views/inventory.py
+++ b/web/plugins/views/inventory.py
@@ -704,6 +704,18 @@ inventory_displayhints.update({
".hardware.video:*.driver_date" : { "title" :
_("Driver Date"), "short" : _("Driver Date") },
".hardware.video:*.driver_version" : { "title" :
_("Driver Version"), "short" : _("Driver Version") },
+ ".hardware.nwadapter:" : { "title" :
_("Network Adapters"), },
+ ".hardware.nwadapter:*." : { "title" :
_("Network Adapter %d"), },
+ ".hardware.nwadapter:*.name" : { "title" :
_("Name"), },
+ ".hardware.nwadapter:*.type" : { "title" :
_("Type"), },
+ ".hardware.nwadapter:*.macaddress" : { "title" :
_("Physical Address (MAC)"), },
+ ".hardware.nwadapter:*.speed" : { "title" :
_("Speed"), "paint" : "nic_speed", },
+ ".hardware.nwadapter:*.ipv4_address" : { "title" :
_("IPv4 Address"), },
+ ".hardware.nwadapter:*.ipv4_subnet" : { "title" :
_("IPv4 Subnet"), },
+ ".hardware.nwadapter:*.ipv6_address" : { "title" :
_("IPv6 Address"), },
+ ".hardware.nwadapter:*.ipv6_subnet" : { "title" :
_("IPv6 Subnet"), },
+ ".hardware.nwadapter:*.gateway" : { "title" :
_("Gateway"), },
+
".software." : { "title" :
_("Software"), "icon" : "software" },
".software.os." : { "title" :
_("Operating System") },
".software.os.name" : { "title" :
_("Name"), "short" : _("Operating System") },