通过zabbix实现对数据库的监控,如ORACLE、MySQL、MSSQL、DB2……
3 篇帖子 分页: 1 / 1
帖子lipeng20004 » 2016年 2月 8日 14:19 星期一
在redhat linux6.5上使用zabbix2.4.4 和 pyora.py (python2.6.6环境) ,对oracle进行监控的过程中,使用python命令调用pyora.py?可以获取被监控数据库的信息;但是在zabbix2.4.4中的/etc/zabbix/zabbix_agentd.conf中定义key值:
UserParameter=pyora[*],/usr/bin/python /etc/zabbix/scripts/pyora.py --username $1 --password $2 --address $3 --database $4 $5 $6 $7 $8
,然后重启server和agent服务后,在使用zabbix_get 调用pyora.py获取oracle数据库的信息时,却报如下错误:

Traceback (most recent call last):

File "/home/zabbix/Pyora-master/pyora.py", line 10, in <module>
import cx_Oracle
ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory
?

详细的测试步骤和日志信息如下:


测试步骤1:

[zabbix@rac1 ~]$ zabbix_get -V

Zabbix get v2.4.4 (revision 52341) (23 February 2015)
Compilation time: Feb 24 2015 20:53:35

测试?步骤2:

[zabbix@rac1 ~]$ python /home/zabbix/Pyora-master/pyora.py --username zabbix --password zabbix --address 172.1.7.10 --database orcl show_users
{"data": [{"{#DBUSER}": "ANONYMOUS"}, {"{#DBUSER}": "APEX_030200"}, {"{#DBUSER}": "APEX_PUBLIC_USER"}, {"{#DBUSER}": "APPQOSSYS"}, {"{#DBUSER}": "CTXSYS"}, {"{#DBUSER}": "DBSNMP"}, {"{#DBUSER}": "DIP"}, {"{#DBUSER}": "EXFSYS"}, {"{#DBUSER}": "FLOWS_FILES"}, {"{#DBUSER}": "MDDATA"}, {"{#DBUSER}": "MDSYS"}, {"{#DBUSER}": "MGMT_VIEW"}, {"{#DBUSER}": "OLAPSYS"}, {"{#DBUSER}": "ORACLE_OCM"}, {"{#DBUSER}": "ORDDATA"}, {"{#DBUSER}": "ORDPLUGINS"}, {"{#DBUSER}": "ORDSYS"}, {"{#DBUSER}": "OUTLN"}, {"{#DBUSER}": "OWBSYS"}, {"{#DBUSER}": "OWBSYS_AUDIT"}, {"{#DBUSER}": "SCOTT"}, {"{#DBUSER}": "SI_INFORMTN_SCHEMA"}, {"{#DBUSER}": "SPATIAL_CSW_ADMIN_USR"}, {"{#DBUSER}": "SPATIAL_WFS_ADMIN_USR"}, {"{#DBUSER}": "SYS"}, {"{#DBUSER}": "SYSMAN"}, {"{#DBUSER}": "SYSTEM"}, {"{#DBUSER}": "WMSYS"}, {"{#DBUSER}": "XDB"}, {"{#DBUSER}": "XS$NULL"}, {"{#DBUSER}": "ZABBIX"}]}
[zabbix@rac1 ~]$

测试步骤3:

[zabbix@rac1 ~]$ zabbix_get -s 172.1.7.10 -k "pyora[zabbix,zabbix,172.1.7.10,orcl,version]"
Traceback (most recent call last):
File "/home/zabbix/Pyora-master/pyora.py", line 10, in <module>
import cx_Oracle
ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory
[zabbix@rac1 ~]$

测试步骤4:

[zabbix@rac1 ~]$ zabbix_get -s rac1 -k "pyora[zabbix,zabbix,172.1.7.10,orcl,version]"
Traceback (most recent call last):
File "/home/zabbix/Pyora-master/pyora.py", line 10, in <module>
import cx_Oracle
ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory


不知道有谁遇到过类似问题,或者 有成功的zabbix2.4.4 + pyora.py的成功环境,可以帮助比对环境的差异;能帮助解决问题,感激不尽,谢谢了!
帖子lipeng20004 » 2016年 2月 8日 14:24 星期一
针对上面,zabbix_get调用pyora.py 的报错,另外 尝试的测试结果,也报同样的错误。如下:

1. 在pyora.py中加入import sys,并sys.path.append增加lib库的搜索路径
import sys
print(sys.path)
sys.path.append("/opt/oracle/product/11.2.0/db_1/lib/")
sys.path.append("/opt/oracle/product/11.2.0/db_1/lib/libclntsh.so.11.1")
print(sys.path)

2. 然后执行的结果,报错ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory,见下面最后行。详细如下:
----2.1 python 直接调用pyora.py脚本
[zabbix@rac1 Pyora-master]$ python /home/zabbix/Pyora-master/pyora.py --username zabbix --password zabbix --address 172.1.7.10 --database orcl show_users

['/home/zabbix/Pyora-master', '/usr/lib/python2.6/site-packages/argparse-1.4.0-py2.6.egg', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info', '/opt/oracle/product/11.2.0/db_1/lib/', '/opt/oracle/product/11.2.0/db_1/lib/libclntsh.so.11.1', '/usr/lib/python2.6/site-packages/libclntsh.so.11.1']
{"data": [{"{#DBUSER}": "ANONYMOUS"}, {"{#DBUSER}": "APEX_030200"}, {"{#DBUSER}": "APEX_PUBLIC_USER"}, {"{#DBUSER}": "APPQOSSYS"}, {"{#DBUSER}": "CTXSYS"}, {"{#DBUSER}": "DBSNMP"}, {"{#DBUSER}": "DIP"}, {"{#DBUSER}": "EXFSYS"}, {"{#DBUSER}": "FLOWS_FILES"}, {"{#DBUSER}": "MDDATA"}, {"{#DBUSER}": "MDSYS"}, {"{#DBUSER}": "MGMT_VIEW"}, {"{#DBUSER}": "OLAPSYS"}, {"{#DBUSER}": "ORACLE_OCM"}, {"{#DBUSER}": "ORDDATA"}, {"{#DBUSER}": "ORDPLUGINS"}, {"{#DBUSER}": "ORDSYS"}, {"{#DBUSER}": "OUTLN"}, {"{#DBUSER}": "OWBSYS"}, {"{#DBUSER}": "OWBSYS_AUDIT"}, {"{#DBUSER}": "SCOTT"}, {"{#DBUSER}": "SI_INFORMTN_SCHEMA"}, {"{#DBUSER}": "SPATIAL_CSW_ADMIN_USR"}, {"{#DBUSER}": "SPATIAL_WFS_ADMIN_USR"}, {"{#DBUSER}": "SYS"}, {"{#DBUSER}": "SYSMAN"}, {"{#DBUSER}": "SYSTEM"}, {"{#DBUSER}": "WMSYS"}, {"{#DBUSER}": "XDB"}, {"{#DBUSER}": "XS$NULL"}, {"{#DBUSER}": "ZABBIX"}]}

----2.1 zabbix_get 调用其key定义中的pyora.py脚本
[zabbix@rac1 Pyora-master]$ zabbix_get -s 172.1.7.10 -k "pyora[zabbix,zabbix,172.1.7.10,orcl,version]"

['/home/zabbix/Pyora-master', '/usr/lib/python2.6/site-packages/argparse-1.4.0-py2.6.egg', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info', '/opt/oracle/product/11.2.0/db_1/lib/', '/opt/oracle/product/11.2.0/db_1/lib/libclntsh.so.11.1']
['/home/zabbix/Pyora-master', '/usr/lib/python2.6/site-packages/argparse-1.4.0-py2.6.egg', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info', '/opt/oracle/product/11.2.0/db_1/lib/', '/opt/oracle/product/11.2.0/db_1/lib/libclntsh.so.11.1', '/usr/lib/python2.6/site-packages/libclntsh.so.11.1']
Traceback (most recent call last):
File "/home/zabbix/Pyora-master/pyora.py", line 20, in <module>
import cx_Oracle
ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory
[zabbix@rac1 Pyora-master]$


能帮助解决问题,将感激不尽,谢谢!
帖子wenzi131 » 2016年 2月 16日 16:24 星期二
python我不是很懂,但用zabbix监控数据库建议使用dbforbix插件会事半功倍,可以简单配置就连接到oracle,有很多定义好的监控项目和模板,还可以自定义监控项目,我是oracle 的dba,现在用zabbix+dbforbix监控数据库方便很多
3 篇帖子 分页: 1 / 1

登录

在线用户

正在浏览此版面的用户:没有注册用户 和 2 位游客