[mrtg] AW: snmpget in a perl script

Michel.Grossenbacher at coop.ch Michel.Grossenbacher at coop.ch
Thu Apr 25 17:31:15 MEST 2002


Hy Cliff
I dont know if the output kinda fits in a SSI thingie but its at last an
example how the snmpget works on perl, Ill try to get the Interface Types
(Token Ring or Ethernet) and the Oper Status from them, the output will be
kinda like this:

host:ethernet:up Status

maybe it helps

Greets

Michel

---------------------------------
use SNMP::Util;

$host = 'xxx';
$community = "xxx";
$ifNumberOID = '.1.3.6.1.2.1.2.1.0';
$ifTypeOID = '.1.3.6.1.2.1.2.2.1.3';
$ifOperStatusOID = '.1.3.6.1.2.1.2.2.1.8';
$output = "serverlist.txt";

$snmp = new SNMP::Util(-device => $host,
		       -community => $community);
open (OUTPUT, ">> $output");
       
$ifNumber = $snmp->get('v',$ifNumberOID);

$i = 1;

while ($i <= $ifNumber)
{
	$ifType = $snmp->get('v',"$ifTypeOID\.$i");
	if ($ifType =~ m/.*tokenRing.*/i)
	{
		$ifOperStatus = $snmp->get('v',"$ifOperStatusOID\.$i");
		print (OUTPUT "$host:$ifType:$ifOperStatus Status\n");
	}
	elsif ($ifType =~ m/.*ethernet.*/i)
	{
		$ifOperStatus = $snmp->get('v',"$ifOperStatusOID\.$i");
		print (OUTPUT "$host:$ifType:$ifOperStatus\n");
	}
	$i++;
}
close (OUTPUT);	
----------------------------------------------------------------------------
-----Ursprungliche Nachricht-----
Von: Cliff [mailto:cliff at acsalaska.net]
Gesendet: Donnerstag, 25. April 2002 17:20
An: mrtg at list.ee.ethz.ch
Betreff: [mrtg] snmpget in a perl script



Hi folks.

I'm graphing an APC UPS.
There are several things that I would like to have
in the web page. Such as:

Last battery replacment date.
Total time the UPS has spent on the batteries.

Since this info is available via snmp I would
have to do an snmpget and then include that data
in the web page as an SSI. I can make the HTML
changes and configure apache to do CGI/SSI no problem.

I need an example of a stand-alone perl script
with an snmpget in it that would be suitable for
inclusion as an SSI. For example purposes anything
would do. I can change the snmpget line to make
it fetch whatever information I might want.

Could somebody spare me a perl snippet?

Thanks gurus.


--
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

--
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