2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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 #<<<netapp_api_if:sep(9)>>>
28 # interface clu1-01_clus1 use-failover-group unused address 222.254.110.11 dns-domain-name none is-auto-revert true lif-uuid 3d682f64-4bd1-11e5-a02c-0050569628b6 vserver Cluster role cluster netmask-length 24 data-protocols.data-protocol none operational-status up netmask 255.255.255.0 failover-policy local_only home-node clu1-01 address-family ipv4 current-port e0a current-node clu1-01 routing-group-name c222.254.110.0/24 listen-for-dns-query false administrative-status up failover-group Cluster home-port e0a is-home true send_data 4265424 send_errors 0 recv_errors 0 instance_name clu1-01_clus1 recv_data 5988948
29 # interface clu1-01_clus2 use-failover-group unused address 222.254.110.12 dns-domain-name none is-auto-revert true lif-uuid 3d6817c9-4bd1-11e5-a02c-0050569628b6 vserver Cluster role cluster netmask-length 24 data-protocols.data-protocol none operational-status up netmask 255.255.255.0 failover-policy local_only home-node clu1-01 address-family ipv4 current-port e0b current-node clu1-01 routing-group-name c222.254.110.0/24 listen-for-dns-query false administrative-status up failover-group Cluster home-port e0b is-home true send_data 4389886 send_errors 0 recv_errors 0 instance_name clu1-01_clus2 recv_data 6113182
32 def netapp_convert_to_if64(info
):
33 interfaces
= netapp_api_parse_lines(info
)
35 # Calculate speed, state and create mac-address list
36 if_mac_list
= {} # Dictionary with lists of common mac addresses
37 vif_list
= [] # List of virtual interfaces
38 for name
, values
in interfaces
.items():
40 mediatype
= values
.get("mediatype")
42 tokens
= mediatype
.split("-")
43 # Possible values according to 7-Mode docu: 100tx | 100tx-fd | 1000fx | 10g-sr
44 if "1000" in mediatype
:
46 elif "100" in mediatype
:
48 elif "10g" in mediatype
:
50 elif "10" in mediatype
:
54 values
["speed"] = speed
56 values
["state"] = "1" if tokens
[-1].lower() == "up" else "2"
57 elif values
.get("port-role") != "storage-acp":
58 # If an interface has no media type and is not a storage-acp it is considered as virtual interface
61 # Reported by Clustermode
62 for status_key
in ["link-status", "operational-status"]:
63 if status_key
in values
:
64 if values
[status_key
] == "up":
70 # Reported by Clustermode
71 if "operational-speed" in values
:
72 values
["speed"] = int(values
["operational-speed"]) * 1000 * 1000
74 if "mac-address" in values
:
75 if_mac_list
.setdefault(values
["mac-address"], [])
76 if_mac_list
[values
["mac-address"]].append((name
, values
.get("state")))
80 for idx
, entry
in enumerate(sorted(interfaces
)):
81 nic_name
, values
= entry
, interfaces
[entry
]
83 speed
= values
.get("speed", 0)
84 state
= values
.get("state", "2")
86 # Try to determine the speed and state for virtual interfaces
87 # We know all physical interfaces for this virtual device and use the highest available
88 # speed as the virtual speed. Note: Depending on the configuration this behaviour might
89 # differ, e.g. the speed of all interfaces might get accumulated..
90 # Additionally, we check if not all interfaces of the virtual group share the same connection speed
92 if "mac-address" in values
:
93 mac_list
= if_mac_list
[values
["mac-address"]]
94 if len(mac_list
) > 1: # check if this interface is grouped
95 extra_info
.setdefault(nic_name
, {})
96 extra_info
[nic_name
]["grouped_if"] = [x
for x
in mac_list
if x
not in vif_list
]
100 for tmp_if
, state
in mac_list
:
101 if tmp_if
== nic_name
or "speed" not in interfaces
[tmp_if
]:
103 check_speed
= interfaces
[tmp_if
]["speed"]
104 max_speed
= max(max_speed
, check_speed
)
105 min_speed
= min(min_speed
, check_speed
)
106 if max_speed
!= min_speed
:
107 extra_info
[nic_name
]["speed_differs"] = (max_speed
, min_speed
)
110 # Virtual interfaces is "Up" if at least one physical interface is up
111 if "state" not in values
:
112 if "mac-address" in values
:
113 for tmp_if
, state
in if_mac_list
[values
["mac-address"]]:
114 if interfaces
[tmp_if
].get("state") == "1":
118 # Only add interfaces with counters
119 if "recv_data" in values
:
120 if values
.get("mac-address"):
121 mac
= "".join(chr(int(x
, 16)) for x
in values
["mac-address"].split(':'))
126 nic
[0] = str(idx
+ 1) # Index
127 nic
[1] = nic_name
# Description
128 nic
[2] = "6" # Fake ethernet # Type
129 nic
[3] = speed
# Speed
130 nic
[4] = state
# Status
132 nic
[5] = values
.get("recv_data", 0) # inoctets
133 nic
[6] = values
.get("recv_packet", 0) # inucast
134 nic
[7] = values
.get("recv_mcasts", 0) # inmcast
136 nic
[9] = 0 # indiscards
137 nic
[10] = values
.get("recv_errors", 0) # inerrors
139 nic
[11] = values
.get("send_data", 0) # outoctets
140 nic
[12] = values
.get("send_packet", 0) # outucast
141 nic
[13] = values
.get("send_mcasts", 0) # outmcast
142 nic
[14] = 0 # outbcast
143 nic
[15] = 0 # outdiscards
144 nic
[16] = values
.get("send_errors", 0) # outspeed
145 nic
[17] = 0 # outqlen
146 nic
[18] = values
.get("interface-name", "") # Alias
151 return nics
, extra_info
154 def inventory_netapp_api_if(parsed
):
155 nics
, _extra_info
= parsed
156 return inventory_if_common(nics
)
159 def check_netapp_api_if(item
, params
, parsed
):
160 nics
, extra_info
= parsed
161 yield check_if_common(item
, params
, nics
)
167 if isinstance(ifIndex
, tuple):
168 _ifGroup
, ifIndex
= ifIndex
170 ifDescr_cln
= cleanup_if_strings(ifDescr
)
171 ifAlias_cln
= cleanup_if_strings(ifAlias
)
173 if if_item_matches(item
, ifIndex
, ifAlias_cln
, ifDescr_cln
):
174 if ifDescr
in extra_info
:
175 vif_group
= extra_info
[ifDescr
]
176 for member_name
, member_state
in vif_group
["grouped_if"]:
177 if member_state
is None or member_name
== ifDescr
:
178 continue # Not a real member or the grouped interface itself
180 if member_state
== "2":
186 yield state
, "Physical interfaces: %s(%s)" % (member_name
,
187 if_statename(member_state
))
190 yield state
, "%s(%s)" % (member_name
, if_statename(member_state
))
192 if "speed_differs" in vif_group
:
193 yield 1, "Interfaces do not have the same speed"
196 check_info
["netapp_api_if"] = {
197 'check_function': check_netapp_api_if
,
198 'inventory_function': inventory_netapp_api_if
,
199 'parse_function': netapp_convert_to_if64
,
200 'service_description': 'Interface %s',
201 'has_perfdata': True,
203 'includes': ['if.include', 'netapp_api.include'],
204 'default_levels_variable': 'if_default_levels',