Skip to content

Commit

Permalink
Initial commit: Perl MIB compiler and wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Gelf committed Nov 30, 2017
0 parents commit 24589ab
Show file tree
Hide file tree
Showing 2 changed files with 2,770 additions and 0 deletions.
48 changes: 48 additions & 0 deletions contrib/mib-parser.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/perl

use strict;
use warnings;

BEGIN {
use Cwd qw( realpath );
use File::Basename;
my $basedir = dirname(realpath(__FILE__));
unshift @INC, $basedir . '/perl-vendor';
}

use SNMP::MIB::Compiler;

my $fh = new FileHandle '< -';
unless (defined $fh) {
print "Error: can't open STDIN: $!\n";
exit(1);
}

my $mib = new SNMP::MIB::Compiler;
$mib->{'make_dump'} = 0;
$mib->{'use_dump'} = 0;
$mib->{'do_imports'} = 0;

my $s = Stream->new($fh);
$mib->{'stream'} = $s;
my $r = $mib->parse_Module();
delete $mib->{'stream'};
$fh->close;

unless ($r) {
print "Unable to parse MIB\n";
exit(1);
}

$mib->create_tree();

use JSON;
print to_json {
'name' => $mib->{'name'},
'imports' => $mib->{'imports'},
'nodes' => $mib->{'nodes'},
'types' => $mib->{'types'},
'macros' => $mib->{'macros'},
'tree' => $mib->{'tree'},
'traps' => $mib->{'traps'},
};
Loading

0 comments on commit 24589ab

Please sign in to comment.