File: snmp__if_err_.in

package info (click to toggle)
munin 2.0.76-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,068 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (188 lines) | stat: -rw-r--r-- 5,613 bytes parent folder | download | duplicates (5)
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
#!@@PERL@@ -w
# -*- cperl -*-

=head1 NAME

snmp__if_err_ - SNMP wildcard plugin to monitor errors on 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.

Specific interface names (labels) are determined via the SNMP OID for
aliases (1.3.6.1.2.1.31.1.1.1.18.*).  These can be overridden via the
"alias" environment variable:

   [snmp_hostname.fqdn_if_2]
   env.alias WAN

The symlink name of the plugin determines the host and the switch
port.  The switch port may be a number or the interface name
(e.g. "ethN.VID@ethN").  This is primarily useful on devices where
the interface number is not guaranteed to be consistent, such as is
the case with some Linux based systems.

=head1 INTERPRETATION

The graph shows a stright forward gauge of errors per second.  This
graph sums all different kinds of interface errors.

=head1 MIB INFORMATION

The pluguin requires the IF-MIB, the standard IETF MIB for network
interfaces.  It sums these OIDs: IF-MIB::ifInDiscards,
IF-MIB::ifInErrors, IF-MIB::ifInUnknownProtos, IF-MIB::ifOutDiscards
and IF-MIB::ifOutErrors.

=head1 MAGIC MARKERS

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

=head1 BUGS

None known.

Earlier versions of this plugin only reported the ifInErrors and
ifOutErrors numbers.  This does not encompas all errors on a interface
therefore the change.

=head1 AUTHORS

Copyright (C) 2004 Jimmy Olsen
Copyright (C) 2005 Dagfinn Ilmari Mannsåker
Copyright (C) 2009 Nicolai Langfeldt

=head1 LICENSE

GPLv2

=cut

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


my $response;

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.10. [1-9]\n"; # ifInOctets
	exit 0;
}

my ($host) = Munin::Plugin::SNMP->config_session();

my $iface;

my $session = Munin::Plugin::SNMP->session();

if ($Munin::Plugin::me =~ /if_err_(\d+)$/) {
    $iface = $1;
} elsif ($Munin::Plugin::me =~ /_if_err_([\w\@.-]+)$/) {
    my $ifAliasContainer = "1.3.6.1.2.1.31.1.1.1.18.";
    my $if_alias = $session->get_by_regex($ifAliasContainer, "^$1\$");
    if (keys(%{$if_alias}) != 1) {
	die "Could not determine interface number from ".$Munin::Plugin::me."\n";
    }
    $iface = (keys %{$if_alias})[0];
} 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 $ifEntryAlias     = "1.3.6.1.2.1.31.1.1.1.18.$iface";

my $ifStatus         = "1.3.6.1.2.1.2.2.1.8.$iface";

my $ifInDiscards     = "1.3.6.1.2.1.2.2.1.13.$iface";
my $ifInErrors       = "1.3.6.1.2.1.2.2.1.14.$iface";
my $ifInUnknownProtos= "1.3.6.1.2.1.2.2.1.15.$iface";
my $ifOutDiscards    = "1.3.6.1.2.1.2.2.1.19.$iface";
my $ifOutErrors      = "1.3.6.1.2.1.2.2.1.20.$iface";

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

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

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

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

    my $extrainfo = '';

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

    # Any error is too many
    my $warn = 1;

    print "graph_title Interface $alias errors\n";
    print "graph_order recv send\n";
    print "graph_args --base 1000\n";
    print "graph_vlabel Errors in (-) / out (+) per \${graph_period}\n";
    print "graph_category network\n";
    print "graph_info This graph shows all kinds of errors for the \"$alias\" network interface.$extrainfo\n";
    print "send.info Number of unsuccessfull send/receive operations (errors) on this interface.\n";
    print "recv.label recv\n";
    print "recv.type DERIVE\n";
    print "recv.graph no\n";
    print "recv.min 0\n";
    print "recv.warning ", ($warn), "\n" if defined $warn;
    print "send.label errors\n";
    print "send.type DERIVE\n";
    print "send.negative recv\n";
    print "send.min 0\n";
    print "send.warning $warn\n" if defined $warn;
    exit 0;
}

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

my $recv = ($session->get_single($ifInErrors) || 0) +
  ($session->get_single($ifInDiscards) || 0) +
  ($session->get_single($ifInUnknownProtos) || 0);

my $send = ($session->get_single($ifOutErrors) || 0) +
  ($session->get_single($ifOutDiscards) || 0);

print "recv.value ", $recv, "\n";
print "send.value ", $send, "\n";