php-doc-en/functions/snmp.sgml
James Gingerich dfad3fd28c Add snmpset documentation (largely copied from snmpget).
Various other wording tweaks to the SNMP documentation.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@10610 c90b9560-bf6c-de11-be94-00142212c4b1
1999-07-13 20:41:26 +00:00

332 lines
11 KiB
Text

<reference id="ref.snmp">
<title>SNMP functions</title>
<titleabbrev>SNMP</titleabbrev>
<partintro>
<simpara>
In order to use the SNMP functions on Unix you need to install the <ulink
url="&url.ucd-snmp;">UCD SNMP</ulink> package. On Windows these functions
are only available on NT and not on Win95/98.
<simpara>
Important: In order to use the UCD SNMP package, you need to define
NO_ZEROLENGTH_COMMUNITY to 1 before compiling it. After configuring UCD
SNMP, edit config.h and search for NO_ZEROLENGTH_COMMUNITY. Uncomment the
#define line. It should look like this afterwards:
<para>
<programlisting>
#define NO_ZEROLENGTH_COMMUNITY 1
</programlisting>
</para>
<simpara>
If you see strange segmentation faults in combination with SNMP commands,
you did not follow the above instructions. If you do not want to recompile
UCD SNMP, you can compile PHP with the --enable-ucd-snmp-hack switch which
will work around the misfeature.
</partintro>
<refentry id="function.snmpget">
<refnamediv>
<refname>snmpget</refname>
<refpurpose>Fetch an SNMP object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>snmpget</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>string <parameter>community</parameter></paramdef>
<paramdef>string <parameter>object_id</parameter></paramdef>
<paramdef>int <parameter><optional>timeout</optional></parameter></paramdef>
<paramdef>int <parameter><optional>retries</optional></parameter></paramdef>
</funcsynopsis>
<para>
Returns SNMP object value on success and false on error.
<para>
The <function>snmpget</function> function is used to read the
value of an SNMP object specified by the
<parameter>object_id</parameter>. SNMP agent is specified by the
<parameter>hostname</parameter> and the read community is
specified by the <parameter>community</parameter> parameter.
<para>
<informalexample>
<literallayout>
$syscontact = snmpget("127.0.0.1", "public", "system.SysContact.0")
</literallayout>
</informalexample>
</refsect1>
</refentry>
<refentry id="function.snmpset">
<refnamediv>
<refname>snmpset</refname>
<refpurpose>Set an SNMP object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>snmpget</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>string <parameter>community</parameter></paramdef>
<paramdef>string <parameter>object_id</parameter></paramdef>
<paramdef>string <parameter>type</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
<paramdef>int <parameter><optional>timeout</optional></parameter></paramdef>
<paramdef>int <parameter><optional>retries</optional></parameter></paramdef>
</funcsynopsis>
<para>
Sets the specified SNMP object value, returning true on success
and false on error.
<para>
The <function>snmpset</function> function is used
to set the value of an SNMP object specified by the
<parameter>object_id</parameter>. SNMP agent is specified by the
<parameter>hostname</parameter> and the read community is specified
by the <parameter>community</parameter> parameter.
</refsect1>
</refentry>
<refentry id="function.snmpwalk">
<refnamediv>
<refname>snmpwalk</refname>
<refpurpose>Fetch all the SNMP objects from an agent</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>array <function>snmpwalk</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>string <parameter>community</parameter></paramdef>
<paramdef>string <parameter>object_id</parameter></paramdef>
<paramdef>int <parameter><optional>timeout</optional></parameter>
</paramdef>
<paramdef>int <parameter><optional>retries</optional></parameter>
</paramdef>
</funcsynopsis>
<para>
Returns an array of SNMP object values starting from the
<function>object_id</function> as root and false on error.
<para>
<function>snmpwalk</function> function is used to read all the
values from an SNMP agent specified by the
<parameter>hostname</parameter>. <parameter>Community</parameter>
specifies the read community for that agent. A null
<parameter>object_id</parameter> is taken as the root of the SNMP
objects tree and all objects under that tree are returned as an
array. If <parameter>object_id</parameter> is specified, all the
SNMP objects below that <parameter>object_id</parameter> are
returned.
<informalexample>
<programlisting role="php">
$a = snmpwalk("127.0.0.1", "public", "");
</programlisting>
</informalexample>
<para>
Above function call would return all the SNMP objects from the
SNMP agent running on localhost. One can step through the values
with a loop
<informalexample>
<programlisting role="php">
for ($i=0; $i&lt;count($a); $i++) {
echo $a[$i];
}
</programlisting>
</informalexample>
</refsect1>
</refentry>
<refentry id="function.snmpwalkoid">
<refnamediv>
<refname>snmpwalkoid</refname>
<refpurpose>Query for a tree of information about a network entity
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>array <function>snmpwalkoid</function></funcdef>
<paramdef>string <parameter>hostname</parameter></paramdef>
<paramdef>string <parameter>community</parameter></paramdef>
<paramdef>string <parameter>object_id</parameter></paramdef>
<paramdef>int <parameter><optional>timeout</optional></parameter>
</paramdef>
<paramdef>int <parameter><optional>retries</optional></parameter>
</paramdef>
</funcsynopsis>
<para>
Returns an associative array with object ids and their respective
object value starting from the <parameter>object_id</parameter>
as root and false on error.
<para>
<function>snmpwalkoid</function> function is used to read all
object ids and their respective values from an SNMP agent
specified by the hostname. Community specifies the read
<parameter>community</parameter> for that agent. A null
<parameter>object_id</parameter> is taken as the root of the SNMP
objects tree and all objects under that tree are returned as an
array. If <parameter>object_id</parameter> is specified, all the
SNMP objects below that <parameter>object_id</parameter> are
returned.
<para>
The existence of <function>snmpwalkoid</function> and
<function>snmpwalk</function> has historical reasons. Both
functions are provided for backward compatibility.
<informalexample>
<programlisting role="php">
$a = snmpwalkoid("127.0.0.1", "public", "");
</programlisting>
</informalexample>
<para>
Above function call would return all the SNMP objects from the
SNMP agent running on localhost. One can step through the values
with a loop
<informalexample>
<programlisting role="php">
for (reset($a); $i = key($a); next($a)) {
echo "$i: $a[$i]&lt;br>\n";
}
</programlisting>
</informalexample>
</refsect1>
</refentry>
<refentry id="function.snmp-get-quick-print">
<refnamediv>
<refname>snmp_get_quick_print</refname>
<refpurpose>Fetch the current value of the UCD library's quick_print setting
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>boolean <function>snmp_get_quick_print</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcsynopsis>
<para>
Returns the current value stored in the UCD Library for quick_print.
quick_print is off by default.
<informalexample>
<programlisting role="php">
$quickprint = snmp_get_quick_print();
</programlisting>
</informalexample>
<para>
Above function call would return <systemitem>false</systemitem> if
quick_print is on, and <systemitem>true</systemitem> if quick_print
is on.
<para>
<function>snmp_get_quick_print</function> is only available when using
the UCD SNMP library. This function is not available when using the
Windows SNMP library.
<para>
See: <function>snmp_set_quick_print</function> for a full description
of what quick_print does.
</refsect1>
</refentry>
<refentry id="function.snmp-set-quick-print">
<refnamediv>
<refname>snmp_set_quick_print</refname>
<refpurpose>Set the value of quick_print within the UCD SNMP library.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>snmp_set_quick_print</function></funcdef>
<paramdef>boolean <parameter>quick_print</parameter></paramdef>
</funcsynopsis>
<para>
Sets the value of quick_print within the UCD SNMP library. When this
is set (1), the SNMP library will return 'quick printed' values. This
means that just the value will be printed. When quick_print is not
enabled (default) the UCD SNMP library prints extra information
including the type of the value (i.e. IpAddress or OID). Additionally,
if quick_print is not enabled, the library prints additional hex values
for all strings of three characters or less.
<para>
Setting quick_print is often used when using the information returned
rather then displaying it.
<informalexample>
<programlisting role="php">
snmp_set_quick_print(0);
$a = snmpget("127.0.0.1", "public", ".1.3.6.1.2.1.2.2.1.9.1");
echo "$a&lt;BR>\n";
snmp_set_quick_print(1);
$a = snmpget("127.0.0.1", "public", ".1.3.6.1.2.1.2.2.1.9.1");
echo "$a&lt;BR>\n";
</programlisting>
</informalexample>
<para>
The first value printed might be: 'Timeticks: (0) 0:00:00.00', whereas
with quick_print enabled, just '0:00:00.00' would be printed.
<para>
By default the UCD SNMP library returns verbose values, quick_print is
used to return only the value.
<para>
Currently strings are still returned with extra quotes, this will be
corrected in a later release.
<para>
<function>snmp_set_quick_print</function> is only available when using
the UCD SNMP library. This function is not available when using
the Windows SNMP library.
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->