Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / hpux_if
bloba2e69a3afc2705057ac533f13f19e0e90c79365a
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 ## Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll
28 # <<<hpux_if>>>
30 # *** lan0 64 bit MIB statistics:
31 # Interface Name = lan0
32 # PPA Number = 0
33 # Description = lan0 HP PCI-X 1000Base-T Release PHNE_36238 B.11.31.0709.02
34 # Interface Type = 1000Base-T
35 # MTU Size = 1500
36 # Speed = 1 Gbps
37 # Station Address = 0x001A4B067700
38 # Administration Status = UP
39 # Operation Status = UP
40 # Last Change = Tue Jul 13 10:36:24 2010
41 # Inbound Octets = 30886837904
42 # Inbound Unicast Packets = 25436296
43 # Inbound Multicast Packets = 0
44 # Inbound Broadcast Packets = 357491069
45 # Inbound Discards = 0
46 # Inbound Errors = 0
47 # Inbound Unknown Protocols = 357491069
48 # Outbound Octets = 3510268106
49 # Outbound Unicast Packets = 25436308
50 # Outbound Multicast Packets = 0
51 # Outbound Broadcast Packets = 0
52 # Outbound Discards = 0
53 # Outbound Errors = 0
54 # Counter Discontinuity Time = Tue Jul 13 10:36:24 2010
55 # Physical Promiscuous Mode = FALSE
56 # Physical Connector Present = TRUE
57 # Interface Alias =
58 # Link Up/Down Trap Enable = Enabled
61 def hpux_convert_to_if64(info):
62 nics = []
63 for line in info:
64 if '***' in line:
65 nic = ['0'] * 20
66 nics.append(nic)
67 nic[2] = '6' # fake port type Ethernet
68 elif '=' in line:
69 line_txt = " ".join(line)
70 left, right = line_txt.split("=")
71 left = left.strip()
72 right = right.strip()
73 if left == "PPA Number":
74 nic[0] = right
75 elif left == "Speed":
76 nic[3] = hpux_parse_speed(right)
77 elif left == "Inbound Octets":
78 nic[5] = right
79 elif left == "Inbound Unicast Packets":
80 nic[6] = right
81 elif left == "Inbound Multicast Packets":
82 nic[7] = right
83 elif left == "Inbound Broadcast Packets":
84 nic[8] = right
85 elif left == "Inbound Discards":
86 nic[9] = right
87 elif left == "Inbound Errors":
88 nic[10] = right
89 elif left == "Outbound Octets":
90 nic[11] = right
91 elif left == "Outbound Unicast Packets":
92 nic[12] = right
93 elif left == "Outbound Multicast Packets":
94 nic[13] = right
95 elif left == "Outbound Broadcast Packets":
96 nic[14] = right
97 elif left == "Outbound Discards":
98 nic[15] = right
99 elif left == "Outbound Errors":
100 nic[16] = right
101 elif left == "Operation Status":
102 nic[4] = hpux_parse_operstatus(right)
103 elif left == "Interface Name":
104 nic[1] = right
105 nic[18] = right
106 elif left == "Station Address":
107 h = right[2:]
108 nic[19] = "".join([chr(int(x + y, 16)) for (x, y) in zip(h[::2], h[1::2])])
109 return nics
112 def hpux_parse_speed(speed):
113 parts = speed.split()
114 if parts[1] == "Gbps":
115 mult = 1000 * 1000 * 1000
116 else:
117 mult = 1000 * 1000
118 return float(parts[0]) * mult
121 def hpux_parse_operstatus(txt):
122 if txt.lower() == "up":
123 return '1'
124 return '2'
127 def inventory_hpux_if(info):
128 return inventory_if_common(hpux_convert_to_if64(info))
131 def check_hpux_if(item, params, info):
132 return check_if_common(item, params, hpux_convert_to_if64(info))
135 check_includes['hpux_if'] = ["if.include"]
137 check_info["hpux_if"] = {
138 'check_function': check_hpux_if,
139 'inventory_function': inventory_hpux_if,
140 'service_description': 'NIC %s',
141 'has_perfdata': True,
142 'group': 'if',
143 'default_levels_variable': 'if_default_levels',