Script to fetch snmp data with oid instances

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
sayasif
Posts: 24
Joined: Thu Sep 12, 2002 12:28 am
Location: India

Script to fetch snmp data with oid instances

Post by sayasif »

HI,

Getting SNMP Data could be easier with this script. I thought it might be useful for cacti users. This script takes in four inputs IP Community Baseoid numberofinstances

I guess IP,Community are understood. Baseoid can be the startOID, so for example a diskutil is x.x.x.a in which 'a' is a instance for example c drive utilization

now all you have to do is to use the script is to give

ip community baseoid numberofinstances (you should know how many drives are there, so 3 drives makes this "2")

and then this script gives the output value for all the instances. I guess configuring data input source and datasource are understood.


======Script starts here ==================
#!/usr/bin/perl -w
#

# Pls Supply an Argument

$arg = shift || die "Usage :$0 <IP> <OID> <No of Iterations> " ;
print "Arg: $arg \n" if ($debug) ;
$community = shift || die "Usage :$0 <IP> <OID> <No of Iterations> " ;
print "Commu: $community \n " if ($debug) ;
$oid = shift || die "Usage :$0 <IP> <OID> <No of Iterations> " ;
print "Oid: $oid \n " if ($debug);
$nofitr = shift || die "Usage :$0 <IP> <OID> <No of Iterations> ";
print "No of Iterations $nofitr \n" if ($debug) ;

for ($i=0;$i<=$nofitr;$i++){
print "The Run is : $i \n" if ($debug);
$Oid = "$oid"."$i" ;
print "$Oid \n" if ($debug) ;
open ( FH ," snmpget $arg $community $Oid | ") || die "Can't open SNMP1 $! ";
while (<FH>){
chomp;
my (undef , $value ) = split (/\s=\s/,$_ );
print " $value ";}

}
============ends here ==================

hope it helps

ACE
ONE MORE DAY WASTED !
User avatar
bulek
Cacti Pro User
Posts: 854
Joined: Mon May 20, 2002 2:07 am
Location: Poland
Contact:

Post by bulek »

You are assuming instances growing by 1. This of course happens quite often but not always. Index of instances can grow in not so regular way. I think you can modify your script to use snmpgetnext which is more appropriate for iterating instances one by one.

- bulek
sayasif
Posts: 24
Joined: Thu Sep 12, 2002 12:28 am
Location: India

Post by sayasif »

Sure thing :D

Thanx for the input . Will post the updated script in the contrib script section. Still new to SNMP WORLD :(

ACE
ONE MORE DAY WASTED !
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests