Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Script for MIB Conversion... 2

Status
Not open for further replies.

CTSQLGUY

Technical User
Feb 4, 2007
33
0
0
US
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";
}
*********************************************************
 
I'm really confused because all along you acted like the output you were getting is what you wanted. Are you saying you want xml now as your output?
 
CTSQLGUY said:
My output file is MUCH more different than the original now.
...
How can I get the new one to have what the original had...
... (4 days later)
Anything...?

Greetings CTSQLGUY,

It would take anyone here 2 seconds to change the output back to the format that you had originally. However, I purposefully left that as an exercise for you. It's such a simply thing to do that you should be able to do it. And also, there is an additional variable ($variables) and one less ($arg), so you need to make sure that you notice this and do something intentional with them.

I invested the time that I did in fixing your script because I suspected that there were probably bugs in the technique you were using (which there were). However I'm here to teach, and I so also hoped that you would learn a something from my example that would help you out in the future.

If you're unable and unwilling to use your time to make this simple change, than I must conclude that the only the thing that you learned is to come here and have other people do your projects for you. This is not something I'm here to do, and so my time here was a waste.

Regards,
- Miller
 
It wasn't a waste at all - I wasn't aware that was your goal.

I hope you weren't insulted...

Thanks again for the help everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top