3 # Copyright (c) 2009 - Rune Nordbøe Skillingstad
 
   4 # Copyright (c) 2009 - Kai Ove Gran
 
   6 # This program is free software; you can redistribute it and/or
 
   7 # modify it under the terms of the GNU General Public License
 
   8 # as published by the Free Software Foundation; version 2 dated June,
 
  11 # This program is distributed in the hope that it will be useful,
 
  12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  14 # GNU General Public License for more details.
 
  16 # You should have received a copy of the GNU General Public License
 
  17 # along with this program; if not, write to the Free Software
 
  18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
  21 #       snmp_host_apcpdu - For APC PDUs. Graphs total current throughput.
 
  24 #%# capabilities=snmpconf
 
  29 my $DEBUG     = $ENV{DEBUG}     || 0;
 
  30 my $host      = $ENV{host}      || undef;
 
  31 my $port      = $ENV{port}      || 161;
 
  32 my $community = $ENV{community} || "public";
 
  33 my $iface     = $ENV{interface} || undef;
 
  34 my $timeout   = $ENV{timeout}   || 1;
 
  35 my $snmp_ver  = $ENV{version}   || 1;
 
  37 if($0 =~ /^(?:|.*\/)apcpdu_([^_]+)$/) {
 
  39     if($host =~ /^([^:]+):(\d+)$/) {
 
  43 } elsif(!defined($host)) {
 
  44     die "# Error: couldn't understand what I'm supposed to monitor."; 
 
  48     '1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1',
 
  49     '1.3.6.1.4.1.318.1.1.12.2.2.1.1.3.1',
 
  50     '1.3.6.1.4.1.318.1.1.12.1.7.0'    
 
  53 if(defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
 
  54     for(my $i = 0; $i < @oidsList; $i++) {
 
  55         print "require " . $oidsList[$i] . "[0-9]\n"; 
 
  60 my ($session, $error) = Net::SNMP->session(
 
  62     -community => $community,
 
  65     -version   => $snmp_ver,
 
  68 if(!defined ($session)) {
 
  69     die "# Croaking: $error";
 
  72 if($ARGV[0] and $ARGV[0] eq "config") {
 
  73     my $name = &get_single($session, '1.3.6.1.4.1.318.1.1.4.3.3.0');
 
  75 #       print "host_name $host\n" unless $host eq 'localhost';
 
  76         print "graph_title Current for $name\n";
 
  77         print "graph_args --base 1000 -l 0\n";
 
  78         print "graph_vlabel Amps\n";
 
  79         print "graph_category Ups\n";
 
  80         print "graph_info This graph shows the total throughput of the PDU\n";
 
  81         print "graph_order load threshold rating\n";
 
  82         print "load.label Load\n";
 
  83         print "load.type GAUGE\n";
 
  84         print "load.info Current load in amps.\n";
 
  85         print "load.draw LINE2\n";
 
  86         print "threshold.label Threshold\n";
 
  87         print "threshold.type GAUGE\n";
 
  88         print "threshold.info Near overload threshold.\n";
 
  89         print "threshold.draw LINE2\n";
 
  90         print "rating.label Rating\n";
 
  91         print "rating.type GAUGE\n";
 
  92         print "rating.info Rating (Max amps).\n";
 
  93         print "rating.draw LINE2\n";
 
  98 my @response = &get_multiple($session, @oidsList);
 
 100 printf "load.value %.02f\n", $response[0] / 10;
 
 101 printf "threshold.value %d\n", $response[1];
 
 102 printf "rating.value %d\n", $response[2];
 
 110     foreach my $oid (@oids) {
 
 111         push(@result, &get_single($handle,$oid));
 
 118     my ($handle, $oid) = @_;
 
 120     my $response = $handle->get_request ($oid);
 
 121     if(!defined $response->{$oid}) {
 
 122         print "# No response\n" if $DEBUG;
 
 125         print "# Got response \"".$response->{$oid}."\"\n" if $DEBUG;
 
 126         return $response->{$oid};