Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / snmp__if_ @ dd4afac8

Historique | Voir | Annoter | Télécharger (4,38 ko)

1
#!/usr/bin/perl -w
2
##
3
## Copyright (C) 2007 OZ
4
##
5
## interface-traffic including warnlevels, based on snmp__if_.
6
##
7
## supports entries for maximum bitrates in
8
## /etc/munin/plugin-conf.d/munin-node like:
9
## [snmp_<hostname>_if_*]
10
## env.levelwarn 800000
11
## env.levelcrit 1000000
12
##
13
## This program is free software; you can redistribute it and/or
14
## modify it under the terms of the GNU General Public License
15
## as published by the Free Software Foundation; version 2 dated June,
16
## 1991.
17
##
18
## This program is distributed in the hope that it will be useful,
19
## but WITHOUT ANY WARRANTY; without even the implied warranty of
20
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
## GNU General Public License for more details.
22
##
23
## You should have received a copy of the GNU General Public License
24
## along with this program; if not, write to the Free Software
25
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26
##
27

    
28
## Revision 0.1  2007/01/18 15:00:00  oz
29

    
30
#
31
#%# family=snmpauto
32
#%# capabilities=snmpconf
33

    
34
use strict;
35
use Net::SNMP;
36

    
37
my $DEBUG = 0;
38

    
39
my $host      = $ENV{host}      || undef;
40
my $port      = $ENV{port}      || 161;
41
my $community = $ENV{community} || "public";
42
my $iface     = $ENV{interface} || undef;
43

    
44
my $response;
45

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

    
55
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_if_(.+)$/)
56
{
57
	$host  = $1;
58
	$iface = $2;
59
	if ($host =~ /^([^:]+):(\d+)$/)
60
	{
61
		$host = $1;
62
		$port = $2;
63
	}
64
}
65
elsif (!defined($host))
66
{
67
	print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
68
	die "# Error: couldn't understand what I'm supposed to monitor.";
69
}
70

    
71
my $ifEntryDescr     = "1.3.6.1.2.1.2.2.1.2.$iface"; 
72
my $ifEntrySpeed     = "1.3.6.1.2.1.2.2.1.5.$iface";
73
my $ifEntryStatus    = "1.3.6.1.2.1.2.2.1.8.$iface";
74
my $ifEntryInOctets  = "1.3.6.1.2.1.2.2.1.10.$iface";
75
my $ifEntryOutOctets = "1.3.6.1.2.1.2.2.1.16.$iface";
76

    
77
my ($session, $error) = Net::SNMP->session(
78
		-hostname  => $host,
79
		-community => $community,
80
		-port      => $port
81
	);
82

    
83
if (!defined ($session))
84
{
85
	die "Croaking: $error";
86
}
87

    
88
if ($ARGV[0] and $ARGV[0] eq "config")
89
{
90
	print "host_name $host\n";
91
	if (!defined ($response = $session->get_request($ifEntryDescr)))
92
	{
93
		die "Croaking: " . $session->error();
94
	}
95
	my $name = $response->{$ifEntryDescr};
96
	$name =~ s/[^\w\s]//g;
97
	my $warn = undef;
98
	if (defined ($response = $session->get_request($ifEntrySpeed)))
99
	{
100
		$warn = $response->{$ifEntrySpeed}/8;
101
	}
102
	my $levelwarn=undef;
103
	$levelwarn=$ENV{levelwarn} if defined($ENV{levelwarn});
104
	my $levelcrit=undef;
105
	$levelcrit=$ENV{levelcrit} if defined($ENV{levelcrit});
106
	if (length ($name) > 15)
107
	{
108
		print "graph_title Interface $iface traffic\n";
109
	}
110
	else
111
	{
112
		print "graph_title Interface $name traffic\n";
113
	}
114
	print "graph_order recv send\n";
115
	print "graph_args --base 1000\n";
116
	print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
117
	print "graph_category network\n";
118
	print "graph_info This graph shows traffic for the \"$name\" network interface.\n";
119
	print "send.info Bits sent/received by this interface.\n";
120
	print "recv.label recv\n";
121
	print "recv.type DERIVE\n";
122
	print "recv.graph no\n";
123
	print "recv.cdef recv,8,*\n";
124
	print "recv.max 2000000000\n";
125
	print "recv.min 0\n";
126
	print "recv.warn ", (-$warn), "\n" if defined $warn;
127
	print "recv.warning $levelwarn\n" if defined $levelwarn;
128
	print "recv.critical $levelcrit\n" if defined $levelcrit;
129
	print "send.label bps\n";
130
	print "send.type DERIVE\n";
131
	print "send.negative recv\n";
132
	print "send.cdef send,8,*\n";
133
	print "send.max 2000000000\n";
134
	print "send.min 0\n";
135
	print "send.warn $warn\n" if defined $warn;
136
	print "send.warning $levelwarn\n" if defined $levelwarn;
137
	print "send.critical $levelcrit\n" if defined $levelcrit;
138
	exit 0; 
139
}
140

    
141
my $status = 1;
142
if (defined ($response = $session->get_request($ifEntryStatus)))
143
{
144
	$status = $response->{$ifEntryStatus};
145
}
146

    
147
if ($status == 2)
148
{
149
	print "recv.value U\n";
150
	print "send.value U\n";
151
	exit 0;
152
}
153

    
154
if (defined ($response = $session->get_request($ifEntryInOctets)))
155
{
156
	print "recv.value ", $response->{$ifEntryInOctets}, "\n";
157
}
158
else
159
{
160
	print "recv.value U\n";
161
}
162

    
163
if (defined ($response = $session->get_request($ifEntryOutOctets)))
164
{
165
	print "send.value ", $response->{$ifEntryOutOctets}, "\n";
166
}
167
else
168
{
169
	print "send.value U\n";
170
}