11# !/usr/bin/perl -w
22#
3- # SEC (Simple Event Correlator) 2.9.1 - sec
4- # Copyright (C) 2000-2022 Risto Vaarandi
3+ # SEC (Simple Event Correlator) 2.9.2 - sec
4+ # Copyright (C) 2000-2023 Risto Vaarandi
55#
66# This program is free software; you can redistribute it and/or
77# modify it under the terms of the GNU General Public License
@@ -183,8 +183,8 @@ $WIN32 = ($^O =~ /win/i && $^O !~ /cygwin/i && $^O !~ /darwin/i);
183183
184184# set version and usage variables
185185
186- $SEC_VERSION = " SEC (Simple Event Correlator) 2.9.1 " ;
187- $SEC_COPYRIGHT = " Copyright (C) 2000-2022 Risto Vaarandi" ;
186+ $SEC_VERSION = " SEC (Simple Event Correlator) 2.9.2 " ;
187+ $SEC_COPYRIGHT = " Copyright (C) 2000-2023 Risto Vaarandi" ;
188188
189189$SEC_USAGE = qq! Usage: $0 [options]
190190
@@ -8392,60 +8392,93 @@ sub update_times_eg {
83928392
83938393
83948394# Parameters: par1 - event group matching pattern
8395- # par2 - event group string
8396- # par3 - reference to the list of tokens from event group string
8397- # Action: match event group string par2 with event group pattern par1;
8395+ # par2 - reference to the list of observed events
8396+ # Action: build the event group string from the list referenced by par2,
8397+ # and match this event group string with event group pattern par1;
83988398# return 1 if match was found, otherwise return 0.
83998399# In the case of PerlFunc and NPerlFunc patterns, the perl function
8400- # referenced by par1 takes event group string par2 and reference to
8401- # the list of tokens par3 as parameters, i.e., the function is invoked
8402- # as follows: par1->(par2, par3)
8400+ # referenced by par1 takes three parameters: event group string,
8401+ # reference to the list of tokens, and reference to the list of
8402+ # event occurrence times
84038403
84048404sub match_eventgroup_substr {
84058405
8406- my ($substr , $string ) = @_ ;
8406+ my ($substr , $ref ) = @_ ;
8407+ my ($egrpstring );
8408+
8409+ # build the event group string and match it with the pattern
8410+
8411+ $egrpstring = join (" " , map { $_ -> [2] } @{$ref });
8412+
8413+ if (index ($egrpstring , $substr ) != -1) { return 1; }
84078414
8408- if (index ($string , $substr ) != -1) { return 1; }
84098415 return 0;
84108416}
84118417
84128418
84138419sub match_eventgroup_nsubstr {
84148420
8415- my ($substr , $string ) = @_ ;
8421+ my ($substr , $ref ) = @_ ;
8422+ my ($egrpstring );
8423+
8424+ # build the event group string and match it with the pattern
8425+
8426+ $egrpstring = join (" " , map { $_ -> [2] } @{$ref });
8427+
8428+ if (index ($egrpstring , $substr ) == -1) { return 1; }
84168429
8417- if (index ($string , $substr ) == -1) { return 1; }
84188430 return 0;
84198431}
84208432
84218433
84228434sub match_eventgroup_regexp {
84238435
8424- my ($regexp , $string ) = @_ ;
8436+ my ($regexp , $ref ) = @_ ;
8437+ my ($egrpstring );
8438+
8439+ # build the event group string and match it with the pattern
8440+
8441+ $egrpstring = join (" " , map { $_ -> [2] } @{$ref });
8442+
8443+ if ($egrpstring =~ / $regexp / ) { return 1; }
84258444
8426- if ($string =~ / $regexp / ) { return 1; }
84278445 return 0;
84288446}
84298447
84308448
84318449sub match_eventgroup_nregexp {
84328450
8433- my ($regexp , $string ) = @_ ;
8451+ my ($regexp , $ref ) = @_ ;
8452+ my ($egrpstring );
8453+
8454+ # build the event group string and match it with the pattern
8455+
8456+ $egrpstring = join (" " , map { $_ -> [2] } @{$ref });
8457+
8458+ if ($egrpstring !~ / $regexp / ) { return 1; }
84348459
8435- if ($string !~ / $regexp / ) { return 1; }
84368460 return 0;
84378461}
84388462
84398463
84408464sub match_eventgroup_perlfunc {
84418465
8442- my ($codeptr , $string , $tokenlist ) = @_ ;
8443- my ($retval );
8466+ my ($codeptr , $ref ) = @_ ;
8467+ my (@timelist , @tokenlist , $egrpstring , $elem , $retval );
8468+
8469+ # build the event group string and list parameters for the function
8470+
8471+ foreach $elem (@{$ref }) {
8472+ push @timelist , $elem -> [0];
8473+ push @tokenlist , $elem -> [2];
8474+ }
8475+
8476+ $egrpstring = join (" " , @tokenlist );
84448477
84458478 # call the function and save its return value;
84468479 # in the case of a function runtime error there is no match
84478480
8448- $retval = eval { $codeptr -> ($string , $ tokenlist ) };
8481+ $retval = eval { $codeptr -> ($egrpstring , \ @ tokenlist, \ @timelist ) };
84498482
84508483 if ($@ ) {
84518484 log_msg(LOG_ERR, " PerlFunc pattern runtime error:" , $@ );
@@ -8456,19 +8489,29 @@ sub match_eventgroup_perlfunc {
84568489 # context (neither undef, nor "", nor 0), return 1, otherwise return 0
84578490
84588491 if ($retval ) { return 1; }
8492+
84598493 return 0;
84608494}
84618495
84628496
84638497sub match_eventgroup_nperlfunc {
84648498
8465- my ($codeptr , $string , $tokenlist ) = @_ ;
8466- my ($retval );
8499+ my ($codeptr , $ref ) = @_ ;
8500+ my (@timelist , @tokenlist , $egrpstring , $elem , $retval );
8501+
8502+ # build the event group string and list parameters for the function
8503+
8504+ foreach $elem (@{$ref }) {
8505+ push @timelist , $elem -> [0];
8506+ push @tokenlist , $elem -> [2];
8507+ }
8508+
8509+ $egrpstring = join (" " , @tokenlist );
84678510
84688511 # call the function and save its return value;
84698512 # in the case of a function runtime error there is no match
84708513
8471- $retval = eval { $codeptr -> ($string , $ tokenlist ) };
8514+ $retval = eval { $codeptr -> ($egrpstring , \ @ tokenlist, \ @timelist ) };
84728515
84738516 if ($@ ) {
84748517 log_msg(LOG_ERR, " NPerlFunc pattern runtime error:" , $@ );
@@ -8479,6 +8522,7 @@ sub match_eventgroup_nperlfunc {
84798522 # context (undef, "", or 0), return 1, otherwise return 0
84808523
84818524 if (!$retval ) { return 1; }
8525+
84828526 return 0;
84838527}
84848528
@@ -9177,7 +9221,7 @@ sub process_singlewith2thresholds_rule {
91779221sub process_eventgroup_rule {
91789222
91799223 my ($rule , $subst , $conffile , $index ) = @_ ;
9180- my ($desc , $key , $time , $oper , $i , $egrpstring , @egrptokens );
9224+ my ($desc , $key , $time , $oper , $i );
91819225 my ($initaction , $slideaction , $endaction , $countaction , $action );
91829226
91839227 $desc = $rule -> {" Desc" };
@@ -9329,19 +9373,15 @@ sub process_eventgroup_rule {
93299373 $rule -> {" ThresholdList" }-> [$i ]) { return ; }
93309374 }
93319375
9332- # if event group pattern has been provided by the rule, create an event
9333- # group string and match it with event group pattern; if the pattern is
9334- # not matching, return
9376+ # if event group pattern has been provided by the rule, call a function
9377+ # that creates an event group string and matches it with the event group
9378+ # pattern; if the pattern is not matching, return
93359379
93369380 if (exists ($rule -> {" EGrpPattern" })) {
93379381
9338- @egrptokens = map { $_ -> [2] } @{$oper -> {" AllTimes" }};
9339- $egrpstring = join (" " , @egrptokens );
9340-
93419382 if (!$matchegrpfunc [$rule -> {" EGrpPatType" }]-> ($rule -> {" EGrpPattern" },
9342- $egrpstring ,
9343- \@egrptokens )) {
9344- return 0;
9383+ $oper -> {" AllTimes" })) {
9384+ return ;
93459385 }
93469386 }
93479387
0 commit comments