| 1 |
#!/usr/bin/perl -w |
|---|
| 2 |
# -*- perl -*- |
|---|
| 3 |
# |
|---|
| 4 |
# Copyright (C) 2004 Jimmy Olsen, Dagfinn Ilmari Mannsaaker |
|---|
| 5 |
# Copyright (C) 2010 Aleksandar Lazic |
|---|
| 6 |
# |
|---|
| 7 |
# This plugin is copied from snmp__processes |
|---|
| 8 |
# |
|---|
| 9 |
# This program is free software; you can redistribute it and/or |
|---|
| 10 |
# modify it under the terms of the GNU General Public License |
|---|
| 11 |
# as published by the Free Software Foundation; version 2 dated June, |
|---|
| 12 |
# 1991. |
|---|
| 13 |
# |
|---|
| 14 |
# This program is distributed in the hope that it will be useful, |
|---|
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 |
# GNU General Public License for more details. |
|---|
| 18 |
# |
|---|
| 19 |
# You should have received a copy of the GNU General Public License |
|---|
| 20 |
# along with this program; if not, write to the Free Software |
|---|
| 21 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|---|
| 22 |
# |
|---|
| 23 |
# |
|---|
| 24 |
#%# family=snmpauto |
|---|
| 25 |
#%# capabilities=snmpconf |
|---|
| 26 |
|
|---|
| 27 |
use strict; |
|---|
| 28 |
use Net::SNMP; |
|---|
| 29 |
|
|---|
| 30 |
my $DEBUG = 0; |
|---|
| 31 |
my $MAXLABEL = 20; |
|---|
| 32 |
|
|---|
| 33 |
my $host = $ENV{host} || undef; |
|---|
| 34 |
my $port = $ENV{port} || 161; |
|---|
| 35 |
my $community = $ENV{community} || "public"; |
|---|
| 36 |
|
|---|
| 37 |
my $response; |
|---|
| 38 |
|
|---|
| 39 |
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") |
|---|
| 40 |
{ |
|---|
| 41 |
# .iso.org.dod.internet.mgmt.mib-2.tcp.tcpCurrEstab.0 |
|---|
| 42 |
print "require .1.3.6.1.2.1.6.9.0 [0-9]\n"; # Number |
|---|
| 43 |
exit 0; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_tcpCurrEstab$/) |
|---|
| 47 |
{ |
|---|
| 48 |
$host = $1; |
|---|
| 49 |
if ($host =~ /^([^:]+):(\d+)$/) |
|---|
| 50 |
{ |
|---|
| 51 |
$host = $1; |
|---|
| 52 |
$port = $2; |
|---|
| 53 |
} |
|---|
| 54 |
} |
|---|
| 55 |
elsif (!defined($host)) |
|---|
| 56 |
{ |
|---|
| 57 |
print "# Debug: $0 -- $1\n" if $DEBUG; |
|---|
| 58 |
die "# Error: couldn't understand what I'm supposed to monitor."; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
my ($session, $error) = Net::SNMP->session( |
|---|
| 62 |
-hostname => $host, |
|---|
| 63 |
-community => $community, |
|---|
| 64 |
-port => $port |
|---|
| 65 |
); |
|---|
| 66 |
|
|---|
| 67 |
if (!defined ($session)) |
|---|
| 68 |
{ |
|---|
| 69 |
die "Croaking: $error"; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
if (defined $ARGV[0] and $ARGV[0] eq "config") |
|---|
| 73 |
{ |
|---|
| 74 |
print "host_name $host\n" unless $host eq 'localhost'; |
|---|
| 75 |
print "graph_title Number of current established tcp connections |
|---|
| 76 |
graph_args --base 1000 -l 0 |
|---|
| 77 |
graph_vlabel number of tcp connections |
|---|
| 78 |
graph_category network |
|---|
| 79 |
graph_info This graph shows the number of current established tcp connections |
|---|
| 80 |
tcpcon.label connections |
|---|
| 81 |
tcpcon.draw LINE2 |
|---|
| 82 |
tcpcon.info The number of tcp connections. |
|---|
| 83 |
"; |
|---|
| 84 |
|
|---|
| 85 |
exit 0; |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
print "tcpcon.value ", &get_single ($session, ".1.3.6.1.2.1.6.9.0"), "\n"; |
|---|
| 89 |
|
|---|
| 90 |
sub get_single |
|---|
| 91 |
{ |
|---|
| 92 |
my $handle = shift; |
|---|
| 93 |
my $oid = shift; |
|---|
| 94 |
|
|---|
| 95 |
print "# Getting single $oid...\n" if $DEBUG; |
|---|
| 96 |
|
|---|
| 97 |
$response = $handle->get_request ($oid); |
|---|
| 98 |
|
|---|
| 99 |
if (!defined $response->{$oid}) |
|---|
| 100 |
{ |
|---|
| 101 |
return undef; |
|---|
| 102 |
} |
|---|
| 103 |
else |
|---|
| 104 |
{ |
|---|
| 105 |
return $response->{$oid}; |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|