This file is indexed.

/usr/share/munin/plugins/snmp__if_ is in munin-plugins-core 2.0.19-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/perl -w
# -*- cperl -*-

=head1 NAME

snmp__if_ - SNMP wildcard plugin to monitor network interfaces of any networked equipment.

=head1 APPLICABLE SYSTEMS

Any SNMP capable networked computer equipment.  Using a command such
as "munin-node-configure --snmp switch.langfeldt.net --snmpversion 2c
--snmpcommunity public | sh -x" should auto-detect all applicable
interfaces.  On a typical switch you will get one plugin pr. ethernet
port.  On a router you might get one plugin pr. VLAN interface.

=head1 CONFIGURATION

As a rule SNMP plugins need site specific configuration.  The default
configuration (shown here) will only work on insecure sites/devices:

   [snmp_*]
	env.version 2
        env.community public

In general SNMP is not very secure at all unless you use SNMP version
3 which supports authentication and privacy (encryption).  But in any
case the community string for your devices should not be "public".

Please see 'perldoc Munin::Plugin::SNMP' for further configuration
information.

=head1 INTERPRETATION

The graph shows a stright forward "bits per second" incomming and
outgoing thruput.  "Incomming" is towards the monitored device.

Note: The internal representation of the speeds is in bytes
pr. second.  The plugin multiplies everyting by 8 to get bits
pr. second.

=head1 MIB INFORMATION

This plugin requires the IF-MIB the standard IETF MIB for network
interfaces.  It reports the contents of the
IF-MIB::ifHCInOctets/IF-MIB::ifHCOutOctets if available,
IF-MIB::ifInOctets/IF-MIB::ifOutOctets if not.  The former are 64 bit
counters only available with SNMP 2 and later.  The later are 32 bit
counters (see FEATURES below).

=head1 MAGIC MARKERS

  #%# family=snmpauto
  #%# capabilities=snmpconf

=head1 VERSION

  $Id$

=head1 BUGS

None known.

=head1 FEATURES

You may get strange results if you use SNMPv1, or SNMPv2 on
switches that do not support 64 bit byte counters.  If the interface
traffic exceeds about 50Mbps a 32 bit byte counter will wrap around in
less than 5 minutes making the graph for the interface show random
results.

If you have a switch/device that supports 64 bit byte counters this plugin
will use them and the graph will be fine.  The graph information will
inform about this.  You must use SNMPv2c or SNMPv3 to be able to use
64 bit counters - if the device supports them.

This problem is a feature of the device SNMP implementation or your
usage of it, it is nothing the plugin can fix.  In the future Munin
may be able to run the plugin more often than the counter wraps
around.

=head1 AUTHOR

Copyright (C) 2004-2009 Jimmy Olsen, Daginn Ilmari Mannsaaker.
Documentation, porting to Munin::Plugin::SNMP and further grooming by
Nicolai Langfeldt.

Initial SNMPv3 support by "Confusedhacker".

=head1 LICENSE

GPLv2

=cut

use strict;
use Munin::Plugin;
use Munin::Plugin::SNMP;


my $response;
my $iface;

# This is the snmpwalk:
# .1.3.6.1.2.1.2.1.0 = INTEGER: 2
# .1.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
# .1.3.6.1.2.1.2.2.1.1.65539 = INTEGER: 65539
# .1.3.6.1.2.1.2.2.1.2.1 = STRING: MS TCP Loopback interface
# .1.3.6.1.2.1.2.2.1.2.65539 = STRING: Broadcom NetXtreme Gigabit Ethernet
# .1.3.6.1.2.1.2.2.1.3.1 = INTEGER: softwareLoopback(24)
# .1.3.6.1.2.1.2.2.1.3.65539 = INTEGER: ethernetCsmacd(6)
# .1.3.6.1.2.1.2.2.1.4.1 = INTEGER: 1520
# .1.3.6.1.2.1.2.2.1.4.65539 = INTEGER: 1500
# .1.3.6.1.2.1.2.2.1.5.1 = Gauge32: 10000000
# .1.3.6.1.2.1.2.2.1.5.65539 = Gauge32: 1000000000
# .1.3.6.1.2.1.2.2.1.6.1 = STRING:
# .1.3.6.1.2.1.2.2.1.6.65539 = STRING: 0:30:48:75:65:5e
# .1.3.6.1.2.1.2.2.1.7.1 = INTEGER: up(1)
# .1.3.6.1.2.1.2.2.1.7.65539 = INTEGER: up(1)
# .1.3.6.1.2.1.2.2.1.8.1 = INTEGER: up(1)
# .1.3.6.1.2.1.2.2.1.8.65539 = INTEGER: up(1)
#
# 64 bit counters:
# .1.3.6.1.2.1.31.1.1.1.6.   Counter64 ifHCInOctets
# .1.3.6.1.2.1.31.1.1.1.10.  Counter64 ifHCOutOctets

if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
	print "index   1.3.6.1.2.1.2.2.1.1.\n";
	print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n";  # Speed
	print "require 1.3.6.1.2.1.2.2.1.10. [1-9]\n"; # ifInOctets
	exit 0;
}

if ($Munin::Plugin::me =~ /_if_(\d+)$/) {
    $iface = $1;
} else {
    die "Could not determine interface number from ".$Munin::Plugin::me."\n";
}

my $ifEntryDescr       = "1.3.6.1.2.1.2.2.1.2.$iface";
my $ifEntrySpeed       = "1.3.6.1.2.1.2.2.1.5.$iface";
my $ifEntryStatus      = "1.3.6.1.2.1.2.2.1.8.$iface";
my $ifEntryInOctets    = "1.3.6.1.2.1.2.2.1.10.$iface";
my $ifEntryOutOctets   = "1.3.6.1.2.1.2.2.1.16.$iface";

# Only available with SNMPv2 and up.
my $ifEntryAlias       = "1.3.6.1.2.1.31.1.1.1.18.$iface";
my $ifEntryIn64Octets  = "1.3.6.1.2.1.31.1.1.1.6.$iface";
my $ifEntryOut64Octets = "1.3.6.1.2.1.31.1.1.1.10.$iface";

my ($session, $error);

# SNMP needed for both config and fetch.
$session = Munin::Plugin::SNMP->session();

if ($ARGV[0] and $ARGV[0] eq "config") {
    my ($host,undef,$version) = Munin::Plugin::SNMP->config_session();

    print "host_name $host\n" unless $host eq 'localhost';

    my $alias = $session->get_single($ifEntryAlias) ||
      $session->get_single($ifEntryDescr) ||
	"Interface $iface";

    if (! ($alias =~ /\d+/) ) {
	# If there are no numbers in the $alias add the if index
	$alias .=" (if $iface)";
    }

    my $extrainfo = '';

    if (defined ($response = $session->get_single($ifEntryStatus))) {
	if ($response == 2) {
	    # Interface is down
	    $extrainfo .= ' The interface is currently down.'
	}
    }

    my $warn = undef;
    my $speed = undef;

    if (defined ($speed = $session->get_single($ifEntrySpeed))) {
	$warn = $speed/8;

	# Warn at 1/8th of actuall speed?  Or just remove warning?
	# Tempted to set warning at 80%. 80% over 5 minutes is pretty
	# busy.

	my $textspeed = scaleNumber($speed,,'bps','',
				   'The interface speed is %.1f%s%s.');

	$extrainfo .= " ".$textspeed if $textspeed;
    }

    if (defined ($session->get_single($ifEntryIn64Octets))) {

	# If we get an answer at the 64 bit OID then this switch
	# supports the extended MIB

	$extrainfo .= " This switch supports 64 bit byte counters and these are used by this plugin.";
    } else {
	# If not we only have a 32 bit counter and are lost.
	$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.";

	# unless perhaps the operator can get us snmp version 2c or 3?
	$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."
	  if $version == 1;
    }

    print "graph_title Interface $alias traffic\n";
    print "graph_order recv send\n";
    print "graph_args --base 1000\n";
    print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
    print "graph_category network\n";
    print "graph_info This graph shows traffic for the \"$alias\" network interface.$extrainfo\n";
    print "send.info Bits sent/received by this interface.\n";
    print "recv.label recv\n";
    print "recv.type DERIVE\n";
    print "recv.graph no\n";
    print "recv.cdef recv,8,*\n";
    print "recv.max $speed\n";
    print "recv.min 0\n";
    print "recv.warning ", (-$warn), "\n" if defined $warn;
    print "send.label bps\n";
    print "send.type DERIVE\n";
    print "send.negative recv\n";
    print "send.cdef send,8,*\n";
    print "send.max $speed\n";
    print "send.min 0\n";
    print "send.warning $warn\n" if defined $warn;
    exit 0;
}

if (defined ($response = $session->get_single($ifEntryStatus))) {
    if ($response == 2) {
	# Interface is down
	print "recv.value U\n";
	print "send.value U\n";
	exit 0;
    }
}

if (defined ($response = $session->get_single($ifEntryIn64Octets) ||
	                 $session->get_single($ifEntryInOctets))) {
    print "recv.value ", $response, "\n";
} else {
    # No response...
    print "recv.value U\n";
}

if (defined ($response = $session->get_single($ifEntryOut64Octets) ||
	                 $session->get_single($ifEntryOutOctets))) {
    print "send.value ", $response, "\n";
} else {
    # No response...
    print "send.value U\n";
}