| 1 |
#!/usr/bin/perl -w |
|---|
| 2 |
# |
|---|
| 3 |
# Copyright (C) Rune Nordbøe Skillingstad |
|---|
| 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 |
#%# family=snmpauto |
|---|
| 23 |
#%# capabilities=snmpconf |
|---|
| 24 |
|
|---|
| 25 |
use strict; |
|---|
| 26 |
use Net::SNMP; |
|---|
| 27 |
|
|---|
| 28 |
my $DEBUG = $ENV{'DEBUG'} || 0; |
|---|
| 29 |
|
|---|
| 30 |
my $host = $ENV{host} || undef; |
|---|
| 31 |
my $port = $ENV{port} || 161; |
|---|
| 32 |
my $community = $ENV{community} || "public"; |
|---|
| 33 |
my $timeout = $ENV{timeout} || 1; |
|---|
| 34 |
|
|---|
| 35 |
my $response; |
|---|
| 36 |
|
|---|
| 37 |
if(defined $ARGV[0] and $ARGV[0] eq "snmpconf") { |
|---|
| 38 |
print "require 1.3.6.1.2.1.43.10.2.1.4.1.1\n"; |
|---|
| 39 |
exit 0; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
if($0 =~ /^(?:|.*\/)snmp_([^_]+)_pages$/) { |
|---|
| 43 |
$host = $1; |
|---|
| 44 |
if($host =~ /^([^:]+):(\d+)$/) { |
|---|
| 45 |
$host = $1; |
|---|
| 46 |
$port = $2; |
|---|
| 47 |
} |
|---|
| 48 |
} |
|---|
| 49 |
elsif(!defined($host)) { |
|---|
| 50 |
print "# Debug: $0 -- $1\n" if $DEBUG; |
|---|
| 51 |
die "# Error: couldn't understand what I'm supposed to monitor."; |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
my ($session, $error) = Net::SNMP->session( |
|---|
| 55 |
-hostname => $host, |
|---|
| 56 |
-community => $community, |
|---|
| 57 |
-port => $port, |
|---|
| 58 |
-timeout => $timeout |
|---|
| 59 |
); |
|---|
| 60 |
|
|---|
| 61 |
if(!defined ($session)) { |
|---|
| 62 |
die "Croaking: $error"; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
if(defined $ARGV[0] and $ARGV[0] eq "config") { |
|---|
| 66 |
print "host_name $host\n"; |
|---|
| 67 |
print "graph_title Pages |
|---|
| 68 |
graph_args --base 1000 -l 0 |
|---|
| 69 |
graph_vlabel Printed pages pr minute |
|---|
| 70 |
graph_scale no |
|---|
| 71 |
graph_category other |
|---|
| 72 |
graph_info This graph numer of printed pages |
|---|
| 73 |
graph_total Total |
|---|
| 74 |
pages.label pages |
|---|
| 75 |
pages.draw AREA |
|---|
| 76 |
pages.type DERIVE |
|---|
| 77 |
pages.cdef pages,60,* |
|---|
| 78 |
pages.info pages printed pr minute |
|---|
| 79 |
"; |
|---|
| 80 |
|
|---|
| 81 |
exit 0; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
print "pages.value ", &get_single ($session, "1.3.6.1.2.1.43.10.2.1.4.1.1"), "\n"; |
|---|
| 85 |
|
|---|
| 86 |
sub get_single { |
|---|
| 87 |
my $handle = shift; |
|---|
| 88 |
my $oid = shift; |
|---|
| 89 |
|
|---|
| 90 |
print "# Getting single $oid...\n" if $DEBUG; |
|---|
| 91 |
|
|---|
| 92 |
$response = $handle->get_request ($oid); |
|---|
| 93 |
|
|---|
| 94 |
if(!defined $response->{$oid}) { |
|---|
| 95 |
print "# No response\n" if $DEBUG; |
|---|
| 96 |
return ""; |
|---|
| 97 |
} else { |
|---|
| 98 |
print "# Got response \"".$response->{$oid}."\"\n" if $DEBUG; |
|---|
| 99 |
return $response->{$oid}; |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|