@@ -75,11 +75,11 @@ func (n *Node) validate(ectx EnricherCtx) error {
75
75
76
76
/* "" behaves like continue */
77
77
if n .OnSuccess != "continue" && n .OnSuccess != "next_stage" && n .OnSuccess != "" {
78
- return fmt .Errorf ("onsuccess '%s' not continue,next_stage" , n .OnSuccess )
78
+ return fmt .Errorf ("onsuccess %q not continue,next_stage" , n .OnSuccess )
79
79
}
80
80
81
81
if n .Filter != "" && n .RunTimeFilter == nil {
82
- return fmt .Errorf ("non-empty filter '%s' was not compiled" , n .Filter )
82
+ return fmt .Errorf ("non-empty filter %q was not compiled" , n .Filter )
83
83
}
84
84
85
85
if n .Grok .RunTimeRegexp != nil || n .Grok .TargetField != "" {
@@ -95,15 +95,15 @@ func (n *Node) validate(ectx EnricherCtx) error {
95
95
for idx , static := range n .Statics {
96
96
if static .Method != "" {
97
97
if static .ExpValue == "" {
98
- return fmt .Errorf ("static %d : when method is set, expression must be present" , idx )
98
+ return fmt .Errorf ("static %d: when method is set, expression must be present" , idx )
99
99
}
100
100
101
101
if _ , ok := ectx .Registered [static .Method ]; ! ok {
102
- log .Warningf ("the method '%s' doesn't exist or the plugin has not been initialized" , static .Method )
102
+ log .Warningf ("the method %q doesn't exist or the plugin has not been initialized" , static .Method )
103
103
}
104
104
} else {
105
105
if static .Meta == "" && static .Parsed == "" && static .TargetByName == "" {
106
- return fmt .Errorf ("static %d : at least one of meta/event/target must be set" , idx )
106
+ return fmt .Errorf ("static %d: at least one of meta/event/target must be set" , idx )
107
107
}
108
108
109
109
if static .Value == "" && static .RunTimeValue == nil {
@@ -117,19 +117,19 @@ func (n *Node) validate(ectx EnricherCtx) error {
117
117
stash := & n .Stash [idx ]
118
118
119
119
if stash .Name == "" {
120
- return fmt .Errorf ("stash %d : name must be set" , idx )
120
+ return fmt .Errorf ("stash %d: name must be set" , idx )
121
121
}
122
122
123
123
if stash .Value == "" {
124
- return fmt .Errorf ("stash %s : value expression must be set" , stash .Name )
124
+ return fmt .Errorf ("stash %s: value expression must be set" , stash .Name )
125
125
}
126
126
127
127
if stash .Key == "" {
128
- return fmt .Errorf ("stash %s : key expression must be set" , stash .Name )
128
+ return fmt .Errorf ("stash %s: key expression must be set" , stash .Name )
129
129
}
130
130
131
131
if stash .TTL == "" {
132
- return fmt .Errorf ("stash %s : ttl must be set" , stash .Name )
132
+ return fmt .Errorf ("stash %s: ttl must be set" , stash .Name )
133
133
}
134
134
135
135
if stash .Strategy == "" {
@@ -147,28 +147,28 @@ func (n *Node) validate(ectx EnricherCtx) error {
147
147
func (n * Node ) processFilter (cachedExprEnv map [string ]any ) (bool , error ) {
148
148
clog := n .Logger
149
149
if n .RunTimeFilter == nil {
150
- clog .Tracef ("Node has not filter, enter" )
150
+ clog .Trace ("Node has not filter, enter" )
151
151
return true , nil
152
152
}
153
153
154
154
// Evaluate node's filter
155
155
output , err := exprhelpers .Run (n .RunTimeFilter , cachedExprEnv , clog , n .Debug )
156
156
if err != nil {
157
- clog .Warningf ("failed to run filter : %v" , err )
158
- clog .Debugf ("Event leaving node : ko" )
157
+ clog .Warningf ("failed to run filter: %v" , err )
158
+ clog .Debug ("Event leaving node: ko" )
159
159
160
160
return false , nil
161
161
}
162
162
163
163
switch out := output .(type ) {
164
164
case bool :
165
165
if ! out {
166
- clog .Debugf ("Event leaving node : ko (failed filter)" )
166
+ clog .Debug ("Event leaving node: ko (failed filter)" )
167
167
return false , nil
168
168
}
169
169
default :
170
- clog .Warningf ("Expr '%s' returned non-bool, abort : %T" , n .Filter , output )
171
- clog .Debugf ("Event leaving node : ko" )
170
+ clog .Warningf ("Expr %q returned non-bool, abort: %T" , n .Filter , output )
171
+ clog .Debug ("Event leaving node: ko" )
172
172
173
173
return false , nil
174
174
}
@@ -216,11 +216,11 @@ func (n *Node) processGrok(p *types.Event, cachedExprEnv map[string]any) (bool,
216
216
gstr := ""
217
217
218
218
if n .Grok .RunTimeRegexp == nil {
219
- clog .Tracef ("! No grok pattern : %p" , n .Grok .RunTimeRegexp )
219
+ clog .Tracef ("! No grok pattern: %p" , n .Grok .RunTimeRegexp )
220
220
return true , false , nil
221
221
}
222
222
223
- clog .Tracef ("Processing grok pattern : %s : %p" , n .Grok .RegexpName , n .Grok .RunTimeRegexp )
223
+ clog .Tracef ("Processing grok pattern: %s: %p" , n .Grok .RegexpName , n .Grok .RunTimeRegexp )
224
224
// for unparsed, parsed etc. set sensible defaults to reduce user hassle
225
225
if n .Grok .TargetField != "" {
226
226
// it's a hack to avoid using real reflect
@@ -229,13 +229,13 @@ func (n *Node) processGrok(p *types.Event, cachedExprEnv map[string]any) (bool,
229
229
} else if val , ok := p .Parsed [n .Grok .TargetField ]; ok {
230
230
gstr = val
231
231
} else {
232
- clog .Debugf ("(%s) target field '%s' doesn't exist in %v" , n .rn , n .Grok .TargetField , p .Parsed )
232
+ clog .Debugf ("(%s) target field %q doesn't exist in %v" , n .rn , n .Grok .TargetField , p .Parsed )
233
233
return false , false , nil
234
234
}
235
235
} else if n .Grok .RunTimeValue != nil {
236
236
output , err := exprhelpers .Run (n .Grok .RunTimeValue , cachedExprEnv , clog , n .Debug )
237
237
if err != nil {
238
- clog .Warningf ("failed to run RunTimeValue : %v" , err )
238
+ clog .Warningf ("failed to run RunTimeValue: %v" , err )
239
239
return false , false , nil
240
240
}
241
241
@@ -247,7 +247,7 @@ func (n *Node) processGrok(p *types.Event, cachedExprEnv map[string]any) (bool,
247
247
case float64 , float32 :
248
248
gstr = fmt .Sprintf ("%f" , out )
249
249
default :
250
- clog .Errorf ("unexpected return type for RunTimeValue : %T" , output )
250
+ clog .Errorf ("unexpected return type for RunTimeValue: %T" , output )
251
251
}
252
252
}
253
253
@@ -262,23 +262,23 @@ func (n *Node) processGrok(p *types.Event, cachedExprEnv map[string]any) (bool,
262
262
263
263
if len (grok ) == 0 {
264
264
// grok failed, node failed
265
- clog .Debugf ("+ Grok '%s' didn't return data on '%s' " , groklabel , gstr )
265
+ clog .Debugf ("+ Grok %q didn't return data on %q " , groklabel , gstr )
266
266
return false , false , nil
267
267
}
268
268
269
269
/*tag explicitly that the *current* node had a successful grok pattern. it's important to know success state*/
270
270
nodeHasOKGrok = true
271
271
272
- clog .Debugf ("+ Grok '%s' returned %d entries to merge in Parsed" , groklabel , len (grok ))
272
+ clog .Debugf ("+ Grok %q returned %d entries to merge in Parsed" , groklabel , len (grok ))
273
273
// We managed to grok stuff, merged into parse
274
274
for k , v := range grok {
275
- clog .Debugf ("\t .Parsed['%s' ] = '%s' " , k , v )
275
+ clog .Debugf ("\t .Parsed[%q ] = %q " , k , v )
276
276
p .Parsed [k ] = v
277
277
}
278
278
// if the grok succeed, process associated statics
279
279
err := n .ProcessStatics (n .Grok .Statics , p )
280
280
if err != nil {
281
- clog .Errorf ("(%s) Failed to process statics : %v" , n .rn , err )
281
+ clog .Errorf ("(%s) Failed to process statics: %v" , n .rn , err )
282
282
return false , false , err
283
283
}
284
284
@@ -304,28 +304,28 @@ func (n *Node) processStash(p *types.Event, cachedExprEnv map[string]any, logger
304
304
// collect the data
305
305
output , err := exprhelpers .Run (stash .ValueExpression , cachedExprEnv , logger , n .Debug )
306
306
if err != nil {
307
- logger .Warningf ("Error while running stash val expression : %v" , err )
307
+ logger .Warningf ("Error while running stash val expression: %v" , err )
308
308
}
309
309
// can we expect anything else than a string ?
310
310
switch output := output .(type ) {
311
311
case string :
312
312
value = output
313
313
default :
314
- logger .Warningf ("unexpected type %t (%v) while running '%s' " , output , output , stash .Value )
314
+ logger .Warningf ("unexpected type %T (%v) while running %q " , output , output , stash .Value )
315
315
continue
316
316
}
317
317
318
318
// collect the key
319
319
output , err = exprhelpers .Run (stash .KeyExpression , cachedExprEnv , logger , n .Debug )
320
320
if err != nil {
321
- logger .Warningf ("Error while running stash key expression : %v" , err )
321
+ logger .Warningf ("Error while running stash key expression: %v" , err )
322
322
}
323
323
// can we expect anything else than a string ?
324
324
switch output := output .(type ) {
325
325
case string :
326
326
key = output
327
327
default :
328
- logger .Warningf ("unexpected type %t (%v) while running '%s' " , output , output , stash .Key )
328
+ logger .Warningf ("unexpected type %T (%v) while running %q " , output , output , stash .Key )
329
329
continue
330
330
}
331
331
@@ -342,7 +342,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx, expressionEnv map[stri
342
342
343
343
cachedExprEnv := expressionEnv
344
344
345
- clog .Tracef ("Event entering node" )
345
+ clog .Trace ("Event entering node" )
346
346
347
347
nodeState , err := n .processFilter (cachedExprEnv )
348
348
if err != nil {
@@ -405,15 +405,15 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx, expressionEnv map[stri
405
405
/*todo : check if a node made the state change ?*/
406
406
/* should the childs inherit the on_success behavior */
407
407
408
- clog .Tracef ("State after nodes : %v" , nodeState )
408
+ clog .Tracef ("State after nodes: %v" , nodeState )
409
409
410
410
// grok or leafs failed, don't process statics
411
411
if ! nodeState {
412
412
if n .Name != "" {
413
413
metrics .NodesHitsKo .With (prometheus.Labels {"source" : p .Line .Src , "type" : p .Line .Module , "name" : n .Name , "stage" : p .Stage , "acquis_type" : p .Line .Labels ["type" ]}).Inc ()
414
414
}
415
415
416
- clog .Debugf ("Event leaving node : ko" )
416
+ clog .Debug ("Event leaving node: ko" )
417
417
418
418
return nodeState , nil
419
419
}
@@ -431,34 +431,34 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx, expressionEnv map[stri
431
431
// if all else is good in whitelist, process node's statics
432
432
err := n .ProcessStatics (n .Statics , p )
433
433
if err != nil {
434
- clog .Errorf ("Failed to process statics : %v" , err )
434
+ clog .Errorf ("Failed to process statics: %v" , err )
435
435
return false , err
436
436
}
437
437
} else {
438
- clog .Tracef ("! No node statics" )
438
+ clog .Trace ("! No node statics" )
439
439
}
440
440
441
441
if nodeState {
442
- clog .Debugf ("Event leaving node : ok" )
443
- log .Tracef ("node is successful, check strategy" )
442
+ clog .Debug ("Event leaving node : ok" )
443
+ log .Trace ("node is successful, check strategy" )
444
444
445
445
if n .OnSuccess == "next_stage" {
446
446
idx := stageidx (p .Stage , ctx .Stages )
447
447
// we're at the last stage
448
448
if idx + 1 == len (ctx .Stages ) {
449
- clog .Debugf ("node reached the last stage : %s" , p .Stage )
449
+ clog .Debugf ("node reached the last stage: %s" , p .Stage )
450
450
} else {
451
451
clog .Debugf ("move Event from stage %s to %s" , p .Stage , ctx .Stages [idx + 1 ])
452
452
p .Stage = ctx .Stages [idx + 1 ]
453
453
}
454
454
} else {
455
- clog .Tracef ("no strategy on success (%s), continue !" , n .OnSuccess )
455
+ clog .Tracef ("no strategy on success (%s), continue!" , n .OnSuccess )
456
456
}
457
457
} else {
458
- clog .Debugf ("Event leaving node : ko" )
458
+ clog .Debug ("Event leaving node: ko" )
459
459
}
460
460
461
- clog .Tracef ("Node successful, continue" )
461
+ clog .Trace ("Node successful, continue" )
462
462
463
463
return nodeState , nil
464
464
}
@@ -491,64 +491,64 @@ func (n *Node) compile(pctx *UnixParserCtx, ectx EnricherCtx) error {
491
491
/* display info about top-level nodes, they should be the only one with explicit stage name ?*/
492
492
n .Logger = n .Logger .WithFields (log.Fields {"stage" : n .Stage , "name" : n .Name })
493
493
494
- n .Logger .Tracef ("Compiling : %s" , dumpr .Sdump (n ))
494
+ n .Logger .Tracef ("Compiling: %s" , dumpr .Sdump (n ))
495
495
496
496
// compile filter if present
497
497
if n .Filter != "" {
498
498
n .RunTimeFilter , err = expr .Compile (n .Filter , exprhelpers .GetExprOptions (map [string ]any {"evt" : & types.Event {}})... )
499
499
if err != nil {
500
- return fmt .Errorf ("compilation of '%s' failed: %v" , n .Filter , err )
500
+ return fmt .Errorf ("compilation of %q failed: %v" , n .Filter , err )
501
501
}
502
502
}
503
503
504
504
/* handle pattern_syntax and groks */
505
505
for _ , pattern := range n .SubGroks {
506
- n .Logger .Tracef ("Adding subpattern '%s' : '%s'" , pattern .Key , pattern .Value )
506
+ n .Logger .Tracef ("Adding subpattern '%s': '%s'" , pattern .Key , pattern .Value )
507
507
508
508
if err = pctx .Grok .Add (pattern .Key .(string ), pattern .Value .(string )); err != nil {
509
509
if errors .Is (err , grokky .ErrAlreadyExist ) {
510
510
n .Logger .Warningf ("grok '%s' already registred" , pattern .Key )
511
511
continue
512
512
}
513
513
514
- n .Logger .Errorf ("Unable to compile subpattern %s : %v" , pattern .Key , err )
514
+ n .Logger .Errorf ("Unable to compile subpattern %s: %v" , pattern .Key , err )
515
515
516
516
return err
517
517
}
518
518
}
519
519
520
520
/* load grok by name or compile in-place */
521
521
if n .Grok .RegexpName != "" {
522
- n .Logger .Tracef ("+ Regexp Compilation '%s' " , n .Grok .RegexpName )
522
+ n .Logger .Tracef ("+ Regexp Compilation %q " , n .Grok .RegexpName )
523
523
524
524
n .Grok .RunTimeRegexp , err = pctx .Grok .Get (n .Grok .RegexpName )
525
525
if err != nil {
526
- return fmt .Errorf ("unable to find grok '%s' : %v" , n .Grok .RegexpName , err )
526
+ return fmt .Errorf ("unable to find grok %q : %v" , n .Grok .RegexpName , err )
527
527
}
528
528
529
529
if n .Grok .RunTimeRegexp == nil {
530
- return fmt .Errorf ("empty grok '%s' " , n .Grok .RegexpName )
530
+ return fmt .Errorf ("empty grok %q " , n .Grok .RegexpName )
531
531
}
532
532
533
533
n .Logger .Tracef ("%s regexp: %s" , n .Grok .RegexpName , n .Grok .RunTimeRegexp .String ())
534
534
535
535
valid = true
536
536
} else if n .Grok .RegexpValue != "" {
537
537
if strings .HasSuffix (n .Grok .RegexpValue , "\n " ) {
538
- n .Logger .Debugf ("Beware, pattern ends with \\ n : '%s' " , n .Grok .RegexpValue )
538
+ n .Logger .Debugf ("Beware, pattern ends with \\ n: %q " , n .Grok .RegexpValue )
539
539
}
540
540
541
541
n .Grok .RunTimeRegexp , err = pctx .Grok .Compile (n .Grok .RegexpValue )
542
542
if err != nil {
543
- return fmt .Errorf ("failed to compile grok '%s' : %v" , n .Grok .RegexpValue , err )
543
+ return fmt .Errorf ("failed to compile grok %q : %v" , n .Grok .RegexpValue , err )
544
544
}
545
545
546
546
if n .Grok .RunTimeRegexp == nil {
547
547
// We shouldn't be here because compilation succeeded, so regexp shouldn't be nil
548
548
return fmt .Errorf ("grok compilation failure: %s" , n .Grok .RegexpValue )
549
549
}
550
550
551
- n .Logger .Tracef ("%s regexp : %s" , n .Grok .RegexpValue , n .Grok .RunTimeRegexp .String ())
551
+ n .Logger .Tracef ("%s regexp: %s" , n .Grok .RegexpValue , n .Grok .RunTimeRegexp .String ())
552
552
553
553
valid = true
554
554
}
0 commit comments