[parsers.nagios] can only read lines with a max length of 64kib
Use Case
The nagios specification says, that the first line of a nagios check script has to contain the text output (plugin output aka short message) followed by a pipe |, followed by optional perfdata (the metrics). Everything after the first new line is considered long plugin output. This can optionally be followed by a second pipe followed by more perfdata. Most check scripts don't use this possibility and append ALL perfdata to the first line. That can lead to very long lines. For example the check_nwc_health script appends performance data to every single port, if you check a switch. On large switches with many ports the first line can get really big.
Problem is, that the nagios parser uses a bufio.Scanner to read the lines, which is, by default, limited to 64kib of data. If the line to scan exceeds this length, the scanner throws an error bufio.Scanner: token too long.
In that case no metrics are created and the inputs.exec does not produce any output.
We would like to add an option to the nagios parser (nagios_max_buffer_size: int) to override the scanners default buffer size, which is possible.
Expected behavior
It is possible to override the scanners default buffer size to let it scan lines longer than 64kib, if necessary. If the nagios_max_buffer_size option is not used in the inputs.exec configuration, the default size is used, as of today.
Actual behavior
There is no option to override the scanners default buffer size and therefore it is not possible to use nagios plugins, that produce very long first lines.
steps to reproduce
install a telegraf somewhere
set up a telegraf configuration with following inputs.exec configuration, that uses aW test check script that produces very long first lines:
[inputs.exec] commands = ["gen_nagios_output.sh 80000"] data_format = "nagios"execute the telegraf
parsing the very long first line leads to an
[inputs.exec] Error in plugin: bufio.Scanner: token too longerror and the plugin does not produce any metrics.
gen_nagios_output.sh
#!/usr/bin/env bash
#
# Generate a valid single-line Nagios plugin output of at least <min_length>
# bytes, e.g. to test handling of very long first lines in inputs.exec with
# data_format = "nagios".
#
# Output format:
# OK - generated 2 metrics | metric1=000123;;;; metric2=000456;;;;
#
# Usage: gen_nagios_output.sh <min_length>
set -euo pipefail
if [[ $# -ne 1 || ! $1 =~ ^[0-9]+$ ]]; then
echo "Usage: $0 <min_length>" >&2
exit 3
fi
min_length=$1
# Stream the perfdata with awk because a pure bash loop is too slow for MiB-sized output.
awk -v min="$min_length" 'BEGIN {
n = 0
len = 0
while (25 + length(n) + len < min || n == 0) {
n++
len += 18 + length(n)
}
srand()
printf "OK - generated %d metrics |", n
for (i = 1; i <= n; i++) {
printf " metric%d=%06d;;;;", i, int(rand() * 1000000)
}
printf "\n"
}'
exit 0Additional info
No response
Source: influxdata/telegraf