Skip to content

Commit b6c78aa

Browse files
Ahmet OeztuerkAhmet Oeztuerk
authored andcommitted
fix the loop label, prevent infinite loops
1 parent 4b9a39c commit b6c78aa

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

pkg/nagflux/collector/spoolfile/nagiosSpoolfileWorker.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string)
277277
currentCheckMultiLabel = getCheckMultiRegexMatch(perfdataStringMatches[0][1])
278278
}
279279

280-
perfdataStringMatchLoop:
281280
for _, perfdataStringMatch := range perfdataStringMatches {
282281
// Allows to add tags and fields to spoolfileentries
283282
tags := map[string]string{}
@@ -325,36 +324,31 @@ func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string)
325324
fieldType, err := indexToPerformanceDataSliceField(i)
326325
if err != nil {
327326
log.Warnf("Error when converting the index to a known field in performance data : %s", err.Error())
328-
continue
327+
goto perfdataStringMatchLoopEnd
329328
}
330329

331330
switch fieldType {
332331
case RawMatch:
333-
continue
334332
case Label:
335333
if len(data) > w.perfdataLabelMaxSize {
336334
log.Warnf("Perfdata Label: '%s' is too long with length: %s and longer than the limit: %s. Probably an anomally. Skipping this perfdata item, Host: %v , Service: %v, Perfdata fields: %v", data, len(data), w.perfdataLabelMaxSize, perf.Hostname, perf.Service, perfdataStringMatch)
337-
goto perfdataStringMatchLoop
335+
goto perfdataStringMatchLoopEnd
338336
}
339-
continue
340337
case UOM:
341338
if len(data) > w.perfdataUOMMaxLength {
342339
log.Warnf("Perfdata UOM: '%s' is too long with length: %s and longer than the limit: %s. Probably an anomally. Host: %v , Service: %v, Perfdata fields: %v", data, len(data), w.perfdataUOMMaxLength, perf.Hostname, perf.Service, perfdataStringMatch)
343-
goto perfdataStringMatchLoop
340+
goto perfdataStringMatchLoopEnd
344341
}
345-
continue
346342
case Value, Min, Max:
347343
if len(data) > w.perfdataNumericValuesMaxLength {
348344
log.Warnf("Perfdata field %s: '%s' is too long with length: %s and longer than the limit: %s. Probably an anomally. Host: %v , Service: %v, Perfdata fields: %v", fieldType.String(), data, len(data), w.perfdataNumericValuesMaxLength, perf.Hostname, perf.Service, perfdataStringMatch)
349-
goto perfdataStringMatchLoop
345+
goto perfdataStringMatchLoopEnd
350346
}
351-
continue
352347
case Warn, Crit:
353348
if len(data) > w.perfdataThresholdsMaxLength {
354349
log.Warnf("Perfdata field %s: '%s' is too long with length: %s and longer than the limit: %s. Probably an anomally. Host: %v , Service: %v, Perfdata fields: %v", fieldType.String(), data, len(data), w.perfdataThresholdsMaxLength, perf.Hostname, perf.Service, perfdataStringMatch)
355-
goto perfdataStringMatchLoop
350+
goto perfdataStringMatchLoopEnd
356351
}
357-
continue
358352
}
359353

360354
if data == "" {
@@ -386,13 +380,13 @@ func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string)
386380
} else {
387381
perf.Tags[fillLabel] = "outer"
388382
}
389-
390383
for i, tag := range []string{"min", "max"} {
391-
tagKey := fmt.Sprintf("%s-%s", rangeRegex.String, tag)
384+
tagKey := fmt.Sprintf("%s-%s", fieldType.String(), tag)
392385
perf.Fields[tagKey] = helper.StringIntToStringFloat(rangeHits[i][0])
393386
}
394387
} else {
395388
log.Warnf("String: '%s' in field '%s' could not be parsed. Host: %v, Service: %v, Perf Data Fields: %v", data, fieldType.String(), perf.Hostname, perf.Service, perfdataStringMatch)
389+
goto perfdataStringMatchLoopEnd
396390
}
397391
case Value, Min, Max:
398392
if data == "U" {
@@ -401,12 +395,16 @@ func (w *NagiosSpoolfileWorker) PerformanceDataIterator(input map[string]string)
401395
}
402396
if !helper.IsStringANumber(data) {
403397
log.Warnf("String: '%s' in field '%s' is not a number, should be one. Host: %v, Service: %v, Perf Data Fields: %v", data, fieldType.String(), perf.Hostname, perf.Service, perfdataStringMatch)
404-
continue perfdataStringMatchLoop
398+
goto perfdataStringMatchLoopEnd
405399
}
406400
perf.Fields[fieldType.String()] = helper.StringIntToStringFloat(data)
407401
}
408402
}
403+
409404
ch <- perf
405+
406+
// Skip item without sending it to the channel
407+
perfdataStringMatchLoopEnd:
410408
}
411409
close(ch)
412410
}()
@@ -479,6 +477,8 @@ func indexToPerformanceDataSliceField(index int) (PerformanceDataSliceFields, er
479477
return Label, nil
480478
case 2:
481479
return Value, nil
480+
case 3:
481+
return UOM, nil
482482
case 4:
483483
return Warn, nil
484484
case 5:

0 commit comments

Comments
 (0)