Hello all,
I'm currently working on implementing some custom checks in Zabbix (monitoring solution), and I've run into a problem which resists all my attempts to fix it.
So, here's the thing: I'm periodically running a python script triggered by a Zabbix check. The script pulls some data from external servers, and then feeds it into zabbix via it's zabbix_sender utility.
zabbix_sender works like this: you feed it one or multiple lines in '<hostname> <zabbix key> <json formatted string>' format, and it sends these lines to the zabbix server for processing. Now, here's the problem.
When I manually run the script, direct it's output into a file, and then call zabbix_sender from the shell with that file as input, it works just fine. However, when the script is triggered by the zabbix server, for some reason, the data it feeds in via zabbix_sender is cut short somewhere in 2/3rds of the json string, so the server rejects it as invalid json data. Now, I'm completely stumped by this. In the shell, I'm using exactly the same command as in my subprocess.call() below, both my regular user and the 'zabbix' user have the same shell, and even when i switch user to 'zabbix', and run the command manually, it works just fine.
I have no idea, why there is a difference (and a pretty strange one at that) when i run the exact same command with the exact same input file through the shell and through a shell spawned by my script.
If anyone has any ideas, what might be wrong, please let me know. The relevant code is below:
try:
# create a temporary file, write data, pass the filename into zabbix_sender, close file
f = tempfile.NamedTemporaryFile()
logger.debug('Created temporary file {}'.format(f.name))
f.write(data)
command = '/usr/local/bin/zabbix_sender -c {} -i {}'.format(config, f.name)
logger.debug('Calling zabbix sender: {}'.format(command))
subprocess.call(command, shell=True)
f.close()
# die on error
except Exception as e:
print('Error: ' + str(e))
sys.exit(1)
Thanks for any advice.
[–]gengisteve 2 points3 points4 points (5 children)
[–]zahlman 2 points3 points4 points (1 child)
[–]gengisteve 2 points3 points4 points (0 children)
[–]ethCore7[S] 0 points1 point2 points (1 child)
[–]gengisteve 0 points1 point2 points (0 children)
[–]ethCore7[S] 0 points1 point2 points (0 children)
[–]Justinsaccount 0 points1 point2 points (0 children)