Hướng dẫn dùng snmpget example trong PHP

(PHP 5, PHP 7, PHP 8)

snmp_read_mib Reads and parses a MIB file into the active MIB tree

Descripción

snmp_read_mib(string $filename): bool

The order in which the MIBs are loaded does matter as the underlying Net-SNMP library will print warnings if referenced objects cannot be resolved.

Parámetros

filename

The filename of the MIB.

Valores devueltos

Devuelve true en caso de éxito o false en caso de error.

Ejemplos

Ejemplo #1 Using snmp_read_mib()

 print_rsnmprealwalk('localhost''public''.1.3.6.1.2.1.2.3.4.5') );snmp_read_mib('./FOO-BAR-MIB.txt');
 
print_rsnmprealwalk('localhost''public''FOO-BAR-MIB::someTable') );
?>

The above example is made up but the results would look like:

     
Array
(
    [iso.3.6.1.2.1.2.3.4.5.0] => Gauge32: 6
)
Array
(
    [FOO-BAR-MIB::someTable.0] => Gauge32: 6
)

jdhall75 at yahoo dot com

14 years ago

If you are trying to import mibs with dependencies on other mibs you will have to set the MIBDIRS environment variable.

Unix / Linux: export MIBDIRS=/home//MIBS:/usr/share/snmp/mibs
Window: Good luck! No really.  Try this url out.  It has everything that you need to know about setting environment vars in windows.

http://vlaurie.com/computers2/Articles/environment.htm

ptitgal at hotmail dot com

16 years ago

Importing massive Mibs located in a directory
/******************** Loading Mibs **************/
$mib_path='YourPath';   
if (
$handle = opendir($mib_path))
{ echo
"Directory handle: $handle
"
;
    echo
"Files:
"
;
    while (
false !== ($file = readdir($handle)))
    { if(
$file!='.')
       { if(
$file!='..')
          { echo
"Read : ";       
            echo
"$mib_path.$file";
            if(
snmp_read_mib($mib_path.'\\'.$file)) echo " Succesful
"
;
            else echo
" Failed
"
;
         }
        }
    }
}
closedir($handle);?>

[PHP 5, PHP 7, PHP 8]

snmp_read_mib Reads and parses a MIB file into the active MIB tree

Descripción

snmp_read_mib[string $filename]: bool

The order in which the MIBs are loaded does matter as the underlying Net-SNMP library will print warnings if referenced objects cannot be resolved.

Parámetros

filename

The filename of the MIB.

Valores devueltos

Devuelve true en caso de éxito o false en caso de error.

Ejemplos

Ejemplo #1 Using snmp_read_mib[]

 print_rsnmprealwalk['localhost''public''.1.3.6.1.2.1.2.3.4.5'] ];snmp_read_mib['./FOO-BAR-MIB.txt'];
 
print_rsnmprealwalk['localhost''public''FOO-BAR-MIB::someTable'] ];
?>

The above example is made up but the results would look like:

Array [ [iso.3.6.1.2.1.2.3.4.5.0] => Gauge32: 6 ] Array [ [FOO-BAR-MIB::someTable.0] => Gauge32: 6 ]

jdhall75 at yahoo dot com

14 years ago

If you are trying to import mibs with dependencies on other mibs you will have to set the MIBDIRS environment variable.

Unix / Linux: export MIBDIRS=/home//MIBS:/usr/share/snmp/mibs
Window: Good luck! No really.  Try this url out.  It has everything that you need to know about setting environment vars in windows.

//vlaurie.com/computers2/Articles/environment.htm

ptitgal at hotmail dot com

16 years ago

Importing massive Mibs located in a directory
/******************** Loading Mibs **************/
$mib_path='YourPath';   
if [
$handle = opendir[$mib_path]]
{ echo
"Directory handle: $handle
"
;
    echo
"Files:
"
;
    while [
false !== [$file = readdir[$handle]]]
    { if[
$file!='.']
       { if[
$file!='..']
          { echo
"Read : ";       
            echo
"$mib_path.$file";
            if[
snmp_read_mib[$mib_path.'\\'.$file]] echo " Succesful
"
;
            else echo
" Failed
"
;
         }
        }
    }
}
closedir[$handle];?>