PHP.mk документација

snmpget

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.snmpget.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.snmpget.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
snmpget

Референца за `function.snmpget.php` со подобрена типографија и навигација.

function.snmpget.php

snmpget

(PHP 4, PHP 5, PHP 7, PHP 8)

snmpgetПреземи SNMP object

= NULL

snmpget(
         string $hostname,
         string $community,
         array|string $object_id,
         int $timeout = -1,
         int $retries = -1
): mixed

На snmpget() функцијата се користи за читање на вредноста на една SNMP објект специфициран од object_id.

Параметри

hostname
На SNMP agent.
community
агент (сервер).
object_id
На SNMP object.
timeout
ID на објект што му претходи на посакуваниот.
retries
Бројот на микросекунди до првиот тајмаут.

Вратени вредности

Патеката до PHP скриптата што треба да се провери. SNMP вредност на објектот при успех или false при грешка.

Примери

Пример #1 Користење snmpget()

<?php
$syscontact
= snmpget("127.0.0.1", "public", "system.SysContact.0");
?>

Види Исто така

  • snmpset() - Преземи го SNMP објектот што го следи дадениот id на објектот

Белешки од корисници 16 белешки

- Поставете ја вредноста на SNMP објект
пред 22 години
It seems that for each snmpget() its own socket() will be opened. This is not closed after snmpget() finishes. Neither existing sockets are reused by subsequent snmpget() calls.

When querying a few switches with lots of ports the maximum file descriptor count of Apache is exhausted. Thus no more snmpget() are possible. Additionaly no more files can be read by this particular Apache process. Neither the PHP file, any include files nor any other files (like a .css file, ...).

This probably explains the observation of tkjode at phalnet dot com. Different to his case is that I'm using Linux.
Јохан Глазер
yasuo_ohgaki at hotmail dot com
It looks like you can use a non-standard port for SNMP
with something like this:

$foo = snmpwalk('foo.bar.com:1161', 'foofoo', '.1.3.6');

This is on PHP 3.16; I haven't managed to get PHP 4.02 to compile successfully on Solaris 2.6 yet.
--Michael
grice at berbee dot com
пред 16 години
This function can be used to identify devices on a network, by getting their sysObjectID and sysDescr. On short, this is what I did:
<?php
   $sysid = @snmpget($ip, 'public', '.1.3.6.1.2.1.1.2.0', 300);
   if($sysid) {
      $sysdescr = @snmpget($ip, 'public', '.1.3.6.1.2.1.1.1.0', 300);
   }
?>

What I get for equipments, for example:
<?php
   $sysid = 'OID: .iso.3.6.1.4.1.5003.8.1.1.57';// => AudioCodes MP114;
   //.iso.3.6.1.4.1. is a "prefix" for the OID domain
   //5003 is the IANA number for AudioCodes
   //8.1.1.57 identifies the equipment type (MP-114)
   $sysdescr = '"Product: MP-114 FXS;SW Version: 5.00A.024"';
?>
Unfortunately, not all of them report correct objectID, for example they report only the vendor and stop there etc.

In case you are wondering why I used the code '.1.3.6.1.2.1.1.2.0' in the function call instead of "sysObjectID.0", it's because only numeric codes seem to work on Windows. For more codes, google "cisco SNMP Object Navigator".
Have fun.
maxie_ro at do dot not dot spam dot yahoo dot com
пред 17 години
For those wishing to use v2 or 3

you can consult the php_snmp.h header
here is the list of functions

PHP_FUNCTION(snmpget);
PHP_FUNCTION(snmpgetnext);
PHP_FUNCTION(snmpwalk);
PHP_FUNCTION(snmprealwalk);
PHP_FUNCTION(snmp_get_quick_print);
PHP_FUNCTION(snmp_set_quick_print);
PHP_FUNCTION(snmp_set_enum_print);
PHP_FUNCTION(snmp_set_oid_output_format);
PHP_FUNCTION(snmpset);

PHP_FUNCTION(snmp2_get);
PHP_FUNCTION(snmp2_getnext);
PHP_FUNCTION(snmp2_walk);
PHP_FUNCTION(snmp2_real_walk);
PHP_FUNCTION(snmp2_set);

PHP_FUNCTION(snmp3_get);
PHP_FUNCTION(snmp3_getnext);
PHP_FUNCTION(snmp3_walk);
PHP_FUNCTION(snmp3_real_walk);
PHP_FUNCTION(snmp3_set);

PHP_FUNCTION(snmp_set_valueretrieval);
PHP_FUNCTION(snmp_get_valueretrieval);
d dot shereck at gmail dot com
пред 18 години
The online documentation says that the function returns "FALSE" on error but, actually, it returns NULL on error.
Едуардо
пред 18 години
Some SNMP agents return mac addresses as hex encoded ascii.

e.g. '30:30:3a:31:37:3a:66:32:3a:39:62:3a:34:36:3a:30:65'

Each octet represents 4 bits of the mac address.
Some vendors may also encode the separators into the string.

Heres a function to convert these strings back into plain hex.

<?php
$hexStr = '30:30:3a:31:37:3a:66:32:3a:39:62:3a:34:36:3a:30:65';

echo(str_replace(':','',hexStr2Ascii($hexStr)));

function hexStr2Ascii($hexStr,$separator = ':'){
    $hexStrArr = explode($separator,$hexStr);
    $asciiOut = null;
    foreach($hexStrArr as $octet){
        $asciiOut .= chr(hexdec($octet));
    }
    return $asciiOut;
}
?>

Outputs: '0017f29b460e'
ac221 at sussex dot ac dot uk
пред 18 години
When I try to get a 64 bit counter variable (e.g. ifHCInOctets) using snmpget function, following error message was appeared.

Error in packet: (noSuchName) There is no such variable name in this MIB

The solution for this is to use snmp2_get(); function. The prameters are same as snmpget();
Малака Удавата (malaka13 at gmail dot com)
19 години пред
I have no idea what the timeout value is, but 1 second is really really 1 000 000 000 nano seconds (cf. http://en.wikipedia.org/wiki/SI_prefix).
michael dot mauch at gmx dot de
19 години пред
Unfortunately, It appears that you can not put multiple objects into the snmpget function, ie: sysUpTime.0 ifInOctets.1 ifOutOctets.1.  For what it's worth, the time argument is in nano-seconds as previously mentioned.  There is a lot of conflicting information out there about this.
Џим
пред 22 години
pooling a cisco.

$ip = '1.1.1.1';
$community ='publico';
$a = snmpget($ip,$community, "IF-MIB::ifLastChange.1")
$b = snmpget($ip,$community, "IF-MIB::ifAlias.1");
print("a = ".$a."\n"."b = ".$b."\n");

a = Timeticks: (929969969) 107 days, 15:14:59.69
b = Timeticks: (929969969) 107 days, 15:14:59.69

when the interface has not description.
javierb at gmx dot net
figroc at gmail dot com
It has been observed on NT/2000 systems that flooding devices with SNMP requests will cause NT's SNMP service to stop working.

For example, I polled 183 switches on our network just fine.  I then attempted to simulate heavy traffic to that page by refreshing and breaking connections (as any real world system would have to go through).  SNMP stopped working throughout the entire machine, including non-PHP/Webserver processes.
tkjode at phalnet dot com
пред 18 години
According the SNMPv2-MIB DEFINITIONS the right syntax should be "system.sysContact.0" and NOT "system.SysContact.0" as used in the above example 2251. 

SNMPv2-MIB DEFINITIONS 
... 
sysContact OBJECT-TYPE 
SYNTAX DisplayString (SIZE (0..255)) 
MAX-ACCESS read-write 
STATUS current 
DESCRIPTION 
"The textual identification of the contact person for this 
managed node, together with information on how to contact 
this person. If no contact information is known, the 
value 
is the zero-length string." 
::= { system 4 }
brunoseys at telenet dot be
пред 22 години
Little tidbit for snmpget function

<?php
//snmpget system stats
$host = 'localhost';
$community = 'public';

//get system name
$sysname = snmpget($host, $community, "system.sysName.0");

//get system uptime
$sysup = snmpget($host, $community, "system.sysUpTime.0");
$sysupre = eregi_replace("([0-9]{3})","",$sysup);
$sysupre2 = eregi_replace("Timeticks:","",$sysupre);
$sysupre3 = eregi_replace("[()]","",$sysupre2);

//get tcp connections
$tcpcon = snmpget($host, $community,"tcp.tcpCurrEstab.0");
$tcpconre = eregi_replace("Gauge32:","",$tcpcon);

echo '
System Name: '.$sysname.'<br>
System Uptime: '.$sysupre3.'<br>
Current Tcp Connections: '.$tcpconre.'<br>';

?>
tridman
19 години пред
The timeout is in micro seconds. Thus 1.000.000 means 1 Second.
brunoseys at telenet dot be
20 години пред
2 year tidbit update :)

<?php
// author: dstjohn at mediacast1.com
// updated: 09-11-2005
// set some vars
$snmpcommunity = 'PUBLIC'; //snmp community name
$ips = 'test1.com,test2.com'; //ips or dns to get snmp data from
$system_number = '1';
//end da vars

//start da loop d loop
for ($i = 0; $i <= $system_number; $i++) {
$sysip = explode(",",$ips);

//get system name
$sysname[0] = snmpget($sysip[$i], $snmpcommunity, "sysName.0");
$sysname[1] = eregi_replace("STRING:","",$sysname[0]);
echo 'System Name: '.$sysname[1].'<br>';

//system description
$sysdesc[0] = snmpget($sysip[$i], $snmpcommunity, "sysDescr.0");
$sysdesc[1] = eregi_replace("STRING:","",$sysdesc[0]);
echo 'System Description: '.$sysdesc[1].'<br>';

//system location
$sysloc[0] = snmpget($sysip[$i], $snmpcommunity, "sysLocation.0");
$sysloc[1] = eregi_replace("STRING:","",$sysloc[0]);
echo 'System Location: '.$sysloc[1].'<br>';

//current tcp connections
$tcpcons[0] = snmpget($sysip[$i], $snmpcommunity, "tcpCurrEstab.0");
$tcpcons[1] = eregi_replace("Gauge32:","",$tcpcons[0]);
echo 'Open TCP/IP Connections: '.$tcpcons[1].'<br>';

//get system uptime
$sysuptime[0] = snmpget($sysip[$i], $snmpcommunity, "system.sysUpTime.0");
$sysuptime[1] = eregi_replace("Timeticks:","",$sysuptime[0]);
echo 'System Uptime: Timeticks -'.$sysuptime[1].'<br>';

//windows only
//installed memory
if(eregi('Windows',$sysdesc[1])){
$mem[0] = snmpget($sysip[$i], $snmpcommunity, "HOST-RESOURCES-MIB::hrMemorySize.0");
$mem[1] = eregi_replace("INTEGER:","",$mem[0]);
$mem[2] = eregi_replace("KBytes","",$mem[1]);
echo 'Insalled Memory: '.$mem[2].' KiloBytes<br>';
}

echo '<br><br>';
}//end loop

?>
fbleau
19 години пред
The default value of Timeout is 1000000  nanoseconde (1 sec) and the retrie is 5 thsi value is set by Net-SNMP library.

#!/usr/local/bin/php
<?php
 $time_start = microtime(true);
 $reponse = snmpget('10.5.1.1', 'public', "1.3.6.1.2.1.1.3.0",1000000,5);
 $time_end = microtime(true);
 $time = $time_end - $time_start;

 echo "Delay in $time secondes\n";
?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.