Hi Trojan,
I found out,that I need to to a bit more formating to be able to send the traps.
I did a couple changes (print) to the code
#!/usr/bin/perl -w
use strict;
my $tohost = "myserver";
my $fromhost = "hisserver";
my %hash = ();
open FH, "trap.oid" or die "Failed to open trap.oid";
while(<FH>) {
/"([^"]+)"\s+"([^"]+)"/
and $hash{$1} = $2;
}
close FH;
open FH, "trap.cds" or die "Failed to open trap.cds";
my @strings;
while(<FH>) {
chomp;
@strings = (), print "echo \"Sending Trap $1\"\n" if(/^CLASS (.*)$/);
if(/^\s+(\d+):[^"]+"([^"]+)"/) {
if(exists $hash{$2}) {
push @strings, $hash{$2};
push @strings, "Integer 0";
} else {
push @strings, "wsnmptrap -h $tohost $2 6";
}
}
push @strings, "$1 OctetString \"$fromhost\"" if(/^\s+\d+:\s+\$SPECIFIC\s+=\s+(\d+);/);
print join(" ", @strings), "\n" if(/^END/);
}
close FH;
Using this trap.cds input
#########################################################
##### Compaq ConsoleManagementController- (CMC) MIB
#########################################################
CLASS IM_153001_2
SELECT
1: ATTR(=,$ENTERPRISE) , VALUE(PREFIX, "1.3.6.1.4.1.232.153" ) ;
2: $SPECIFIC = 153001;
3: ATTR(=, "sysDescr") ;
4: ATTR(=, "sysContact")");
5: ATTR(=, "sysName");
6: ATTR(=, "sysLocation");
7: ATTR(PREFIX, "cpqCmcStatusTemp1"), VALUE(=,2);
MAP
sub_source = HP_Insight_Manager;
specificTrap = $V2;
hpq_eventID = 153001_2;
severity = HARMLESS;
hpq_contact = $V4;
hostname=$V5;
hpq_location = $V6;
hpq_CmcStatusTemp1 = $V7;
sub_origin = $K7;
hpq_val = $V7;
msg = "The status of Compaq ConsoleManagementController temperature 1: Normal";
hpq_info = PRINTF ( "Location: %s, Message: %s from: %s, contact %s", $V6, $V7, $V5, $V4);
END
and following trap.oid
"sysDescr" "1.3.6.1.2.1.1.1"
"sysContact" "1.3.6.1.2.1.1.4"
"sysName" "1.3.6.1.2.1.1.5"
"ssSubsysName" "1.3.6.1.4.1.36.2.15.21.1.3.2.1.2"
"sysLocation" "1.3.6.1.2.1.1.6"
"cpqCmcStatusTemp1" "1.3.6.1.4.1.232.153.2.2.4.1"
the result now looks like this:
echo "Sending Trap IM_153001_2"
wsnmptrap -h myserver 1.3.6.1.4.1.232.153 6 153001 OctetString "hisserver" 1.3.6.1.2.1.1.1 Integer 0 1.3.6.1.2.1.1.4 Integer 0 1.3.6.1.2.1.1.5 Integer 0 1.3.6.1.2.1.1.6 Integer 0 1.3.6.1.4.1.232.153.2.2.4.1 Integer 0
But this result is not correct. If you look at the example above you'll see that line
7: ATTR(PREFIX, "cpqCmcStatusTemp1"), VALUE(=,2);
contains a VALUE of 2.
So I'd like to check, if the matched line contains a Value ( if line doesnt contain a value I have to set it to 0)
So final output of this example should look like this
wsnmptrap -h myserver 1.3.6.1.4.1.232.153 6 153001 OctetString "hisserver" 1.3.6.1.2.1.1.1 Integer 0 1.3.6.1.2.1.1.4 Integer 0 1.3.6.1.2.1.1.5 Integer 0 1.3.6.1.2.1.1.6 Integer 0 1.3.6.1.4.1.232.153.2.2.4.1 Integer 7
Cheers, Dietmar