snmpget -v2c -c public IP_Address 1.3.6.1.4.1.9.2.1.3.0
provide the correct community and IP address of snmp agent, it should return the host-name of the agent. otherwise you can paste your problem on this blog and ill try my level best to reply ASAP.
vi inventory.pl
open your fav editor and paste the code in the code section.
Execution:
perl scriptname.pl # perl inventory.pl
Some important and Usefull OIDs:
iso.3.6.1.2.1.47.1.1.1.1.11.1 motherboard oid
iso.3.6.1.2.1.47.1.1.1.1.11.21 device
iso.3.6.1.2.1.47.1.1.1.1.13.1 device name
1.3.6.1.2.1.47.1.1.1.1.11 serial numbers
1.3.6.1.2.1.47.1.1.1.1.13 names
1.3.6.1.4.1.9.2.1.3.0 hostname
#!/usr/bin/perl
$snmpro="public";
$rtrlist="input.txt";
open (RTR, "input.txt") || die "Can't open $rtrlist file";
open (LOG, ">result.csv") || die "Can't open $workingdir/RESULT file";
open (ERR1, ">err.log") || die "Can't open $workingdir/RESULT file";
while (<RTR>) {
#print $_;
chomp($rtr="$_");
$snmpget=`snmpget -v2c -c $snmpro $rtr 1.3.6.1.4.1.9.2.1.3.0`;
if ($snmpget =~ /Timeout/) { print ERR1 "cant open $rtr\n"; print "can't open $rtr.\n"; } else
{
@str = split (/\=/,$snmpget);
@hostname = split (/ /,$str[1]);
print $hostname[2];
chomp($hostname[2]);
}
@snmpname = `snmpwalk -v2c -c $snmpro $rtr 1.3.6.1.2.1.47.1.1.1.1.13`;
@snmpserial = `snmpwalk -v2c -c $snmpro $rtr 1.3.6.1.2.1.47.1.1.1.1.11`;
$line_num=0;
foreach (@snmpname) {
chomp ($_);
@name = split (/\=/,$_);
@name1= split (/ /,$name[1]);
if($name1[2]) {
chomp($snmpserial[$line_num]);
@serial1= split (/\=/,$snmpserial[$line_num]);
@serial = split (/ /,$serial1[1]);
print $name1[2]."=".$serial[2]."\n";
print LOG $rtr.",".$hostname[2].",".$name1[2],$serial[2]."\n";
}
$line_num++;
}
#print @snmpname;
#print @snmpserial;
#printf LOG ("%-12.12s; %-30.30s; %-25.25s; %-12.12s\n", $RTR, $LOC, $CON, $SIN);
}
close (RTR);
close (LOG);
close (ERR1);
Nice, i use perl script to manage my network too.
ReplyDelete