nobody43 / zabbix-smartmontools

Disk SMART monitoring for Linux, FreeBSD and Windows. LLD, trapper.
The Unlicense
54 stars 19 forks source link

Zabbix_sender error #1

Closed mappsys closed 7 years ago

mappsys commented 7 years ago

When running smartctl-send.py to send data to zabbix, i found the following error:

zabbix_sender [20508]: ERROR: [line 1] '-' encountered as 'Hostname', but no default hostname was specified.

I looked behind the problem and i found that the parsing of zabbix agent configuration, used in -c parameter does not return the Hostname when using the "HostnameItem=system.hostname" (the default agent configuration). This creates a big trouble when automating distribution of agent among several monitored hosts.

To workaround i must set the "Hostname=" with a fixed agent's name.

mappsys commented 7 years ago

The problem is caused by zabbix_sender command. The command does not fallback to HostnameItem when Hostname parameter is not found, and this will not be changed as you could see in https://support.zabbix.com/browse/ZBXNEXT-1729.

nobody43 commented 7 years ago

That's a good catch, thank you! If it does not fall back we will fall back for it. :) Will fix soon.

nobody43 commented 7 years ago

resolved

mappsys commented 7 years ago

Hi, thanks for the upload, but it seems this will not solve the problem! The error is on zabbix_sender command using de -c parameter (used in smartctl-send.py, lines 25 and 29). These lines continues to use '-' hardcoded and the code you send only changes the smartctl_lld.py. I'm not sure how the subprocess.Popen works on python3, but it seems the new variable is local to the first script and will not be visible through the pipe to be used in smartctl-send.py. I change my local copy with the following code:

"$(zabbix_agentd -t agent.hostname | grep -oP '(?<=[s|).*(?=])')"

Thanks again for this program it help me a lot.

nobody43 commented 7 years ago

Have you changed 'hostnameFrom' to 'fqdn'? The default is 'config' because its faster and widely used.

Here's the logic: if string matches - python determines system full or short name (guess full is what 'system.hostname' does). So, one that passes to sender is:

example.org smartctl.info[sda,device] "sda"

and it works without hostname in config, I've tested it. If it does not work for you - please provide output of:

zabbix_get -s 127.0.0.1 -k smartctl.discovery[-v]

mappsys commented 7 years ago

Hi, it seems that we are talking about different things here. Your logic is correct, but the error is on the second script (smartctl-SEND.py not smartctl-LLD.py). The error is not on the zabbix_get. To set a real test, you need to comment Hostname parameter in zabbix_agentd.conf and use the HostnameItem=system.hostname instead. Here is my output (using -v instead of get):

... zabbix_sender [16507]: ERROR: [line 1] '-' encountered as 'Hostname', but no default hostname was specified Sending failed. Use option -vv for more detailed output.

Thanks in advance!

nobody43 commented 7 years ago

Please provide item's data string: example.org smartctl.info[sda,device] "sda"

mappsys commented 7 years ago

Here is the data string:

nobody43 commented 7 years ago

That's it - you have to update the scripts!

It must work after that. Sender call will still be '-i -', yes, but data are changed to specific hostname and no error is triggered.

mappsys commented 7 years ago

it works! Thanks!

nobody43 commented 7 years ago

As of https://github.com/nobodysu/zabbix-smartmontools/commit/2823562878dc10a2c8ea4d5989bc099229f0331c this action is automatic.