新人求助windows下netsnmp怎么连接Python

2025-02-24 23:23:48
推荐回答(1个)
回答1:

由于需要练手,准备将nagios的bash shell/perl监控脚本改用python写,而监控机上yum安装的net-snmp默认没有启用python模块,这里重新编译安装一个。

需要准备的安装包包括:

setuptools-0.6c11-py2.4.egg    //提供easy_install指令用来直接在线安装python模块,类似于perl的 cpan install;

net-snmp-5.7.2.tar.gz             //net-snmp的源码包。

先安装setuptools-0.6c11-py2.4.egg,否则net-snmp编译安装无法通过。

#chmod 755 setuptools-0.6c11-py2.4.egg

#./setuptools-0.6c11-py2.4.egg

接着,安装net-snmp

#tar -zxvf net-snmp-5.7.2.tar.gz

#cd net-snmp-5.7.2

#./configure --prefix=/usr/local/netsnmp --with-python-modules

#make

#make install

#cd python

#python setup.py build

#python setup.py test    

出现以下错误:

ImportError: libnetsnmp.so.30: cannot open shared object file: No such file or directory

由于net-snmp是编译安装,且安装路径为/usr/local/netsnmp,以至于找不到相应模块,解决方法:

#echo "/usr/local/netsnmp/lib" >> /etc/ld.so.conf

#ldconfig

#python setup.py test//出现类似下图内容即正常:

#python setup.py install

测试net-snmp的python模块的导入:

#python

>>>import netsnmp //如果没有报错的话,则net-snmp的python模块启用成功。