SNMP::walk

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

SNMP::walkFetch SNMP object subtree

Beschreibung

public SNMP::walk(
    array|string $objectId,
    bool $suffixAsKey = false,
    int $maxRepetitions = -1,
    int $nonRepeaters = -1
): array|false

SNMP::walk() is used to read SNMP subtree rooted at specified objectId.

Parameter-Liste

objectId

Root of subtree to be fetched

suffixAsKey

By default full OID notation is used for keys in output array. If set to true subtree prefix will be removed from keys leaving only suffix of object_id.

nonRepeaters

This specifies the number of supplied variables that should not be iterated over. The default is to use this value from SNMP object.

maxRepetitions

This specifies the maximum number of iterations over the repeating variables. The default is to use this value from SNMP object.

Rückgabewerte

Returns an associative array of the SNMP object ids and their values on success or false on error. When a SNMP error occures SNMP::getErrno() and SNMP::getError() can be used for retrieving error number (specific to SNMP extension, see class constants) and error message respectively.

Fehler/Exceptions

Diese Methode löst standardmäßig keine Exceptions aus. Um das Auslösen einer SNMPException-Exception beim Auftreten bestimmter Bibliotheksfehler zu aktivieren, muss muss der SNMP-Klassenparameter exceptions_enabled auf einen entsprechenden Wert gesetzt werden. Siehe SNMP::$exceptions_enabled explanation für weitere Details.

Beispiele

Beispiel #1 SNMP::walk() example

<?php
  $session 
= new SNMP(SNMP::VERSION_1"127.0.0.1""public");
  
$fulltree $session->walk(".");
  
print_r($fulltree);
  
$session->close();
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

Array
(
    [SNMPv2-MIB::sysDescr.0] => STRING: Test server
    [SNMPv2-MIB::sysObjectID.0] => OID: NET-SNMP-MIB::netSnmpAgentOIDs.8
    [DISMAN-EVENT-MIB::sysUpTimeInstance] => Timeticks: (1150681750) 133 days, 4:20:17.50
    [SNMPv2-MIB::sysContact.0] => STRING: Nobody
    [SNMPv2-MIB::sysName.0] => STRING: server.localdomain
    ...
)

Beispiel #2 suffixAsKey example

suffixAsKey may be used when merging multiple SNMP subtrees into one. This example maps interface names to their type.

<?php
  $session 
= new SNMP(SNMP::VERSION_1"127.0.0.1""public");
  
$session->valueretrieval SNMP_VALUE_PLAIN;
  
$ifDescr $session->walk(".1.3.6.1.2.1.2.2.1.2"TRUE);
  
$session->valueretrieval SNMP_VALUE_LIBRARY;
  
$ifType $session->walk(".1.3.6.1.2.1.2.2.1.3"TRUE);
  
print_r($ifDescr);
  
print_r($ifType);
  
$result = array();
  foreach(
$ifDescr as $i => $n) {
    
$result[$n] = $ifType[$i];
  }
  
print_r($result);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

Array
(
    [1] => igb0
    [2] => igb1
    [3] => ipfw0
    [4] => lo0
    [5] => lagg0
)
Array
(
    [1] => INTEGER: ieee8023adLag(161)
    [2] => INTEGER: ieee8023adLag(161)
    [3] => INTEGER: ethernetCsmacd(6)
    [4] => INTEGER: softwareLoopback(24)
    [5] => INTEGER: ethernetCsmacd(6)
)
Array
(
    [igb0] => INTEGER: ieee8023adLag(161)
    [igb1] => INTEGER: ieee8023adLag(161)
    [ipfw0] => INTEGER: ethernetCsmacd(6)
    [lo0] => INTEGER: softwareLoopback(24)
    [lagg0] => INTEGER: ethernetCsmacd(6)
)

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Art der Steuerung / Navigation auf der Seite

Auf der Suche nach Online-Casino-Boni bietet Wheelz Casino (https://wheelzcasino-win.com) eine großartige Gelegenheit, verschiedene Strategien un ...

Geschrieben von retav83729 am 23.05.2024 21:07:52
Forum: PHP Developer Forum
Seltsames Verhalten von execute() oder Fehler meinerseits

Hello You can check below steps - Check for errors after executing the statement. Bind parameters to placeholders in the SQL query. Confirm t ...

Geschrieben von nolanmaris am 20.05.2024 12:12:16
Forum: SQL / Datenbanken
Ein Problem mit der Lampe

Yes ..i was facing the same issue .

Geschrieben von nolanmaris am 20.05.2024 12:02:55
Forum: Off-Topic Diskussionen
Hello

Hello , I am new member here. I have around 8years of experience in developing User Interfaces for Mobile/Tablet/Desktop using HTML, CSS, JavaScri ...

Geschrieben von nolanmaris am 20.05.2024 12:01:22
Forum: User stellen sich vor