PHP SNMP - 找不到模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16467712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:11:07  来源:igfitidea点击:

PHP SNMP - Cannot find module

phpapachesnmp

提问by PLui

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:

我已经启用了 SNMP 模块,尝试使用模块中的功能。我已将 MIBDIRS 环境变量设置为我拥有 mib 的位置,但我仍然收到这些“找不到模块”警告:

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.

我在 Windows 上。

采纳答案by PLui

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

显然,您可以设置 2 个环境变量。一个是MIBDIRS所有 MIB 文件所在的位置。另一个是MIBS,我相信这是您要加载的 SNMP 模块。通过设置MIBSALL,我能够摆脱错误。

回答by marcus

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

我在使用 php7.1 的 Ubuntu 中遇到了同样的问题,解决方案是安装 snmp 包

apt-get install snmp

回答by Wesley Schleumer de Góes

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

打开您的php.ini并在如下所示的行中添加一些神奇的分号:

extension=php_snmp.dll

It should look like:

它应该看起来像:

;extension=php_snmp.dll

回答by Robin

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

php包不包含mibs文件夹,你需要做的是下载net-snmp的源文件并将文件夹复制到你的php目录中

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

下载链接 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

之后,解压 zip 文件并将 mibs 文件夹复制到您的 php 目录

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

例如,将其复制到 C:\PHP\Extras\mibs
然后添加一个名为 MIBDIRS 的新系统变量。它的值应该是:C:\PHP\Extras\mibs

Finally, you can run php -m

最后,你可以运行 php -m

and you issue will be resoved

您的问题将得到解决

I attach a screenshot for your reference.enter image description here

我附上截图供您参考。在此处输入图片说明

回答by tc0nn

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

在 linux 上,我可以通过将其添加到我的 /etc/php5/apache2/conf.d/snmp.ini 文件来修复这些问题。

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

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

回答by Teddy

I just fixed it on my machine here by adding

我只是通过添加将它固定在我的机器上

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

to /etc/snmp/snmp.conf.

/etc/snmp/snmp.conf

回答by Aayush Bhardwaj

Faced a similar problem but in Ubuntu -

面临类似的问题,但在 Ubuntu 中 -

In /etc/snmp/snmp.conf -

在 /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 .

所以,注释掉这个文件中的 mibs 行就解决了。

回答by Gendalph

Stumbled upon this migrating older Cacti to Ubuntu 16.

偶然发现将旧的 Cacti 迁移到 Ubuntu 16。

In Ubuntu/Debian package php-snmpdepends 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.

在 Ubuntu/Debian 软件包中,php-snmp依赖于php7.0-snmp,它们都没有附带 MIB 或依赖于snmp-mibs-downloader,因此 SNMP 模块最终被废弃,没有可用的 MIB。

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 mibdirsin /etc/php/x.x/mods-available/snmp.iniand/or manually load required MIBs (loading everything via mibs = ALLwould work, but I consider it bad practice).

您应该做的是安装snmp-mibs-downloader(或等效的)并让它下载所有可用的 MIB,看看是否有帮助。如果没有,你可能需要调整mibdirs/etc/php/x.x/mods-available/snmp.ini和/或手动加载所需的MIB(装载一切通过mibs = ALL将工作,但我认为这是不好的做法)。

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

如果没有可用的下载器,请遵循@Robin 的建议并从Net-SNMP获取 MIB