Re: Very Newbie: Converting a complex MIB file with mib2c
Fulko Hew <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Jul 2, 2010 at 9:11 AM, Stavros Tsolakos <[email protected]>wrote: > Hi all. > > I am really new to SNMP and net-snmp. I have a MIB file from a network > switch and i wanted to make a custom subagent to make the snmpd of my > workstation report some dummy data, as if it were the switch. I have > managed to build a subagent reporting a dummy integer value. But when > trying to use mib2c on the MIB file (I have configured it correctly, > mib2c can find both the MIB and the starting node) I am not sure of > which configuration file to use. > > The MIB contains many tables, many scalar and many string values. Is > there a configuration file to automagically generate template code > which respects data types? Do I have to use mib2c separately for each > entry of my MIB? > > Thank you very much and my apologies if the question is stupid. I am > very newbie and very confused, too. > No, its not a stupid question, and it is really an interesting problem. I started to tackle this in a generic manner. Ie simulate a network of devices that respond to whatever they were queried for with legal (but not neccessarily accurate) responses. And cache the responses so that they would be consistent across queries (for enumerations, some strings etc) and for integers and strings they may dynamically change, so you could have 'pretty' data on charts (it thats what your NMS was doing. Turns out, unless you only looked at a limited scenario where everything was under your control, the problem of dynamic OID generation (especially with tables that use multiple indexes, becomes nasty). Unfortunately, I tied my simulator into a whack of my other software that I can't let out at this time. (it uses it to access the MIBs compiled into my system's database) (because the simulator would simulate any and all MIBs compiled in if it were walked ... from wherever you started, including .iso. So right now, because I have over 300 different MIBs in my NMS, MIB walking a single simulated device returns (5 instances) of each variable, so that results in over 100K variables (MIB-II, CISCO routers, Synoptic switches, my company's proprietary devices... etc.) Simulating a single, simple MIB file for read-only would be relatively easy. What I would do is: Take the output of a MIB compiler listing all the OIDs for _your_ file. build a hash of those OIDs (including as many instances of table entries you (statically) desire (with valid index values) and write a simple perl program to access the hash and return the associated value (and the scan the hash correctly for the 'next' OID if required.) But I'm simplifying the process for the sake of the email. :-) Here is a simple app I wrote at the beginning of testing my simulator concept. The you would need to alter it to: 1/ register _your_ part of the OID tree 2/ perform the lookup for _your_ OIDs to value mapping 3/ return the right 'type' designator for the right variable. 3/ return the right 'next' OID, if getnext was used. #!/usr/bin/perl use NetSNMP::OID (':all'); use NetSNMP::agent (':all'); use NetSNMP::ASN (':all'); use Socket; sub my_snmp_handler { my ($handler, $registration_info, $request_info, $requests) = @_; for (my $request = $requests; $request; $request = $request->next()) { # handle each request component my $oid = $request->getOID(); print STDERR " Using $0 to "; if ($request_info->getMode() == MODE_GET) { # was it a 'get' print STDERR " Get $oid\n"; $request->setValue(ASN_OCTET_STR, 'Get() hello from $oid'); } elsif ($request_info->getMode() == MODE_GETNEXT) { # or a 'getNext' print STDERR "GetNext $oid\n"; my $next_oid; if ($oid =~ /0$/) { $next_oid = new NetSNMP::OID('9'); } else { $next_oid = new NetSNMP::OID($oid . '.0'); } $request->setOID($next_oid); $request->setValue(ASN_OCTET_STR, 'GetNext() Hello from $next_oid'); } } } # Mainline print "No $agent defined\n" if (!$agent); { my $regat='.1.3.6.1.2.1.1.1'; print STDERR "Registering $0 as the handler for OID: $regat\n"; my $regoid = new NetSNMP::OID($regat); $agent->register($0, $regoid, \&my_snmp_handler); } Fulko ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ Net-snmp-users mailing list [email protected] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users