Cleanup config.nodes_of
[check_mk.git] / checks / aix_if
blob51522120762dd171211359a8fb0f964906222656
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 # Example output from agent:
29 # <<<aix_if>>>
30 # [en0]
31 # Device Type: Virtual I/O Ethernet Adapter (l-lan)
32 # Hardware Address: 3a:91:69:58:fb:02
33 # Packets: 160437280 Packets: 202011889
34 # Bytes: 288954334803 Bytes: 88290654589
35 # Transmit Errors: 0 Receive Errors: 0
36 # Broadcast Packets: 9914 Broadcast Packets: 27541611
37 # Multicast Packets: 2 Multicast Packets: 0
38 # General Statistics:
39 # -------------------
40 # No mbuf Errors: 0
41 # Adapter Reset Count: 0
42 # Adapter Data Rate: 20000
43 # Driver Flags: Up Broadcast Running
44 # Simplex 64BitSupport ChecksumOffload
45 # DataRateSet
48 def parse_aix_if(info):
49 nic_info = {}
50 index = 0
51 for line in info:
52 # Be careful! On clustered hosts we have more than one perf-counters section
53 # and ethtool section. This needs to be handled. Sadly we have no section
54 # headers. Try to detect it by data format.
55 if line[0].startswith('['):
56 nic = line[0][1:-1]
57 index += 1
58 nic_info[nic] = {"ifIndex": index}
59 nic_info[nic]["ifDescr"] = nic
60 nic_info[nic]["ifAlias"] = nic
61 if nic.startswith("lo"):
62 nic_info[nic]["ifType"] = "24"
63 else:
64 nic_info[nic]["ifType"] = "6"
65 elif line[0] == "Bytes:" and line[2] == "Bytes:":
66 nic_info[nic]["ifOutOctets"] = line[1]
67 nic_info[nic]["ifInOctets"] = line[3]
68 elif line[0] == "Packets:" and line[2] == "Packets:":
69 nic_info[nic]["outucast"] = line[1]
70 nic_info[nic]["inucast"] = line[3]
71 elif line[0] == "Transmit" and line[1] == "Errors:":
72 nic_info[nic]["ifOutErrors"] = line[2]
73 nic_info[nic]["ifInErrors"] = line[5]
74 elif " ".join(line[0:2]) == "Broadcast Packets:":
75 nic_info[nic]["outbcast"] = line[2]
76 nic_info[nic]["inbcast"] = line[5]
77 elif " ".join(line[0:2]) == "Multicast Packets:":
78 nic_info[nic]["outmcast"] = line[2]
79 nic_info[nic]["inmcast"] = line[5]
80 elif " ".join(line[0:2]) == "Hardware Address:":
81 nic_info[nic]["ifPhysAddress"] = "".join([chr(int(x, 16)) for x in line[2].split(":")])
82 elif " ".join(line[0:3]) == "Adapter Data Rate:":
83 # speed is in Mb/s
84 nic_info[nic]["ifSpeed"] = int(line[3]) * 1000000
85 elif " ".join(line[0:2]) == "Driver Flags:":
86 nic_info[nic]["flags"] = line[2:]
87 elif " ".join(line[0:3]) == "KIM Driver Flags:":
88 nic_info[nic]["flags"] = line[3:]
89 elif len(line) and ":" not in " ".join(line) and "flags" in nic_info[nic]:
90 nic_info[nic]["flags"] += line
92 if_table = []
93 for nic in nic_info:
94 if "Up" in nic_info[nic]["flags"]:
95 nic_info[nic]["ifOperStatus"] = 1
96 elif "Down" in nic_info[nic]["flags"]:
97 nic_info[nic]["ifOperStatus"] = 2
98 # No information from entstat. We consider interfaces up
99 # if they have been used at least some time since the
100 # system boot.
101 elif nic_info[nic]["ifInOctets"] > 0:
102 nic_info[nic]["ifOperStatus"] = 1
103 else:
104 # unknown, or never been up
105 nic_info[nic]["ifOperStatus"] = 4
107 nic_info[nic]["ifOutQLen"] = 0
108 nic_info[nic]["ifInDiscards"] = 0
109 nic_info[nic]["ifOutDiscards"] = 0
111 nic_list = []
112 for attr in [
113 "ifIndex", "ifDescr", "ifType", "ifSpeed", "ifOperStatus", "ifInOctets", "inucast",
114 "inmcast", "inbcast", "ifInDiscards", "ifInErrors", "ifOutOctets", "outucast",
115 "outmcast", "outbcast", "ifOutDiscards", "ifOutErrors", "ifOutQLen", "ifAlias",
116 "ifPhysAddress"
118 nic_list.append(nic_info[nic].get(attr, 0))
119 if_table.append(map(str, nic_list))
120 return if_table
123 def inventory_aix_if(info):
124 return inventory_if_common(info)
127 def check_aix_if(item, params, info):
128 return check_if_common(item, params, info)
131 check_info["aix_if"] = {
132 'inventory_function': inventory_aix_if,
133 'check_function': check_aix_if,
134 'parse_function': parse_aix_if,
135 'service_description': 'Interface %s',
136 'has_perfdata': True,
137 'group': 'if',
138 'default_levels_variable': 'if_default_levels',
139 'includes': ['if.include']