~ubuntu-branches/ubuntu/gutsy/munin/gutsy

« back to all changes in this revision

Viewing changes to node/node.d/snmp__if_err_.in

  • Committer: Bazaar Package Importer
  • Author(s): Tore Anderson
  • Date: 2004-05-21 20:51:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040521205119-oz8bllbjp9hs80ig
Tags: upstream-0+1.0.0pre5
ImportĀ upstreamĀ versionĀ 0+1.0.0pre5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
#
 
3
# $Log: snmp__if_err_.in,v $
 
4
# Revision 1.2  2004/04/30 22:20:22  jimmyo
 
5
# It should now even work. :-)
 
6
#
 
7
# Revision 1.1  2004/04/30 16:59:45  jimmyo
 
8
# New SNMP plugin: if_err
 
9
#
 
10
# Revision 1.3  2004/02/22 20:17:58  jimmyo
 
11
# Typo fix
 
12
#
 
13
# Revision 1.2  2004/02/18 21:54:56  jimmyo
 
14
# Did a bit of work on the snmp-thingie.
 
15
#
 
16
# Revision 1.1  2004/01/02 18:50:00  jimmyo
 
17
# Renamed occurrances of lrrd -> munin
 
18
#
 
19
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
 
20
# Import of LRRD CVS tree after renaming to Munin
 
21
#
 
22
# Revision 1.1  2003/12/19 20:53:45  jimmyo
 
23
# Created by jo
 
24
#
 
25
#
 
26
 
 
27
use strict;
 
28
use Net::SNMP;
 
29
 
 
30
my $DEBUG = 1;
 
31
 
 
32
my $host      = $ENV{host}      || undef;
 
33
my $port      = $ENV{port}      || 161;
 
34
my $community = $ENV{community} || "public";
 
35
my $iface     = $ENV{interface} || undef;
 
36
 
 
37
my $response;
 
38
 
 
39
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
 
40
{
 
41
        print "number  1.3.6.1.2.1.2.1.0\n";
 
42
        print "index   1.3.6.1.2.1.2.2.1.1.\n";
 
43
        print "require 1.3.6.1.2.1.2.2.1.3. ^6\$\n"; # Type
 
44
        print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed
 
45
        exit 0;
 
46
}
 
47
 
 
48
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_if_err_(.+)$/)
 
49
{
 
50
        $host  = $1;
 
51
        $iface = $2;
 
52
        if ($host =~ /^([^:]+):(\d+)$/)
 
53
        {
 
54
                $host = $1;
 
55
                $port = $2;
 
56
        }
 
57
}
 
58
else
 
59
{
 
60
        print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
 
61
        die "# Error: couldn't understand what I'm supposed to monitor.";
 
62
}
 
63
 
 
64
my $ifEntryDescr     = "1.3.6.1.2.1.2.2.1.2.$iface"; 
 
65
my $ifEntrySpeed     = "1.3.6.1.2.1.2.2.1.5.$iface";
 
66
my $ifEntryStatus    = "1.3.6.1.2.1.2.2.1.8.$iface";
 
67
my $ifEntryInErrors  = "1.3.6.1.2.1.2.2.1.14.$iface";
 
68
my $ifEntryOutErrors = "1.3.6.1.2.1.2.2.1.20.$iface";
 
69
 
 
70
my ($session, $error) = Net::SNMP->session(
 
71
                -hostname  => $host,
 
72
                -community => $community,
 
73
                -port      => $port
 
74
        );
 
75
 
 
76
if (!defined ($session))
 
77
{
 
78
        die "Croaking: $error";
 
79
}
 
80
 
 
81
if ($ARGV[0] and $ARGV[0] eq "config")
 
82
{
 
83
        print "host_name $host\n";
 
84
        if (!defined ($response = $session->get_request($ifEntryDescr)))
 
85
        {
 
86
                die "Croaking: " . $session->error();
 
87
        }
 
88
        my $name = $response->{$ifEntryDescr};
 
89
        my $warn = undef;
 
90
        if (defined ($response = $session->get_request($ifEntrySpeed)))
 
91
        {
 
92
                $warn = $response->{$ifEntrySpeed}/8;
 
93
        }
 
94
        print "graph_title $name errors\n";
 
95
        print "graph_order recv send\n";
 
96
        print "graph_args --base 1000\n";
 
97
        print "graph_vlabel bps in (-) / out (+)\n";
 
98
        print "recv.label recv\n";
 
99
        print "recv.type COUNTER\n";
 
100
        print "recv.graph no\n";
 
101
        print "recv.cdef recv,8,*\n";
 
102
        print "recv.max 2000000000\n";
 
103
        print "recv.warn ", (-$warn), "\n" if defined $warn;
 
104
        print "send.label bps\n";
 
105
        print "send.type COUNTER\n";
 
106
        print "send.negative recv\n";
 
107
        print "send.cdef send,8,*\n";
 
108
        print "send.max 2000000000\n";
 
109
        print "send.warn $warn\n" if defined $warn;
 
110
        exit 0; 
 
111
}
 
112
 
 
113
my $status = 1;
 
114
if (defined ($response = $session->get_request($ifEntryStatus)))
 
115
{
 
116
        $status = $response->{$ifEntryStatus};
 
117
}
 
118
 
 
119
if ($status == 2)
 
120
{
 
121
        print "recv.value U\n";
 
122
        print "send.value U\n";
 
123
        exit 0;
 
124
}
 
125
 
 
126
if (defined ($response = $session->get_request($ifEntryInErrors)))
 
127
{
 
128
        print "recv.value ", $response->{$ifEntryInErrors}, "\n";
 
129
}
 
130
else
 
131
{
 
132
        print "recv.value U\n";
 
133
}
 
134
 
 
135
if (defined ($response = $session->get_request($ifEntryOutErrors)))
 
136
{
 
137
        print "send.value ", $response->{$ifEntryOutErrors}, "\n";
 
138
}
 
139
else
 
140
{
 
141
        print "send.value U\n";
 
142
}