#!/usr/bin/perl

use lib "."; use lib "uxmon"; use lib "platforms"; 		#inslib
use SNMP_util;

$host = shift;

foreach $f (split("\n",`ls -1 *.txt`)) {
    print STDERR "reading mib $f\n";
    open( IN, "<$f" );
    while( <IN> ) {
	chomp;
	my( $txt, $num ) = split( /[\s\t]+/ );
	next unless( $num =~ /^[\d\.]+$/ );
	$mib{$num} = $txt;
    }
    close IN;
}

@walk = sort keys %mib;

$success = "x";
foreach $oid (@walk) {
#    print "walking $oid\n";
    next if( $oid =~ /^$success/ );
    @data = snmpwalk( "public\@$host", $oid );
    if( @data ) {
	$success = $oid;
	foreach $data (@data) {
	    $data =~ /^([^:]*):(.*)$/;
	    $soid = $oid.".$1";
	    $text = $2;
	    $sub = "";
	    while( $soid ) {
		last if( defined $mib{$soid} );
		if( $soid =~ /^(.*)\./ ) {
		    $soid = $1;
		    $sub = ".".$'.$sub;
		}
		else {
		    $sub = ".".$soid.$sub;
		    $soid = "";
		}
	    }
	    if( defined $mib{$soid} ) {
		print $mib{$soid};
	    }
	    print $sub.": ".$text."\n";
	}
    }
}
