Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / netif
blob16ebe1af543a506a01f613d22ad6258100b57aa4
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 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 # WARNING: This check is deprecated and will be removed soon. Please
28 # update your agent and use lnx_if instead.
30 linux_nic_check = "lnx_if"
33 def inventory_netif_link(info):
34 if linux_nic_check != "legacy":
35 return []
36 return [(i[0], i[4] == 'yes', i[4] == 'yes') for i in info if len(i) == 5]
39 def check_netif_link(item, targetstate, info):
40 links = [i[4] for i in info if i[0] == item]
41 if len(links) == 0:
42 return (2, "unknown network device")
43 elif len(links) != 1:
44 return (3, "network devices listed more than once")
45 if links[0] == 'yes':
46 link = True
47 elif links[0] == 'no':
48 link = False
49 else:
50 return (3, "invalid link state '%s'" % link)
52 if link == targetstate:
53 if link:
54 return (0, "Link is up")
55 return (0, "no link / NIC unused")
57 if link:
58 return (1, "Link is up, NIC should be unused")
59 return (2, "no link")
62 def inventory_netif_params(info):
63 if linux_nic_check != "legacy":
64 return []
65 return [(i[0], '', tuple(i[1:4])) for i in info if len(i) == 5]
68 def check_netif_params(item, params, info):
69 infolist = [i[1:4] for i in info if i[0] == item]
70 if len(infolist) == 0:
71 return (2, "unknown network device")
72 elif len(infolist) != 1:
73 return (3, "network devices listed more than once")
74 act_params = tuple(infolist[0])
75 if act_params == params:
76 return (0, "%s" % (",".join(act_params),))
77 return (2, "%s (should be %s)" % (",".join(act_params), ",".join(params)))
80 check_info["netif.params"] = {
81 'check_function': check_netif_params,
82 'inventory_function': inventory_netif_params,
83 'service_description': 'NIC %s parameter',
86 check_info["netif.link"] = {
87 'check_function': check_netif_link,
88 'inventory_function': inventory_netif_link,
89 'service_description': 'NIC %s link',