PHP: SNMP関数 - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<swf_viewportsnmp_get_quick_print>
view the version of this page
Last updated: Tue, 21 Dec 2004

CXII. SNMP関数

要件

UNIX上でSNMP関数を使用するためには、パッケージをインストールする必要があります。 Windows上では、これらの関数は NT 上でのみ利用可能であり、 Win95/98 では利用できません。

インストール手順

重要: UCD SNMP パッケージを使用するには、コンパイル前に NO_ZEROLENGTH_COMMUNITYを1に定義する必要があります。UCD SNMPのコン フィグレーションを行った後、config.hを編集し、 NO_ZEROLENGTH_COMMUNITY を探してください。 #define の行のコメントを外してください。 これにより、次のようになるはずです。
#define NO_ZEROLENGTH_COMMUNITY 1
Now compile PHP --with-snmp[=DIR].

SNMP コマンドと組み合わせた場合に奇妙なセグメント例外が生じる場合 は、上の指示に従っていないと思われます。UCD SNMPを再コンパイルした くない場合は、この不具合に対処するため、PHPを --enable-ucd-snmp-hack スイッチをつけてコンパイルしてください。

Windows版は、SNMPサポート用ファイルがmibsディレ クトリにあります。このディレクトリは、 directory. This directory should be moved to DRIVE:\usr\mibs, where DRIVE must be replaced with the driveletter where PHP is installed on, e.g.: c:\usr\mibs.

実行用の設定

この拡張モジュールは設定ディレクティブを全く定義しません。

定義済みの定数

この拡張モジュールは定数を全く定義しません。

目次
snmp_get_quick_print --  UCD ライブラリの quick_print の現在の設定値を取得する
snmp_get_valueretrieval --  Return the method how the SNMP values will be returned
snmp_read_mib --  Reads and parses a MIB file into the active MIB tree
snmp_set_enum_print --  Return all values that are enums with their enum value instead of the raw integer
snmp_set_oid_numeric_print --  Return all objects including their respective object id within the specified one
snmp_set_quick_print -- UCB SNMP ライブラリで quick_print の値を設定する
snmp_set_valueretrieval --  Specify the method how the SNMP values will be returned
snmpget -- SNMPオブジェクトを取得する
snmpgetnext --  Fetch a SNMP object
snmprealwalk --  指定したオブジェクトに関するオブジェクトIDを含む全てのオブジェク トを返す
snmpset -- SNMP オブジェクトを設定する
snmpwalk -- エージェントから全てのSNMPオブジェクトを取りだす
snmpwalkoid -- ネットワークエンティティに関する情報ツリーの検索


add a note add a note User Contributed Notes
SNMP関数
tom at tom420 dot cjb dot net
02-Sep-2004 07:52
As of Net-SNMP 5.1.2 the file config.h is now called acconfig.h. This is where you will find and uncomment the line
#define NO_ZEROLENGTH_COMMUNITY 1
as described in the manual above.

I've been looking for the file for about 20 minutes before I located it by the new name.
amit_gupta at users dot sourceforge dot net
16-Jul-2004 01:01
I was struggling to compile PHP 4.3.8/PHP-5 with net-snmp-5.1 RPMS .  It was continously showing errors during make. Later I first complied and installed net-snmp-5.1  on fedora system. With this compiled Net-snmp , I could install PHP 4.3.8/php5 successfully. So if you are also getting error during make command during installation of PHP, first compile net-snmp instaead of using its RPM.

Amit Gupta
peterd at nospam telephonetics co uk
15-Jun-2004 07:37
I've found that when using SNMP on Windows (2000 Pro) the drive the mib files have to be located on actually depends on where you subsequently call PHP from.

For example:
(Assume PHP is installed in c:\\php and the mibs are installed in c:\\usr\\mibs and you have a script c:\\test.php)
Open a command prompt at c:\\
Calling c:\\php\\cli\\php.exe c:\\test.php will work fine.
Change directory to d:\\
Execute c:\\php\\cli\\php.exe c:\\test.php will now cause an error about not finding mib files.

If you now copy the mibs to d:\\usr\\mibs and run the above command again, it will now work fine.

Effectively the drive the mibs has to be on is the same as the drive of the current working directory when you call PHP.

This isn't very useful at all, so after some digging around there seems to be an environment variable (MIBDIRS) you can set specifying where the MIBs are to be found.

After setting MIBDIRS=c:\\php\\mibs in the environment and placing the mibs there, everything seemed to work fine.

Note: If you need SNMP whilst using apache you may have to use the PassEnv command with MIBDIRS in your apache config, I haven't tried this yet.
Sean Boulter
09-Jun-2004 01:01
In addition to working on NT as the documentation says, SNMP works on XP if you have the snmp extensions enabled in the ph.ini file, point the ini file to the correct extensions folder, and copy the mibs from the full install package to c:\usr\mibs.
mcotner at mcotner dot com
25-Feb-2004 06:37
Hi all,
I had a need for mass polling of many devices and bulkgets were very desirable.  It turns out the change was simpler than I thought.

One word of warning, however.  The version is set in such a way that if I were to keep the changes to a minimum all operations that weren't v3 needed to be set to v2c.  This isn't a problem for us because we have no v1 specific devices.  If you're polling any v1 ONLY agents then you will have issues with this patch. 

Here's the patch.  I hope this helps.

Just save it to /tmp/patch
cd ext/snmp/
patch snmp.c /tmp/patch

'njoy,
Mark

--- snmp.c    2003-08-07 12:44:11.000000000 -0400
+++ /tmp/snmp.c    2004-02-24 22:03:22.000000000 -0500
@@ -405,7 +405,11 @@
                 RETURN_FALSE;
             }
         } else if (st >= 2) {
-            pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
+            int reps = 20, non_reps = 0;
+
+            pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
+            pdu->non_repeaters = non_reps;
+            pdu->max_repetitions = reps;    /* fill the packet */
             snmp_add_null_var(pdu, name, name_length);
         }
 
@@ -471,7 +475,7 @@
                             goto retry;
                         }
                     } else if (st >= 2) {
-                        if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) {
+                        if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETBULK)) != NULL) {
                             goto retry;
                         }
                     }
@@ -579,7 +583,7 @@
 
     session.peername = hostname;
     session.remote_port = remote_port;
-    session.version = SNMP_VERSION_1;
+    session.version = SNMP_VERSION_2c;
     /*
     * FIXME: potential memory leak
     * This is a workaround for an "artifact" (Mike Slifcak)
thug at wolf359 dot cjb dot net
22-Apr-2002 07:06
Just a quick note on PHP SNMP instalation on Windows machines (IIS 5.x / Win2k SP2 etc...)
I had installed PHP into C:\PHP.. (standard stuff eh?)

Whilst I had followed the instructions for the installation of SNMP (put php_snmp.dll in extension_dir, uncomment entry in php.ini and all mib files located on the same drive where php was installed  (in this case c:\usr\mibs right?) I still ran into trouble like "Cannot find module (IP-MIB): At line 0 in (none)..." appearing on the bottom of every php that page I was viewing which existed on a drive other than C:\ drive...

It seams that the mibs dir (and content thereof) have to be located on every volume where a php file will be executed from.

For example :-
If you have a php file as "C:\INETPUB\WWWROOT\snmp1.php" then the coresponding "C:\USR\MIBS\*.*" has to be present (as mentioned in the install.txt).

Now here comes the catch...

If you have a "D:\INETPUB\PHPROOT\snmp1.php" file, then a copy of the mib files have to be in "D:\USR\MIBS\*.*" as well (the same mib files that are on the C:\ drive and same basic location <drive>:\USR\MIBS).

(Or in short : Copy the C:\USR dir (inc mibs dir) to *every* drive you intend to have .php files accessed from.  Done!)

Hope this helps other PHParians.

Keep up the *Great* work!!!

<swf_viewportsnmp_get_quick_print>
 Last updated: Tue, 21 Dec 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: /
Last updated: Mon Mar 14 08:13:06 2005 Local time zone must be set--see zic manual page