gpmidi / zabbix-apache-stats

GNU General Public License v2.0
54 stars 46 forks source link

ValueError: need more than 1 value to unpack #1

Closed error10 closed 10 years ago

error10 commented 10 years ago

Attempting to run fetch.py on a CentOS 5.10 system returns the following error:

Traceback (most recent call last):
  File "/etc/zabbix/bin/fetch.py", line 224, in <module>
    data = parse(data = data)
  File "/etc/zabbix/bin/fetch.py", line 77, in parse
    for (key, val) in csvobj:
ValueError: need more than 1 value to unpack

This is very strange code. It works perfectly on my Debian and Ubuntu systems; this is the first CentOS box I have tried to run it on.

I threw in a print data just before line 77 to verify that it was actually seeing the Apache server status, and the status appeared to be present and valid.

The only other change I made to the script was in line 1, which I changed to:

#!/usr/bin/python26

to try to rule out any problem with Python 2.4.

The box is running:

CentOS 5.10 python26-2.6.8-2.el5

My command line was:

/etc/zabbix/bin/fetch.py -c $(hostname) -z monitor.example.com -l http://localhost/whm-server-status
gpmidi commented 10 years ago

Could you change the "print data" to "print repr(csvobj)" and send me the output on your CentOS 5 box and also from one of the working systems?

PS Yeah, the code is weird because I was new to Python at the time.

error10 commented 10 years ago

The output from the working Debian system is:

# /etc/zabbix/bin/fetch.py -c $(hostname) -z monitor.example.com
<_csv.reader object at 0xb716e454>
zabbix_sender [24704]: DEBUG: Answer [{
        "response":"success",
        "info":"Processed 20 Failed 0 Total 20 Seconds spent 0.000334"}]
Info from server: "Processed 20 Failed 0 Total 20 Seconds spent 0.000334"
sent: 20; skipped: 0; total: 20

The output from the failing CentOS 5 system is:

# /etc/zabbix/bin/fetch.py -c $(hostname) -z monitor.example.com -l http://localhost/whm-server-status
<_csv.reader object at 0x14d88a0>
Traceback (most recent call last):
  File "/etc/zabbix/bin/fetch.py", line 225, in <module>
    data = parse(data = data)
  File "/etc/zabbix/bin/fetch.py", line 78, in parse
    for (key, val) in csvobj:
ValueError: need more than 1 value to unpack

Actually I think I just found the difference. On the working system, the server-status URL is http://localhost/server-status, which is apparently the default. On the failing system the URL is http://localhost/whm-server-status (since it's using cPanel, at least until I get rid of it). So I was able to reproduce the error on the working Debian system simply by specifying a -l option:

# /etc/zabbix/bin/fetch.py -c $(hostname) -z monitor.example.com -l http://localhost/server-status
<_csv.reader object at 0xb70f7b1c>
Traceback (most recent call last):
  File "/etc/zabbix/bin/fetch.py", line 225, in <module>
    data = parse(data = data)
  File "/etc/zabbix/bin/fetch.py", line 78, in parse
    for (key, val) in csvobj:
ValueError: need more than 1 value to unpack
gpmidi commented 10 years ago

Did you add the Location directive noted in the readme to Apache's config?

error10 commented 10 years ago

Yes, it's in Apache's config.

After some more digging, I discovered that the URL needs to contain ?auto at the end in order to work.

So:

# /etc/zabbix/bin/fetch.py -c $(hostname) -z monitor.example.com -l http://localhost/whm-server-status

fails, while

# /etc/zabbix/bin/fetch.py -c $(hostname) -z monitor.example.com -l http://localhost/whm-server-status?auto

works properly.

You could call this a PEBKAC if you want...

gpmidi commented 10 years ago

Good to hear that you have it working. I've added a note about the issue to the readme.

mtcocktail commented 10 years ago

I've the same error and the same resolution with a classical LAMP with a new url of server-status-module. I think you must change readme, maybe this is not only for Cpanel user. But i don't understand why i must add "?auto". This option charge an automatic reload when i'm consulting with browser. With fetch.py it simply get one times the server-status page ?

jva5007 commented 9 years ago

I tried to run this script from our monitoring server for a remote host running Apache 2.4.16, but when I excecute cron, it returns the following error.

Traceback (most recent call last): File "/usr/local/plugin/fetch.py", line 225, in data = parse(data = data) File "/usr/local/plugin/fetch.py", line 78, in parse for (key, val) in csvobj: ValueError: need more than 1 value to unpack

I have added hostname before each item key in the template.

When I add print data in 77th line in the script it shows correct data from apache server along with the error above. I also checked with 'print repr(csvobj)' but it shows the following.

<_csv.reader object at 0x7f04feca5a60> Traceback (most recent call last): File "/usr/local/plugin/fetch.py", line 225, in data = parse(data = data) File "/usr/local/plugin/fetch.py", line 78, in parse for (key, val) in csvobj: ValueError: need more than 1 value to unpack

remote host is an amazon ec2 instance.