Skip to content

Commit d69358e

Browse files
author
Risto Vaarandi
committed
version 2.9.2
1 parent 5f2234b commit d69358e

4 files changed

Lines changed: 96 additions & 42 deletions

File tree

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
--- version 2.9.2
2+
3+
* starting from this version, list of event occurrence times that correspond
4+
to event group string tokens is passed to PerlFunc and NPerlFunc event
5+
group patterns as an additional parameter.
6+
7+
18
--- version 2.9.1
29

310
* added support for 'egtoken*' fields in EventGroup rules.

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SEC (Simple Event Correlator) 2.9.1
1+
SEC (Simple Event Correlator) 2.9.2
22

33
Introduction:
44
-------------

sec

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

84048404
sub 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

84138419
sub 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

84228434
sub 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

84318449
sub 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

84408464
sub 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

84638497
sub 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 {
91779221
sub 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

sec.man

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\"
2-
.\" SEC (Simple Event Correlator) 2.9.1 - sec.man
3-
.\" Copyright (C) 2000-2022 Risto Vaarandi
2+
.\" SEC (Simple Event Correlator) 2.9.2 - sec.man
3+
.\" Copyright (C) 2000-2023 Risto Vaarandi
44
.\"
55
.\" This program is free software; you can redistribute it and/or
66
.\" modify it under the terms of the GNU General Public License
@@ -16,7 +16,7 @@
1616
.\" along with this program; if not, write to the Free Software
1717
.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
.\"
19-
.TH sec 1 "May 2022" "SEC 2.9.1"
19+
.TH sec 1 "June 2023" "SEC 2.9.2"
2020
.SH NAME
2121
sec \- simple event correlator
2222
.SH SYNOPSIS
@@ -4452,9 +4452,16 @@ If the
44524452
.I egptype
44534453
field is set to PerlFunc or NPerlFunc, the Perl function given with the
44544454
.I egpattern
4455-
field is called in the Perl scalar context, with the function having two
4456-
parameters: the event group string, and the reference to the list of tokens
4457-
from the event group string.
4455+
field is called in the Perl scalar context, with the function having three
4456+
parameters: the event group string, the reference to the list of tokens
4457+
from the event group string, and the reference to the list of event
4458+
occurrence times that correspond to tokens.
4459+
Each event occurrence time is provided in seconds since Epoch,
4460+
with the first element in the list being the occurrence time
4461+
of the event represented by the first token in the event group string,
4462+
the second element in the list being the occurrence time of the event
4463+
represented by the second token in the event group string, etc.
4464+
.PP
44584465
With
44594466
.IR egptype=PerlFunc ,
44604467
event group pattern matches if the return value of the function evaluates
@@ -6821,7 +6828,7 @@ With some locale settings, single quotes (') in this man page might
68216828
be displayed incorrectly. As a workaround, set the LANG environment
68226829
variable to C when reading this man page (e.g., env LANG=C man sec).
68236830
.SH AUTHOR
6824-
Risto Vaarandi (ristov at users d0t s0urcef0rge d0t net)
6831+
Risto Vaarandi (firstname d0t lastname at gmail d0t c0m)
68256832
.SH ACKNOWLEDGMENTS
68266833
The author is grateful to SEB Estonia for supporting this work.
68276834
The author also thanks the following people for supplying software patches,

0 commit comments

Comments
 (0)