Here's a simplified script, and a corrected way to call it. It should work
on any OS and doesn't require an external executable.

You should have SNMP_Session.pm, SNMP_util.pm, and BER.pm in perl/lib. If
you don't, add this line with the correct location of your mrtg libraries.

use lib qw(d:\mrtg\lib\mrtg2);

--------------------------------------------
#!d:\perl\bin\perl
# upstime.pl
# convert runtime MIB variable for APC UPS 
# from timeticks to minutes so mrtg understands it
# eg. perl upsdata01.pl [EMAIL PROTECTED] 
# returns runtime in minutes and load percentage
#
require 5.005;
use strict;
use SNMP_util "0.77";

my @a = snmpget($ARGV[0], "enterprises.318.1.1.1.2.2.3.0");
my @b=split(/:/,@a[0]);
my @c= snmpget($ARGV[0], "enterprises.318.1.1.1.4.2.3.0");
print eval($b[0] * 60 + $b[1]),"\n";
print @c[0],"\n";
--------------------------------------------

Use something like this as an mrtg target definition.

Target[UPSTime]: `path\to\perl path\to\script\upstime.pl [EMAIL PROTECTED]

-----Original Message-----
From: Jerry Heidtke [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 15, 2003 8:21 AM
To: 'Leonard Miller'; [EMAIL PROTECTED]
Subject: [mrtg] Re: UPS Runtime Remaining



Here's what I use with APC UPS to graph time remaining.

This is the perl script. It's a slightly modified version of the script
included in the contrib directory with mrtg. The main modification is that
it accepts the target IP address and community name as command line
parameters.

It uses snmpget.exe from the net-snmp package. It could rather easily be
rewritten to use the SNMP_util perl library included with mrtg. This is left
for an exercise for the reader...

Jerry

--------------------------------------------
#!d:\perl\bin\perl
#
# Script to convert runtime MIB variable for UPS into minutes
# eg. perl upsdata01.pl host-addr snmp-community
$x=$ARGV[0];
@y=split(/@/,$x);
$a=`d:/usr/bin/snmpget $y[1] $y[0] .1.3.6.1.4.1.318.1.1.1.2.2.3.0`; chomp
$a; @b=split(/ /,$a); @c=split(/:/,$b[4]); @d=split(/ /,`d:/usr/bin/snmpget
$y[1] $y[0] .1.3.6.1.4.1.318.1.1.1.4.2.3.0`); chomp $d; print eval($c[0] *
60 + $c[1]),"\n"; print $d[3];
--------------------------------------------

Here is a sample mrtg config to call it.

--------------------------------------------
MaxBytes[_]: 600
Options[_]: growright, gauge, nopercent, noo, integer
WithPeak[_]: wmy
Unscaled[_]:
YLegend[_]: UPS Run Time
ShortLegend[_]: minutes
LegendI[_]: UPS Run Time Remaining:
LegendO[_]:
Legend1[_]: UPS Run Time
Legend2[_]:
Legend3[_]: Max. UPS Run Time
Legend4[_]:

Target[UPSTime]: `d:\perl\bin\wperl d:\mrtgcfg\cfg\template\upsdata01.pl
xxx.xxx.xxx.xxx community`
Title[UPSTime]:  UPS Run Time Remaining for
PageTop[UPSTime]:  UPS Run Time Remaining for
--------------------------------------------


-----Original Message-----
From: Leonard Miller [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 15, 2003 7:37 AM
To: [EMAIL PROTECTED]
Subject: [mrtg] UPS Runtime Remaining



Me again with another UPS question.  So far I have been able
to get everything I need from my UPSssssss, temperature, status, capacity
and about 8 other values I needed, except runtime remaining.  I assumed it
would return a value like this "546000" and I had the config file setup to
calculate the result based on that. But it doesn't.  It returns the actual
time remaining, HH:MM:SS.

Is there a way to get it to read and graph the returned value? Or will I
have to look to an external perl script to do this?  

Thanks
Leonard

--
Unsubscribe mailto:[EMAIL PROTECTED]
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi


Confidentiality Notice: This e-mail message, including any attachments, is 
for the sole use of the intended recipient(s) and may contain confidential 
and privileged information.  Any unauthorized review, use, disclosure or 
distribution is prohibited.  If you are not the intended recipient, please 
contact the sender by reply e-mail and destroy all copies of the original 
message.


--
Unsubscribe mailto:[EMAIL PROTECTED]
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi


Confidentiality Notice: This e-mail message, including any attachments, is 
for the sole use of the intended recipient(s) and may contain confidential 
and privileged information.  Any unauthorized review, use, disclosure or 
distribution is prohibited.  If you are not the intended recipient, please 
contact the sender by reply e-mail and destroy all copies of the original 
message.


--
Unsubscribe mailto:[EMAIL PROTECTED]
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi

Reply via email to