File: snmp__if_err_.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (216 lines) | stat: -rwxr-xr-x 5,724 bytes parent folder | download | duplicates (3)
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
#!@@PERL@@ -w
#
# Copyright (C) 2004 Jimmy Olsen, Dagfinn Ilmari Mannsaaker
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
#
# $Log$
# Revision 1.16  2004/12/10 18:51:43  jimmyo
# linux/apt* has been forced to LANG=C, to get predictable output.
#
# Revision 1.15  2004/12/10 10:47:47  jimmyo
# Change name from ${scale} to ${graph_period}, to be more consistent.
#
# Revision 1.14  2004/12/09 22:12:55  jimmyo
# Added "graph_period" option, to make "graph_sums" usable.
#
# Revision 1.13  2004/11/21 00:16:56  jimmyo
# Changed a lot of plugins so they use DERIVE instead of COUNTER.
#
# Revision 1.12  2004/11/20 22:37:21  jimmyo
# Strip strange characters.
#
# Revision 1.11  2004/11/20 22:10:49  jimmyo
# Clean up output of plugin a bit.
#
# Revision 1.10  2004/11/20 22:06:22  jimmyo
# Clean up output of plugin a bit.
#
# Revision 1.9  2004/11/16 20:08:26  jimmyo
# License cleanups.
#
# Revision 1.8  2004/11/12 20:28:03  ilmari
# No debugging info by default
#
# Revision 1.7  2004/09/08 15:25:33  ilmari
# Use @@PERL@@ in all perl shebang lines.
#
# Revision 1.6  2004/09/07 13:19:22  ilmari
# SNMP plugins now honour the "host" environment variable if they can't deduce the hostname from zsh.
#
# Revision 1.5  2004/09/05 12:00:18  jimmyo
# Set family and capabilities.
#
# Revision 1.4  2004/09/04 21:58:28  jimmyo
# Set category and info fields.
#
# Revision 1.3  2004/09/04 19:12:14  jimmyo
# Accept ppp interfaces as well as ethernet interfaces.
#
# Revision 1.2  2004/04/30 22:20:22  jimmyo
# It should now even work. :-)
#
# Revision 1.1  2004/04/30 16:59:45  jimmyo
# New SNMP plugin: if_err
#
# Revision 1.3  2004/02/22 20:17:58  jimmyo
# Typo fix
#
# Revision 1.2  2004/02/18 21:54:56  jimmyo
# Did a bit of work on the snmp-thingie.
#
# Revision 1.1  2004/01/02 18:50:00  jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.1  2003/12/19 20:53:45  jimmyo
# Created by jo
#
#
#%# family=snmpauto
#%# capabilities=snmpconf

use strict;
use Net::SNMP;

my $DEBUG = 0;

my $host      = $ENV{host}      || undef;
my $port      = $ENV{port}      || 161;
my $community = $ENV{community} || "public";
my $iface     = $ENV{interface} || undef;

my $response;

if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
{
	print "number  1.3.6.1.2.1.2.1.0\n";
	print "index   1.3.6.1.2.1.2.2.1.1.\n";
	print "require 1.3.6.1.2.1.2.2.1.3. ^(6|23)\$\n"; # Type
	print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed
	exit 0;
}

if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_if_err_(.+)$/)
{
	$host  = $1;
	$iface = $2;
	if ($host =~ /^([^:]+):(\d+)$/)
	{
		$host = $1;
		$port = $2;
	}
}
elsif (!defined($host))
{
	print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
	die "# Error: couldn't understand what I'm supposed to monitor.";
}

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 $ifEntryInErrors  = "1.3.6.1.2.1.2.2.1.14.$iface";
my $ifEntryOutErrors = "1.3.6.1.2.1.2.2.1.20.$iface";

my ($session, $error) = Net::SNMP->session(
		-hostname  => $host,
		-community => $community,
		-port      => $port
	);

if (!defined ($session))
{
	die "Croaking: $error";
}

if ($ARGV[0] and $ARGV[0] eq "config")
{
	print "host_name $host\n";
	if (!defined ($response = $session->get_request($ifEntryDescr)))
	{
		die "Croaking: " . $session->error();
	}
	my $name = $response->{$ifEntryDescr};
	$name =~ s/[^\w\s]//g;
	my $warn = undef;
	if (defined ($response = $session->get_request($ifEntrySpeed)))
	{
		$warn = $response->{$ifEntrySpeed}/8;
	}
	if (length ($name) > 15)
	{
		print "graph_title Interface $iface errors\n";
	}
	else
	{
		print "graph_title Interface $name errors\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 errors for the \"$name\" network interface.\n";
	print "send.info Bits unsuccessfully 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 2000000000\n";
	print "recv.min 0\n";
	print "recv.warn ", (-$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 2000000000\n";
	print "send.min 0\n";
	print "send.warn $warn\n" if defined $warn;
	exit 0; 
}

my $status = 1;
if (defined ($response = $session->get_request($ifEntryStatus)))
{
	$status = $response->{$ifEntryStatus};
}

if ($status == 2)
{
	print "recv.value U\n";
	print "send.value U\n";
	exit 0;
}

if (defined ($response = $session->get_request($ifEntryInErrors)))
{
	print "recv.value ", $response->{$ifEntryInErrors}, "\n";
}
else
{
	print "recv.value U\n";
}

if (defined ($response = $session->get_request($ifEntryOutErrors)))
{
	print "send.value ", $response->{$ifEntryOutErrors}, "\n";
}
else
{
	print "send.value U\n";
}