I have a script that takes MIB's and converts them to a CFX file, the file is something readable by a program I'm using for SNMP management
The script is a work in progress, the majority of it is done but I need some assistance to finish it...
The script does exactly what I want except right now it's not outputting the file, I'm forced to run it via command using:
script.pl >C:\Test\Test.CFX
I would love to be able to include it in the script - or better yet have it prompt me for the name!
Additionally, the other headache I've run into is with SNMP 2.0. MIB's no longer use TRAP-TYPE to identify traps, they now use NOTIFICATION-TYPE. Does someone know how I could say to look for either/or?
Any assistance would be greatly appreciated!
Thanks!
*********************************************************
$infile = 'c:\Test\TRAPS.mib';
#Outfile is not currently used - use file redirect when running script.
#$outfile = 'C:\Test\Test.CFX';
$inprocess = 0;
open (INFILE, "$infile") || die;
#open (OUTFILE, ">$outfile") || die;
writeheader();
while (<INFILE>) {
#
# This line grabs each TRAP-TYPE object within the specified MIB/infile.
#
if ($_ =~/[a-zA-Z0-9].* TRAP-TYPE/) {
if ($inprocess) {
punchout();
}
$object = $_;
chomp ($object);
$inprocess = 1;
next;
}
#
# This line grabs each trapID within the specified MIB/infile.
#
if ($_ =~/::= ([0-9]).*/) {
$trapid = $_;
chomp ($trapid);
next;
}
#
# This line grabs each ARGUMENT within the specified MIB/infile.
#
if ($_ =~/--#ARGUMENTS ([0-9,\{ ]).*/) {
$arg = $_;
chomp ($arg);
next;
}
#
# This line grabs each DESCRIPTION within the specified MIB/infile. Good for alert "message" content...
#
if ($_ =~/DESCRIPTION/) {
$descr = <INFILE>;
chomp ($descr);
next;
}
}
writeTrailer();
#
# Write one Trap Configuration Record to the output.
#
sub punchout {
@object = ($object =~ /(\w+)/g);
$object = @object[0];
print " <$object>\n";
print " trap_type = 6\n";
@trapid = ($trapid =~ /(\w+)/g);
print " specific_trap = @trapid[0]\n";
print " <alarm>\n";
print " active = yes\n";
$descr =~ s/"//g;
$descr =~ s/^\s*//;
print " message = $descr\n";
print " severity = 2\n";
print " subsystem = NORTEL\n";
print " suppkey = $object\n";
print " </alarm>\n";
print " convert_trap = no\n";
print " log_trap = no\n";
print " </$object>\n";
}
#
# Start by writing section header
#
sub writeheader {
print "<profiles> overwrite\n";
print " <.1.3.6.1.4.1.2636>\n";
print " name = Nortel Contivity TrapsV1\n";
print " active = yes\n";
}
# End by writing section trailer
#
sub writeTrailer {
print " </.1.3.6.1.4.1.2636>\n";
print "</profiles>\n";
}
*********************************************************
The script is a work in progress, the majority of it is done but I need some assistance to finish it...
The script does exactly what I want except right now it's not outputting the file, I'm forced to run it via command using:
script.pl >C:\Test\Test.CFX
I would love to be able to include it in the script - or better yet have it prompt me for the name!
Additionally, the other headache I've run into is with SNMP 2.0. MIB's no longer use TRAP-TYPE to identify traps, they now use NOTIFICATION-TYPE. Does someone know how I could say to look for either/or?
Any assistance would be greatly appreciated!
Thanks!
*********************************************************
$infile = 'c:\Test\TRAPS.mib';
#Outfile is not currently used - use file redirect when running script.
#$outfile = 'C:\Test\Test.CFX';
$inprocess = 0;
open (INFILE, "$infile") || die;
#open (OUTFILE, ">$outfile") || die;
writeheader();
while (<INFILE>) {
#
# This line grabs each TRAP-TYPE object within the specified MIB/infile.
#
if ($_ =~/[a-zA-Z0-9].* TRAP-TYPE/) {
if ($inprocess) {
punchout();
}
$object = $_;
chomp ($object);
$inprocess = 1;
next;
}
#
# This line grabs each trapID within the specified MIB/infile.
#
if ($_ =~/::= ([0-9]).*/) {
$trapid = $_;
chomp ($trapid);
next;
}
#
# This line grabs each ARGUMENT within the specified MIB/infile.
#
if ($_ =~/--#ARGUMENTS ([0-9,\{ ]).*/) {
$arg = $_;
chomp ($arg);
next;
}
#
# This line grabs each DESCRIPTION within the specified MIB/infile. Good for alert "message" content...
#
if ($_ =~/DESCRIPTION/) {
$descr = <INFILE>;
chomp ($descr);
next;
}
}
writeTrailer();
#
# Write one Trap Configuration Record to the output.
#
sub punchout {
@object = ($object =~ /(\w+)/g);
$object = @object[0];
print " <$object>\n";
print " trap_type = 6\n";
@trapid = ($trapid =~ /(\w+)/g);
print " specific_trap = @trapid[0]\n";
print " <alarm>\n";
print " active = yes\n";
$descr =~ s/"//g;
$descr =~ s/^\s*//;
print " message = $descr\n";
print " severity = 2\n";
print " subsystem = NORTEL\n";
print " suppkey = $object\n";
print " </alarm>\n";
print " convert_trap = no\n";
print " log_trap = no\n";
print " </$object>\n";
}
#
# Start by writing section header
#
sub writeheader {
print "<profiles> overwrite\n";
print " <.1.3.6.1.4.1.2636>\n";
print " name = Nortel Contivity TrapsV1\n";
print " active = yes\n";
}
# End by writing section trailer
#
sub writeTrailer {
print " </.1.3.6.1.4.1.2636>\n";
print "</profiles>\n";
}
*********************************************************