SNMP get-next-request
- From: "S3B" <Sebastian.Zych@xxxxxxxxx>
- Date: 23 Mar 2007 07:42:18 -0700
I'm a total newbee in Perl.
I'm trying to write a simple script wich gets from router or computer
incoming and outgoing traffic.
But those variables mus be taken all the time. I've read about get-
next-request in Net::SNMP module but I can't do it I don't know how.
I know that are programs like MRTG or RRDTool but I want to do it by
myself.
In next step i want do build a png graph to visualize traffic
This is my actual script:
#! /usr/local/bin/perl
use strict;
use vars qw($session $error $response);
use Net::SNMP;
#use Net::SNMP::HostInfo;
# Lista hostow
my @HOSTS = qw(localhost);
my $community = 'public';
my $ipInDelivers = ".1.3.6.1.2.1.4.9.0";
my $ipInReceives = '.1.3.6.1.2.1.4.3';
my $ipOutRequests = '.1.3.6.1.2.1.4.10';
my $sysUpTime = '1.3.6.1.2.1.1.3.0';
my $ifOutOctets = '1.3.6.1.2.1.2.2.1.16.1';
# Sesja
foreach my $host (@HOSTS) {
($session, $error) = Net::SNMP->session(
-hostname => shift || $host,
-community => shift || $community,
-port => shift || 161
);
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit 1;
}
if (!defined($response = $session->get_request($sysUpTime))) {
printf("ERROR: %s.\n", $session->error());
$session->close();
exit 1;
}
printf("SysUpTime for host '%s' is %s.\n",
$session->hostname(),
$response->{$sysUpTime}
);
if (!defined($response = $session->get_request($ipInDelivers))) {
printf("ERROR: %s.\n", $session->error());
$session->close();
exit 1;
}
printf("ipInDelivers for host '%s' is %s.\n",
$session->hostname(),
$response->{$ipInDelivers}
);
if (!defined($response = $session->get_request($ipOutRequests))) {
printf("ERROR: %s.\n", $session->error());
$session->close();
exit 1;
}
printf("ifOutOctets for host '%s' is %s.\n",
$session->hostname(),
$response->{$ipOutRequests}
);
}
$session->close();
exit 0;
Thnaks for any help ;)
.
- Prev by Date: Re: cannot determine peer address with Unix domain sockets
- Next by Date: Learning Perl with shells operations
- Previous by thread: First line in body of Mail::POP3Client
- Next by thread: Learning Perl with shells operations
- Index(es):
Relevant Pages
|