我终于放弃了,自己去调试了。
基于@SelivanovPavel的回答,我打开了调试功能zencommand
并等待,当然,ZenPack失败了。
2012-08-16 18:16:14,092 INFO zen.zencommand: Datasource MySQL/mysql command: /opt/zenoss/ZenPacks/ZenPacks.zenoss.MySqlMonitor-2.2.0-py2.7.egg/ZenPacks/zenoss/MySqlMonitor/libexec/check_mysql_stats.py -H 2001:db8:81:2c::2 -p 3306 -u zenoss -w 'password' -g
2012-08-16 18:16:14,100 DEBUG zen.zencommand: Running /opt/zenoss/ZenPacks/ZenPacks.zenoss.MySqlMonitor-2.2.0-py2.7.egg/ZenPacks/zenoss/MySqlMonitor/libexec/check_mysql_stats.py
2012-08-16 18:16:14,544 DEBUG zen.zencommand: Datasource: mysql Received exit code: 1 Output: 'MySQL Error: (2003, "Can\'t connect to MySQL server on \'2001:db8:81:2c::2\' (-9)")\n'
2012-08-16 18:16:14,545 DEBUG zen.zencommand: Process MySQL/mysql stopped (1), 0.43 seconds elapsed
所以我挖成ZenPack,发现它被导入(一个显然是旧版本的)pymysql
从/opt/zenoss/lib/python
。
在python命令行上进行测试时,我发现了从何处抛出异常:
>>> sys.path.insert(0, "/opt/zenoss/lib/python");
>>> import pymysql
>>> pymysql.install_as_MySQLdb()
>>> import MySQLdb
>>> self.conn = MySQLdb.connect(host="2001:db8:81:2c::2", port=3306, db='', user='zenoss', passwd='password')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/zenoss/lib/python/pymysql/__init__.py", line 93, in Connect
return Connection(*args, **kwargs)
File "/opt/zenoss/lib/python/pymysql/connections.py", line 504, in __init__
self._connect()
File "/opt/zenoss/lib/python/pymysql/connections.py", line 673, in _connect
raise OperationalError(2003, "Can't connect to MySQL server on %r (%s)" % (self.host, e.args[0]))
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '2001:db8:81:2c::2' (-9)")
connections.py
在那附近检查时,我惊骇地发现它试图打开一个AF_INET
套接字,并且没有代码可以打开AF_INET6
套接字。繁荣,瞬间失败。
当前版本的pymysql
似乎也包含这种缺陷。没有IPv6支持。
因此,“答案”将是我必须解决的pymysql
。不是我想度过的下午。
这种令人讨厌的黑客技术可以使事情正常进行(尽管您需要Python 2.6)。打开/opt/zenoss/lib/python/pymysql/connections.py
并搜索AF_INET
660行附近的内容。然后进行以下更改:
if DEBUG: print 'connected using unix_socket'
else:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- t = sock.gettimeout()
- sock.settimeout(self.connect_timeout)
- sock.connect((self.host, self.port))
- sock.settimeout(t)
+ sock = socket.create_connection((self.host, self.port), self.connect_timeout)
self.host_info = "socket %s:%d" % (self.host, self.port)
if DEBUG: print 'connected using socket'
此后已在上游pymysql中修复,并且应该在将来的版本中可用。