-
Patch request
-
Resolution: Unresolved
-
Trivial
-
6.0.32
-
None
-
Sprint candidates
Steps to reproduce:
- Create Item key (for example): vfs.file.regmatch[/var/log/messages, ".", "utf8"]
- Get error message: Timeout while processing item.
- This is because Zabbix Agent 2 reads the entire file, while we are only searching for one match. When a match is found, Zabbix Agent 2 keeps searching.
Result:
zabbix_agent2 -t 'vfs.file.regmatch[/tmp/messages, ".", "utf8"]' -> 2024/08/02 14:58:13.213737 [MongoDB] plugin "/usr/sbin/zabbix-agent2-plugin/zabbix-agent2-plugin-mongodb" process exited 2024/08/02 14:58:13.218301 [PostgreSQL] plugin "/usr/sbin/zabbix-agent2-plugin/zabbix-agent2-plugin-postgresql" process exited vfs.file.regmatch[/tmp/messages, ".", "utf8"] [m|ZBX_NOTSUPPORTED] [Timeout while processing item.]
Expected:
The check succeeds and exits with first found match:
./zabbix_agent2 -t 'vfs.file.regmatch[/tmp/messages, ".", "utf8"]' vfs.file.regmatch[/tmp/messages, ".", "utf8"] [s|1]
Proposed Solution:
We took the source of the Zabbix Agent 2 binary and added a break in the last for loop of:
zabbix-6.0.32/src/go/plugins/vfs/file/regmatch.go
That looks like this:
... initial := true undecodedBufNumBytes := 0 var undecodedBuf []byte for 0 < undecodedBufNumBytes || initial { initial = false elapsed := time.Since(start) if elapsed.Seconds() > float64(p.options.Timeout) { return nil, errors.New("Timeout while processing item.") } curline++ undecodedBuf, undecodedBufNumBytes, encoding, err = p.readTextLineFromFile(f, encoding) if err != nil { return nil, err } utf8_buf, utf8_bufNumBytes := decodeToUTF8(encoding, undecodedBuf, undecodedBufNumBytes) utf8_bufStr := string(utf8_buf[:utf8_bufNumBytes]) if curline >= startline { if match := r.Match([]byte(utf8_bufStr)); match { ret = 1 break <<<<<<<-------- HERE } } if curline >= endline { break } } return ret, nil
This will return the expected value and speeds up the processing:
time ./zabbix_agent2 -t 'vfs.file.regmatch[/tmp/messages, ".", "utf8"]' vfs.file.regmatch[/tmp/messages, ".", "utf8"] [s|1]real 0m0.407s user 0m0.005s sys 0m0.006s