[ZBX-24969] vfs.file.regmatch does not break after match Created: 2024 Aug 05 Updated: 2025 Apr 11 Resolved: 2025 Apr 11 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Agent (G) |
Affects Version/s: | 6.0.32 |
Fix Version/s: | 7.0.12rc1, 7.2.6rc1, 7.4.0rc1 (master) |
Type: | Problem report | Priority: | Trivial |
Reporter: | Sander Linsen | Assignee: | Armands Arseniuss Skolmeisters |
Resolution: | Fixed | Votes: | 0 |
Labels: | None | ||
Remaining Estimate: | 0h | ||
Time Spent: | 3h | ||
Original Estimate: | 3h |
Team: | |
Sprint: | S25-W12/13, S25-W14/15 |
Story Points: | 1 |
Description |
Steps to reproduce:
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: ./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
|
Comments |
Comment by Vladislavs Sokurenko [ 2024 Aug 05 ] |
This should do the trick: diff --git a/src/go/plugins/vfs/file/regmatch.go b/src/go/plugins/vfs/file/regmatch.go index 2addcd79ebe..732ad6a5463 100644 --- a/src/go/plugins/vfs/file/regmatch.go +++ b/src/go/plugins/vfs/file/regmatch.go @@ -111,6 +111,7 @@ func (p *Plugin) exportRegmatch(params []string, timeout int) (result interface{ if curline >= startline { if match := r.Match([]byte(utf8_bufStr)); match { ret = 1 + break } } |
Comment by Sander Linsen [ 2024 Aug 05 ] |
Yes, a diff would've been more helpful. Thank you! |
Comment by Armands Arseniuss Skolmeisters [ 2025 Apr 08 ] |
Available in versions:
|