PHP SNMP - Cannot find module

早过忘川 提交于 2019-12-18 04:43:13

问题


I've enabled the SNMP module was trying to the functions in the module. I have set the MIBDIRS environment variable to where I have my mibs but I'm still getting these "Cannot find module" warnings:

Cannot find module (IP-MIB): At line 0 in (none)
Cannot find module (IF-MIB): At line 0 in (none)
Cannot find module (TCP-MIB): At line 0 in (none)
Cannot find module (UDP-MIB): At line 0 in (none)
Cannot find module (HOST-RESOURCES-MIB): At line 0 in (none)
Cannot find module (SNMPv2-MIB): At line 0 in (none)
Cannot find module (SNMPv2-SMI): At line 0 in (none)
Cannot find module (NOTIFICATION-LOG-MIB): At line 0 in (none)
Cannot find module (UCD-SNMP-MIB): At line 0 in (none)
Cannot find module (UCD-DEMO-MIB): At line 0 in (none)
Cannot find module (SNMP-TARGET-MIB): At line 0 in (none)
Cannot find module (NET-SNMP-AGENT-MIB): At line 0 in (none)
Cannot find module (DISMAN-EVENT-MIB): At line 0 in (none)
Cannot find module (SNMP-VIEW-BASED-ACM-MIB): At line 0 in (none)
Cannot find module (SNMP-COMMUNITY-MIB): At line 0 in (none)
Cannot find module (UCD-DLMOD-MIB): At line 0 in (none)
Cannot find module (SNMP-FRAMEWORK-MIB): At line 0 in (none)
Cannot find module (SNMP-MPD-MIB): At line 0 in (none)
Cannot find module (SNMP-USER-BASED-SM-MIB): At line 0 in (none)
Cannot find module (SNMP-NOTIFICATION-MIB): At line 0 in (none)
Cannot find module (SNMPv2-TM): At line 0 in (none)

I know I have fixed this once but I can't seem to fix it again...what else can I try?

I'm on Windows.


回答1:


I've got the same problem in Ubuntu with php7.1 and the solution was installing snmp package

apt-get install snmp



回答2:


Apparently there are 2 environment variables you can set. One is MIBDIRS which is where all the MIB files are. Another is MIBS, which I believe is which SNMP modules you want to load. By setting MIBS to ALL, I was able to get rid of the errors.




回答3:


Open your php.ini and add some magical semicolon at line that look like:

extension=php_snmp.dll

It should look like:

;extension=php_snmp.dll



回答4:


On linux, I was able to fix these by adding this to my /etc/php5/apache2/conf.d/snmp.ini file.

mibdir=/usr/share/snmp/mibs
mibs=all




回答5:


The php package doesn't include mibs folder, what you have to do is download the source file of net-snmp and copy the folder into your php directory

download link https://sourceforge.net/projects/net-snmp/files/net-snmp/5.7.3/

after that, unzip the zip file and copy the mibs folder to your php directory

for exmaple,copy it to C:\PHP\Extras\mibs
Thne add a new system variable called MIBDIRS. Its value should be: C:\PHP\Extras\mibs

Finally, you can run php -m

and you issue will be resoved

I attach a screenshot for your reference.




回答6:


I just fixed it on my machine here by adding

mibdirs +/var/lib/mibs/iana:/var/lib/mibs/ietf

to /etc/snmp/snmp.conf.




回答7:


Faced a similar problem but in Ubuntu -

In /etc/snmp/snmp.conf -

# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loading them by commenting out the following line.
#mibs :

So , commenting out the mibs line in this file solved it .




回答8:


Stumbled upon this migrating older Cacti to Ubuntu 16.

In Ubuntu/Debian package php-snmp depends on php7.0-snmp, neither of which come with MIBs or depend on snmp-mibs-downloader, hence SNMP module ends up being defunct with no MIBs available.

What you should do is install snmp-mibs-downloader (or equivalent) and let it download all available MIBs and see if that helps. If it doesn't, you might need to adjust mibdirs in /etc/php/x.x/mods-available/snmp.ini and/or manually load required MIBs (loading everything via mibs = ALL would work, but I consider it bad practice).

If no downloader is available, follow @Robin's advice and get MIBs from Net-SNMP



来源:https://stackoverflow.com/questions/16467712/php-snmp-cannot-find-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!