root / plugins / snmp / snmp__ifx_ @ 7da1b039
Historique | Voir | Annoter | Télécharger (4,56 ko)
| 1 | b084f05b | Kenyon Ralph | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # |
||
| 3 | # Copyright (C) 2008 François Borlet-Hote |
||
| 4 | # |
||
| 5 | # This program is free software; you can redistribute it and/or |
||
| 6 | # modify it under the terms of the GNU General Public License |
||
| 7 | # as published by the Free Software Foundation; version 2 dated June, |
||
| 8 | # 1991. |
||
| 9 | # |
||
| 10 | # This program is distributed in the hope that it will be useful, |
||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | # GNU General Public License for more details. |
||
| 14 | # |
||
| 15 | # You should have received a copy of the GNU General Public License |
||
| 16 | # along with this program; if not, write to the Free Software |
||
| 17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
||
| 18 | # |
||
| 19 | # |
||
| 20 | # $Log$ |
||
| 21 | # |
||
| 22 | # Based on snmp_if from the Revision 1.18 2004/12/10 18:51:43 by jimmyo |
||
| 23 | # |
||
| 24 | # Revision 1.0 2008/05/29 16:10:00 fbh |
||
| 25 | # Created by fbh |
||
| 26 | # |
||
| 27 | # |
||
| 28 | #%# family=snmpauto |
||
| 29 | #%# capabilities=snmpconf |
||
| 30 | |||
| 31 | use strict; |
||
| 32 | use Net::SNMP; |
||
| 33 | |||
| 34 | my $DEBUG = 0; |
||
| 35 | |||
| 36 | my $host = $ENV{host} || undef;
|
||
| 37 | my $port = $ENV{port} || 161;
|
||
| 38 | my $community = $ENV{community} || "public";
|
||
| 39 | my $iface = $ENV{interface} || undef;
|
||
| 40 | my $version = $ENV{version} || "2c";
|
||
| 41 | |||
| 42 | my $response; |
||
| 43 | |||
| 44 | if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") |
||
| 45 | {
|
||
| 46 | print "number 1.3.6.1.2.1.2.1.0\n"; |
||
| 47 | print "index 1.3.6.1.2.1.2.2.1.1.\n"; |
||
| 48 | print "require 1.3.6.1.2.1.2.2.1.3. ^(6|23)\$\n"; # Type |
||
| 49 | print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed |
||
| 50 | exit 0; |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_ifX_(.+)$/) |
||
| 54 | {
|
||
| 55 | $host = $1; |
||
| 56 | $iface = $2; |
||
| 57 | if ($host =~ /^([^:]+):(\d+)$/) |
||
| 58 | {
|
||
| 59 | $host = $1; |
||
| 60 | $port = $2; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | elsif (!defined($host)) |
||
| 64 | {
|
||
| 65 | print "# Debug: $0 -- $1 -- $2\n" if $DEBUG; |
||
| 66 | die "# Error: couldn't understand what I'm supposed to monitor."; |
||
| 67 | } |
||
| 68 | |||
| 69 | my $ifEntryDescr = "1.3.6.1.2.1.2.2.1.2.$iface"; |
||
| 70 | my $ifEntrySpeed = "1.3.6.1.2.1.2.2.1.5.$iface"; |
||
| 71 | my $ifEntryStatus = "1.3.6.1.2.1.2.2.1.8.$iface"; |
||
| 72 | my $ifEntryInOctets = "1.3.6.1.2.1.31.1.1.1.6.$iface"; |
||
| 73 | my $ifEntryOutOctets = "1.3.6.1.2.1.31.1.1.1.10.$iface"; |
||
| 74 | |||
| 75 | my ($session, $error) = Net::SNMP->session( |
||
| 76 | -hostname => $host, |
||
| 77 | -community => $community, |
||
| 78 | -port => $port, |
||
| 79 | -version => $version |
||
| 80 | ); |
||
| 81 | |||
| 82 | if (!defined ($session)) |
||
| 83 | {
|
||
| 84 | die "Croaking: $error"; |
||
| 85 | } |
||
| 86 | |||
| 87 | if ($ARGV[0] and $ARGV[0] eq "config") |
||
| 88 | {
|
||
| 89 | print "host_name $host\n"; |
||
| 90 | if (!defined ($response = $session->get_request($ifEntryDescr))) |
||
| 91 | {
|
||
| 92 | die "Croaking: " . $session->error(); |
||
| 93 | } |
||
| 94 | my $name = $response->{$ifEntryDescr};
|
||
| 95 | $name =~ s/[^\w\s]//g; |
||
| 96 | my $warn = undef; |
||
| 97 | my $max = 1000000000; |
||
| 98 | if (defined ($response = $session->get_request($ifEntrySpeed))) |
||
| 99 | {
|
||
| 100 | $max = $response->{$ifEntrySpeed};
|
||
| 101 | $warn = $response->{$ifEntrySpeed}*0.8;
|
||
| 102 | } |
||
| 103 | if (length ($name) > 15) |
||
| 104 | {
|
||
| 105 | print "graph_title Interface $iface traffic\n"; |
||
| 106 | } |
||
| 107 | else |
||
| 108 | {
|
||
| 109 | print "graph_title Interface $name traffic\n"; |
||
| 110 | } |
||
| 111 | |||
| 112 | print "graph_order recv send\n"; |
||
| 113 | print "graph_args --base 1000\n"; |
||
| 114 | print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
|
||
| 115 | print "graph_category network\n"; |
||
| 116 | print "graph_info This graph shows traffic for the \"$name\" network interface.\n"; |
||
| 117 | print "send.info Bits sent/received by this interface.\n"; |
||
| 118 | print "recv.label recv\n"; |
||
| 119 | print "recv.type DERIVE\n"; |
||
| 120 | print "recv.graph no\n"; |
||
| 121 | print "recv.cdef recv,8,*\n"; |
||
| 122 | print "recv.max ",$max,"\n"; |
||
| 123 | print "recv.min 0\n"; |
||
| 124 | print "recv.warn ", (-$warn), "\n" if defined $warn; |
||
| 125 | print "send.label bps\n"; |
||
| 126 | print "send.type DERIVE\n"; |
||
| 127 | print "send.negative recv\n"; |
||
| 128 | print "send.cdef send,8,*\n"; |
||
| 129 | print "send.max ",$max,"\n"; |
||
| 130 | print "send.min 0\n"; |
||
| 131 | print "send.warn $warn\n" if defined $warn; |
||
| 132 | exit 0; |
||
| 133 | } |
||
| 134 | |||
| 135 | my $status = 1; |
||
| 136 | if (defined ($response = $session->get_request($ifEntryStatus))) |
||
| 137 | {
|
||
| 138 | $status = $response->{$ifEntryStatus};
|
||
| 139 | } |
||
| 140 | |||
| 141 | if ($status == 2) |
||
| 142 | {
|
||
| 143 | print "recv.value U\n"; |
||
| 144 | print "send.value U\n"; |
||
| 145 | exit 0; |
||
| 146 | } |
||
| 147 | |||
| 148 | if (defined ($response = $session->get_request($ifEntryInOctets))) |
||
| 149 | {
|
||
| 150 | print "recv.value ", $response->{$ifEntryInOctets}, "\n";
|
||
| 151 | } |
||
| 152 | else |
||
| 153 | {
|
||
| 154 | print "recv.value U\n"; |
||
| 155 | } |
||
| 156 | |||
| 157 | if (defined ($response = $session->get_request($ifEntryOutOctets))) |
||
| 158 | {
|
||
| 159 | print "send.value ", $response->{$ifEntryOutOctets}, "\n";
|
||
| 160 | } |
||
| 161 | else |
||
| 162 | {
|
||
| 163 | print "send.value U\n"; |
||
| 164 | } |
