-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit: Perl MIB compiler and wrapper
- Loading branch information
0 parents
commit 24589ab
Showing
2 changed files
with
2,770 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}, | ||
}; |
Oops, something went wrong.