[mrtg] Fwd: Re: snmpget in a perl script

Taylor Lewick Taylor.Lewick at us.fortis.com
Thu Apr 25 21:29:08 MEST 2002


Oops, meant to send this to the list earlier,.. just sent it to one recipient...

cliff, if I understand what you are asking, its really easy...
Here is a little perl program I use to display some info from our UPS.  
Real basic, doesnt include automatic updates or graphs...
I used an snmpwalk instead of the snmpget here, only difference is a scalar variable instead of an array...
Let me know if you get a graphing perl program working, I would like to see what you did.
Are you using gd.pm?  

#!/usr/bin/perl

use CGI;

print "Content-type: text/html\n\n";

@bat=`/opt/OV/bin/snmpwalk $ip_addr 1.3.6.1.4.1.534.1.2`;
@input=`/opt/OV/bin/snmpwalk $ip_addr 1.3.6.1.4.1.534.1.3.4`;
@output=`/opt/OV/bin/snmpwalk $ip_addr 1.3.6.1.4.1.534.1.4.4`;

&battery_table;
&battery_data;
&input_data;
&output_data;

sub battery_display {
print "<tr>";
&battery_data;
print "</tr>";
}

sub battery_data {
foreach $items (@bat){
@things1 = split(/:/, $items);
push @input1, "$things1[2]";}
$bat_time_remain_min = (@input1[0] / 60);
$bat_capacity = @input1[3];
print "<td>$bat_time_remain_min</td>";
print "<td>$bat_capacity</td>";
}

sub input_data {
foreach $items (@input){
@things2 = split(/:/, $items);
push @input1, "$things2[2]";}
$in_volt_total = (@input1[3] + @input1[4] + @input1[5]);
print "$in_volt_total<br>";
$in_curr_total = (@input1[6] + @input1[7] + @input1[8]);
print "$in_curr_total<br>";
$in_watt_total = (@input1[9] + @input1[10] + @input1[11]);
print "$in_watt_total<br>";
}

sub output_data {
foreach $items (@output){
@things3 = split(/:/, $items);
push @output1, "$things3[2]";}
$out_volt_total = (@output1[3] + @output1[4] + @output1[5]);
print "$out_volt_total<br>";
$out_curr_total = (@output1[6] + @output1[7] + @output1[8]);
print "$out_curr_total<br>";
$out_watt_total = (@output1[9] + @output1[10] + @output1[11]);
print "$out_watt_total<br>";
}

$volt_useage = (($out_volt_total / $in_volt_total)*100);
print "<br>$volt_useage %";

sub battery_table {
print "<html>\n\n";
print "<title>Result of SNMP Walk on UPS<\/title>\n\n";
print "<body bgcolor=\"#ffffff\" text=\"#000000\">\n\n";
print "<table border='3'>";
print "<TBODY><tr>";
print "<td><b>Time Remaining (min)</b></td>";
print "<td><b>Capacity</u></b></td>";
print "<td><b>% Voltage Utilization</u></b></td>";
print "<td><b>% Watts Utilization</u></b></td>";
&battery_display;
#&input_display;
print "</TBODY></table>";
}

print "<\/html>\n\n";


Taylor Lewick
Unix System Administrator
Fortis Benefits
816 881 6073

"Help Wanted.  Seeking Telepath..."
"You Know where to apply."

****************************************************************
			Please Note
The information in this E-mail message is legally privileged
and confidential information intended only for the use of the
individual(s) named above. If you, the reader of this message,
are not the intended recipient, you are hereby notified that 
you should not further disseminate, distribute, or forward this
E-mail message. If you have received this E-mail in error,
please notify the sender. Thank you
*****************************************************************

-- Binary/unsupported file stripped by Listar --
-- Err : No filename to use for decode, file stripped.
-- Type: message/rfc822


--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
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



More information about the mrtg mailing list