0

I am using Zabbix 2.2.
I have a very specific environment, where I have to generate desired data to file via script, then upload that file to ftp from host and download it to Zabbix server from ftp.
After file is downloaded, I check it with log[] and vfs.file.regexp[] items.

I use these items as below:

log[/path/to/file.txt,"C.*\s([0-9]+\.[0-9])$",Windows-1250,,"all",\1]
vfs.file.regexp[/path/to/file.txt,"C.*\s([0-9]+\.[0-9])$",Windows-1250,,,\1]

The line I am parsing looks like below:

                C:      8195Mb  5879Mb  2316Mb  28.2

The value I want to extract is 28.2 at the end of file.

The problem I am currently trying to solve is that when I update the file (upload from host to ftp, then download from ftp to Zabbix server), the value does not update.

I was trying only log[] at start, but I suspect, that log[] treat the file as real log file and doesn't check the same lines (althought, following the documentation, it should with "all" value), so I added vfs.file.regexp[] item too.

The log[] has received a value in past, but it doesn't update.
The vfs.file.regexp[] hasn't received any value so far.
file.txt has got reuploaded and redownloaded several times and situation doesn't change.
It seems that log[] reads only new lines in the file, it doesn't check lines already caught if there are any changes.

The zabbix_agentd.log file doesn't report any problem with access to file, nor with regexp construction (it did report "unsupported" for log[] key, when I had something set up wrong).

I use debug logging level for agent - I haven't found any interesting info about that problem.

I have no idea what I might be doing wrong or what I do not know about how Zabbix is performing these checks. I see 2 solutions for that: adding more lines to the file instead of making new one or making new files and check them with logrt[], but those doesn't satisfy my desires.
Any help is greatly appreciated.
Of course I will provide additional information, if requested - for now I don't know what else might be useful.

tymik
  • 378
  • 2
  • 4
  • 16
  • 1
    Regarding "C.*([0-9]+\.[0-9])$" regexp and the fact that it matches only "8.2", rather than "28.2". The reason is that ".*" after "C" is greedy, so it eats up everything up to "8". You can fix it by including a space before "(", like this: "C.* ([0-9]+\.[0-9])$". – asaveljevs May 20 '14 at 14:31
  • I've tried regexp with .*?, which should be lazy, but Zabbix doesn't seem to understand ? modifier. Anyways, finally not regexp was the problem, as I've fixed it and problem still persist. – tymik May 21 '14 at 10:03
  • 1
    Since log[] is meant for log file monitoring (i.e., files that grow in size line by line), the correct approach in your case would be to use vfs.file.regexp[], so let's stick to that key only. I have tried the following item and it works perfectly: vfs.file.regexp[/tmp/file.txt,"C.*\s([0-9]+\.[0-9])$",,,,\1]. Could you please provide more information on the problem? Is the item in "not supported" state? How small is its update interval? Does it work if you save the file in UTF-8 encoding and omit "Windows-1250" from the key? – asaveljevs May 21 '14 at 11:24
  • update interval is 30s by default. I haven't found it being in "not supported" state. I have no idea how to adapt script for dumping data in utf-8, but I wouldn't consider it as being problemmaker, because in log[] it works that way. And trying to dump in utf8 would probably require much more effort than trying to solve problem with logrt[]. vfs.file.regexp[] is configured to return value as float. And value is supposed to be float if I want to use triggers with the value, without making triggers statements heavily complicated to perform comparison on extracted value. Can I provide more info? – tymik May 21 '14 at 15:12
  • What happens when you execute the following command on the agent's host: $ zabbix_agentd -t 'vfs.file.regexp[/tmp/file.txt,"C.*\s([0-9]+\.[0-9])$",Windows-1250,,,\1]'? Here, replace path to the file with the correct one. – asaveljevs May 22 '14 at 08:26
  • it returns: [s|] even for \0 in item. it works ok unless i put anything into group in regexp. for a dummy test, .* in group worked fine for \0, but for \1 didn't return anything – tymik May 22 '14 at 09:49
  • It seems that there is a bug in Zabbix that is related to Windows line endings. I have reported it as https://support.zabbix.com/browse/ZBX-8248 . Meanwhile, does it help if you omit "$" from the regular expression? – asaveljevs May 23 '14 at 06:52
  • Yes, it helps with "$" omitted, group is properly catched, but inly from command line - Zabbix server didn't get the value yet. I'll add another comment if the value gets to Zabbix server. I wonder why it works in log[] and doesn't work with vfs.file.regexp[] item, as I used exactly the same regexp in both. – tymik May 23 '14 at 09:10
  • Ok, it started updating after some time and it receives the value regardless the value doesn't change. – tymik May 23 '14 at 11:05
  • Do I understand correctly that in "Latest data" you see an old value for the item, but the file contains a new one? If so and the data for the item is periodically coming to Zabbix server, then you might be pointing it at the wrong file. – asaveljevs May 23 '14 at 13:38
  • No, the value get's updates with every period of item check, it works properly. It reads and stores the value regardless of it's change and this is what I wanted to achieve :) – tymik May 24 '14 at 11:28
  • @asaveljevs will you complete the information and post is as an answer or should I do it? – tymik May 27 '14 at 05:31

2 Answers2

1

Item log[] is meant for files that grow in size line by line, so the correct approach in your case would be to stick to vfs.file.regexp[].

With vfs.file.regexp[], you are doing everything correctly, except that there is a bug in Zabbix (reported as ZBX-8248) that prevents "$" symbol in regular expressions from matching Windows line endings.

So in order to make it work in the meanwhile you should omit "$" from the regular expression.

asaveljevs
  • 1,143
  • 6
  • 8
0

I have not tried the log functionality of Zabbix, but my guess is that the log file is opened once during the Zabbix agent startup and then held open. This means that even if you overwrite your file, the old file handle is still kept open and Zabbix reads the data from there.

If this is the case, I propose you two solutions:

1) Somehow send HUP signal to Zabbix agent (so it would reopen the files for reading)

or

2) Use the External script functionality in Zabbix and create a shell script which parses your file.

Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78
  • 1
    @Janne: The log file is opened every N seconds, where N is the item update interval. It is never held open for a long period of time. – asaveljevs May 20 '14 at 14:25