]> jfr.im git - munin-plugins.git/blob - snmp__if_pfsense_ppp_
support for a 2nd unbound plugin
[munin-plugins.git] / snmp__if_pfsense_ppp_
1 #!/usr/bin/perl -w
2 # -*- cperl -*-
3
4 =head1 NAME
5
6 snmp__if_ - SNMP wildcard plugin to monitor network interfaces of any networked equipment.
7
8 =head1 APPLICABLE SYSTEMS
9
10 Any SNMP capable networked computer equipment. Using a command such
11 as "munin-node-configure --snmp switch.langfeldt.net --snmpversion 2c
12 --snmpcommunity public | sh -x" should auto-detect all applicable
13 interfaces. On a typical switch you will get one plugin pr. ethernet
14 port. On a router you might get one plugin pr. VLAN interface.
15
16 =head1 CONFIGURATION
17
18 As a rule SNMP plugins need site specific configuration. The default
19 configuration (shown here) will only work on insecure sites/devices:
20
21 [snmp_*]
22 env.version 2
23 env.community public
24
25 In general SNMP is not very secure at all unless you use SNMP version
26 3 which supports authentication and privacy (encryption). But in any
27 case the community string for your devices should not be "public".
28
29 Please see 'perldoc Munin::Plugin::SNMP' for further configuration
30 information.
31
32 =head1 INTERPRETATION
33
34 The graph shows a stright forward "bits per second" incomming and
35 outgoing thruput. "Incomming" is towards the monitored device.
36
37 Note: The internal representation of the speeds is in bytes
38 pr. second. The plugin multiplies everyting by 8 to get bits
39 pr. second.
40
41 =head1 MIB INFORMATION
42
43 This plugin requires the IF-MIB the standard IETF MIB for network
44 interfaces. It reports the contents of the
45 IF-MIB::ifHCInOctets/IF-MIB::ifHCOutOctets if available,
46 IF-MIB::ifInOctets/IF-MIB::ifOutOctets if not. The former are 64 bit
47 counters only available with SNMP 2 and later. The later are 32 bit
48 counters (see FEATURES below).
49
50 =head1 MAGIC MARKERS
51
52 #%# family=snmpauto
53 #%# capabilities=snmpconf
54
55 =head1 VERSION
56
57 $Id$
58
59 =head1 BUGS
60
61 None known.
62
63 =head1 FEATURES
64
65 You may get strange results if you use SNMPv1, or SNMPv2 on
66 switches that do not support 64 bit byte counters. If the interface
67 traffic exceeds about 50Mbps a 32 bit byte counter will wrap around in
68 less than 5 minutes making the graph for the interface show random
69 results.
70
71 If you have a switch/device that supports 64 bit byte counters this plugin
72 will use them and the graph will be fine. The graph information will
73 inform about this. You must use SNMPv2c or SNMPv3 to be able to use
74 64 bit counters - if the device supports them.
75
76 This problem is a feature of the device SNMP implementation or your
77 usage of it, it is nothing the plugin can fix. In the future Munin
78 may be able to run the plugin more often than the counter wraps
79 around.
80
81 =head1 AUTHOR
82
83 Copyright (C) 2004-2009 Jimmy Olsen, Daginn Ilmari Mannsaaker.
84 Documentation, porting to Munin::Plugin::SNMP and further grooming by
85 Nicolai Langfeldt.
86
87 Initial SNMPv3 support by "Confusedhacker".
88
89 =head1 LICENSE
90
91 GPLv2
92
93 =cut
94
95 use strict;
96 use Munin::Plugin;
97 use Munin::Plugin::SNMP;
98
99
100 my $response;
101 my $iface;
102
103 # This is the snmpwalk:
104 # .1.3.6.1.2.1.2.1.0 = INTEGER: 2
105 # .1.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
106 # .1.3.6.1.2.1.2.2.1.1.65539 = INTEGER: 65539
107 # .1.3.6.1.2.1.2.2.1.2.1 = STRING: MS TCP Loopback interface
108 # .1.3.6.1.2.1.2.2.1.2.65539 = STRING: Broadcom NetXtreme Gigabit Ethernet
109 # .1.3.6.1.2.1.2.2.1.3.1 = INTEGER: softwareLoopback(24)
110 # .1.3.6.1.2.1.2.2.1.3.65539 = INTEGER: ethernetCsmacd(6)
111 # .1.3.6.1.2.1.2.2.1.4.1 = INTEGER: 1520
112 # .1.3.6.1.2.1.2.2.1.4.65539 = INTEGER: 1500
113 # .1.3.6.1.2.1.2.2.1.5.1 = Gauge32: 10000000
114 # .1.3.6.1.2.1.2.2.1.5.65539 = Gauge32: 1000000000
115 # .1.3.6.1.2.1.2.2.1.6.1 = STRING:
116 # .1.3.6.1.2.1.2.2.1.6.65539 = STRING: 0:30:48:75:65:5e
117 # .1.3.6.1.2.1.2.2.1.7.1 = INTEGER: up(1)
118 # .1.3.6.1.2.1.2.2.1.7.65539 = INTEGER: up(1)
119 # .1.3.6.1.2.1.2.2.1.8.1 = INTEGER: up(1)
120 # .1.3.6.1.2.1.2.2.1.8.65539 = INTEGER: up(1)
121 #
122 # 64 bit counters:
123 # .1.3.6.1.2.1.31.1.1.1.6. Counter64 ifHCInOctets
124 # .1.3.6.1.2.1.31.1.1.1.10. Counter64 ifHCOutOctets
125
126 if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
127 print "index 1.3.6.1.2.1.2.2.1.1.\n";
128 print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed
129 print "require 1.3.6.1.2.1.2.2.1.10. [1-9]\n"; # ifInOctets
130 exit 0;
131 }
132
133 if ($Munin::Plugin::me =~ /_if_(\d+)$/) {
134 # Also accept leading 0 like (snmp_router_if_01 .. snmp_router_if_24)
135 $iface = int $1;
136 } else {
137 die "Could not determine interface number from ".$Munin::Plugin::me."\n";
138 }
139
140 my $ifEntryDescr = "1.3.6.1.2.1.2.2.1.2.$iface";
141 my $ifEntryHiSpeed = "1.3.6.1.2.1.31.1.1.1.15.$iface";
142 my $ifEntrySpeed = "1.3.6.1.2.1.2.2.1.5.$iface";
143 my $ifEntryStatus = "1.3.6.1.2.1.2.2.1.8.$iface";
144 my $ifEntryInOctets = "1.3.6.1.2.1.2.2.1.10.$iface";
145 my $ifEntryOutOctets = "1.3.6.1.2.1.2.2.1.16.$iface";
146
147 # Only available with SNMPv2 and up.
148 my $ifEntryAlias = "1.3.6.1.2.1.31.1.1.1.18.$iface";
149 my $ifEntryIn64Octets = "1.3.6.1.2.1.31.1.1.1.6.$iface";
150 my $ifEntryOut64Octets = "1.3.6.1.2.1.31.1.1.1.10.$iface";
151
152 my ($session, $error);
153
154 # SNMP needed for both config and fetch.
155 $session = Munin::Plugin::SNMP->session();
156 $session->translate([-nosuchinstance => 0]);
157
158 if ($ARGV[0] and $ARGV[0] eq "config") {
159 my ($host,undef,$version) = Munin::Plugin::SNMP->config_session();
160
161 print "host_name $host\n" unless $host eq 'localhost';
162
163 my $alias = $session->get_single($ifEntryAlias) ||
164 $session->get_single($ifEntryDescr) ||
165 "Interface $iface";
166
167 if (! ($alias =~ /\d+/) ) {
168 # If there are no numbers in the $alias add the if index
169 $alias .=" (if $iface)";
170 }
171
172 my $extrainfo = '';
173
174 if (defined ($response = $session->get_single($ifEntryStatus))) {
175 if ($response == 2) {
176 # Interface is down
177 $extrainfo .= ' The interface is currently down.'
178 }
179 }
180
181 my $warn = undef;
182 my $speed = undef;
183
184 if (defined ($speed = $session->get_single($ifEntrySpeed)) && $speed != 64000) {
185 # ifSpeed only supports values up to 4.3Gbps, because it's a
186 # 32-bit value. For faster interfaces, e.g. 10GE or 8Gb/s FC,
187 # use ifHighSpeed instead, which contains the interface speed
188 # in Mbps (e.g. 1000 for GE).
189 #
190 # To detect whether we should use ifHighSpeed, check for an
191 # ifSpeed value of 2^32-1 (4294967295). For some reason
192 # Brocade Fabric OS returns 2^32-2 instead, so check that as
193 # well.
194
195 if ($speed == 4294967294 || $speed == 4294967295) {
196 $speed = $session->get_single($ifEntryHiSpeed)
197 * 1000 * 1000;
198 }
199
200 $warn = ($speed/10)*8;
201
202 # Warn at 1/8th of actuall speed? Or just remove warning?
203 # Tempted to set warning at 80%. 80% over 5 minutes is pretty
204 # busy.
205
206 my $textspeed = scaleNumber($speed,,'bps','',
207 'The interface speed is %.1f%s%s.');
208
209 $extrainfo .= " ".$textspeed if $textspeed;
210 }
211
212 if (defined ($session->get_single($ifEntryIn64Octets))
213 && !($session->get_single($ifEntryIn64Octets) eq '')) {
214
215 # If we get an answer at the 64 bit OID then this switch
216 # supports the extended MIB
217
218 $extrainfo .= " This switch supports 64 bit byte counters and these are used by this plugin.";
219 } else {
220 # If not we only have a 32 bit counter and are lost.
221 $extrainfo .= " NOTE! This switch supports only 32 bit byte counters which makes the plugin unreliable and unsuitable for most 100Mb (or faster) interfaces, where bursts are expected to exceed 50Mbps. This means that for interfaces where much traffic is sent this plugin will report false thruputs and cannot be trusted.";
222
223 # unless perhaps the operator can get us snmp version 2c or 3?
224 $extrainfo .= " I notice that you use SNMP version 1 which does not support 64 bit quantities. You may get better results if you switch to SNMP version 2c or 3. Please refer to the plugin documentation."
225 if $version == 1;
226 }
227
228 print "graph_title Interface $alias traffic\n";
229 print "graph_order recv send\n";
230 print "graph_args --base 1000\n";
231 print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
232 print "graph_category network\n";
233 print "graph_info This graph shows traffic for the \"$alias\" network interface.$extrainfo\n";
234 print "send.info Bits sent/received by this interface.\n";
235 print "recv.label recv\n";
236 print "recv.type DERIVE\n";
237 print "recv.graph no\n";
238 print "recv.cdef recv,8,*\n";
239 print "recv.max $speed\n" if $speed;
240 print "recv.min 0\n";
241 print "recv.warning ", ($warn), "\n" if defined $warn && ($warn != 0);
242 print "send.label bps\n";
243 print "send.type DERIVE\n";
244 print "send.negative recv\n";
245 print "send.cdef send,8,*\n";
246 print "send.max $speed\n" if $speed;
247 print "send.min 0\n";
248 print "send.warning $warn\n" if defined $warn && ($warn != 0);
249 exit 0;
250 }
251
252 if (defined ($response = $session->get_single($ifEntryStatus))) {
253 if ($response == 2) {
254 # Interface is down
255 print "recv.value U\n";
256 print "send.value U\n";
257 exit 0;
258 }
259 }
260
261 if (defined ($response = $session->get_single($ifEntryIn64Octets) ||
262 $session->get_single($ifEntryInOctets))) {
263 print "recv.value ", $response, "\n";
264 } else {
265 # No response...
266 print "recv.value U\n";
267 }
268
269 if (defined ($response = $session->get_single($ifEntryOut64Octets) ||
270 $session->get_single($ifEntryOutOctets))) {
271 print "send.value ", $response, "\n";
272 } else {
273 # No response...
274 print "send.value U\n";
275 }