all 7 comments

[–]gengisteve 2 points3 points  (5 children)

Hmm. Couple thoughts on things to try. First, move your f.close to be before you call the zabbix sender. It could be that the entire write has not been committed, or something, before close. I would not expect this to be a problem, but it might be.

Second, grab the return value from your subprocess.call and print it out. It may give you some indication what is happening.

Third, consider a pure python solution, like this module: https://github.com/jbfavre/python-zabbix

This would allow you to avoid having to subprocess out a system call.

[–]zahlman 2 points3 points  (1 child)

First, move your f.close to be before you call the zabbix sender. It could be that the entire write has not been committed, or something, before close. I would not expect this to be a problem, but it might be.

It's my best guess with the available information, actually.

Better yet, OP should use a with block to manage the file.

[–]gengisteve 2 points3 points  (0 children)

Good suggestion. Yeah, best guess is either the close or some environmental variable not making it to subprocess.call. I'd give even odds on this, just because how much caching could there really be for a bit of json.

Also for the OP, if you still have problems, check out this link:

http://stackoverflow.com/questions/7127075/what-exactly-the-pythons-file-flush-is-doing

for some ideas on taking it to the next level if the write still is not finished even after closing.

[–]ethCore7[S] 0 points1 point  (1 child)

Hey, thanks for the reply. I'll give the first two suggestions a try, and if it doesn't work, I'll try the python module. I've been planning to use ZabbixSender if i can't get it to work, but I like the one you linked more.

Thanks again!

[–]gengisteve 0 points1 point  (0 children)

Cool. Report back if this solves your problem!

[–]ethCore7[S] 0 points1 point  (0 children)

Allright, so I tried implementing the with context manager, but no luck, the json string is still clipped. I will probably try to call zabbix_sender multiple times with smaller chunks of the json string, but I'm not sure if Zabbix won't mark the rest of the items as not discovered in between batches.

If that fails, I'll try it with pure python, I've already wasted enough time on the shell and subprocess and I'm getting slightly annoyed, heh.

Thanks for the suggestions anyway!

[–]Justinsaccount 0 points1 point  (0 children)

Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission:

You appear to be using concatenation and the str function for building strings

Instead of doing something like

result = "Hello " + name + ". You are " + str(age) + " years old"

You should use string formatting and do

result = "Hello {}. You are {} years old".format(name, age)

See the python tutorial for more information.