SNMP

目次

SNMP クラス

はじめに

SNMP セッションを表します。

クラス概要

SNMP
/* 定数 */
public const int SNMP::VERSION_1;
public const int SNMP::VERSION_2c;
public const int SNMP::VERSION_2C;
public const int SNMP::VERSION_3;
public const int SNMP::ERRNO_NOERROR;
public const int SNMP::ERRNO_ANY;
public const int SNMP::ERRNO_GENERIC;
public const int SNMP::ERRNO_TIMEOUT;
public const int SNMP::ERRNO_ERROR_IN_REPLY;
public const int SNMP::ERRNO_OID_NOT_INCREASING;
public const int SNMP::ERRNO_OID_PARSING_ERROR;
public const int SNMP::ERRNO_MULTIPLE_SET_QUERIES;
/* プロパティ */
public readonly array $info;
public intnull $max_oids;
public int $valueretrieval;
public bool $quick_print;
public bool $enum_print;
public int $oid_output_format;
public bool $oid_increasing_check;
public int $exceptions_enabled;
/* メソッド */
public __construct(
    int $version,
    string $hostname,
    string $community,
    int $timeout = -1,
    int $retries = -1
)
public bool close()
public mixed get(arraystring $objectId, bool $preserveKeys = false)
public int getErrno()
public string getError()
public mixed getnext(arraystring $objectId)
public bool set(arraystring $objectId, arraystring $type, arraystring $value)
public bool setSecurity(
    string $securityLevel,
    string $authProtocol = "",
    string $authPassphrase = "",
    string $privacyProtocol = "",
    string $privacyPassphrase = "",
    string $contextName = "",
    string $contextEngineId = ""
)
public arrayfalse walk(
    arraystring $objectId,
    bool $suffixAsKey = false,
    int $maxRepetitions = -1,
    int $nonRepeaters = -1
)

プロパティ

max_oids

GET/SET/GETBULK リクエスト単位の最大の OID

valueretrieval

SNMP の値を返す方法

SNMP_VALUE_LIBRARYNet-SNMP ライブラリの返す値を返します。
SNMP_VALUE_PLAINSNMP 型情報を含まないプレーンな値を返します。
SNMP_VALUE_OBJECT オブジェクトを返します。このオブジェクトはプロパティ "value" および "type" を持ち、後者のプロパティの値は SNMP_OCTET_STR, SNMP_COUNTER などの定数となります。 "value" の中身は SNMP_VALUE_LIBRARYSNMP_VALUE_PLAIN のどちらが設定されているかによって変わります。
quick_print

NET-SNMP ライブラリ内の quick_print の値

NET-SNMP ライブラリ内の quick_print の値を指定します。 これを (1 に) 設定すると、SNMP ライブラリは「手早く表示」した値を返します。 つまり、単なる値だけを表示するということです。quick_print を有効にしなければ (デフォルト)、NET-SNMP ライブラリは追加情報 (値の型、たとえば IpAddress や OID) も表示します。 さらに、quick_print が有効でない場合は、三文字以下のすべての文字列に対して追加の十六進値を表示します。

enum_print

enum 値の表示方法

walk や get などが、自動的に MIB 内の enum 値の元をたどって その値も可読形式の文字列にするかどうかを設定します。

oid_output_format

OID の出力フォーマットの制御

oid_output_format の値による、OID .1.3.6.1.2.1.1.3.0 の表示方法の変化
SNMP_OID_OUTPUT_FULL.iso.org.dod.internet.mgmt.mib-2.system.sysUpTime.sysUpTimeInstance
SNMP_OID_OUTPUT_NUMERIC.1.3.6.1.2.1.1.3.0
SNMP_OID_OUTPUT_MODULEDISMAN-EVENT-MIB::sysUpTimeInstance
SNMP_OID_OUTPUT_SUFFIXsysUpTimeInstance
SNMP_OID_OUTPUT_UCDsystem.sysUpTime.sysUpTimeInstance
SNMP_OID_OUTPUT_NONEUndefined
oid_increasing_check

OID ツリーを走査中の OID 増加チェックの無効化

SNMP エージェントの中には、 OID を返す順番がおかしくても走査はできるというものがあります。 それ以外のエージェントの場合、OID を返す順番がおかしくなると SNMP::walk が無限ループになり、 メモリを食いつぶしてしまいます。PHP の SNMP ライブラリは、 デフォルトで OID の増加チェックを行い、もし OID ツリーの走査中に OID が増加しないパターンがあればそこで走査を終了します。 oid_increasing_checkfalse にすると、このチェックが無効になります。

exceptions_enabled

警告ではなく SNMPException を発生させるのがどの失敗なのかを設定します。 Use bitwise OR'ed SNMP::ERRNO_* constants. By default all SNMP exceptions are disabled.

info

読み込み専用のプロパティで、リモートエージェントの設定を表します。 ホスト名やポート、デフォルトのタイムアウト、デフォルトの再試行回数を含みます。

定義済み定数

SNMP エラー型

SNMP::ERRNO_NOERROR

SNMP に関するエラーは発生していません。

SNMP::ERRNO_GENERIC

SNMP のエラーが発生しました。

SNMP::ERRNO_TIMEOUT

SNMP エージェントへのリクエストがタイムアウトしました。

SNMP::ERRNO_ERROR_IN_REPLY

SNMP エージェントがエラーの応答を返しました。

SNMP::ERRNO_OID_NOT_INCREASING

SNMP エージェントが、(BULK)WALK コマンドの実行中に前の OID から増加していない OID に当たりました。 リモート SNMP エージェントが偽物である可能性があります。

SNMP::ERRNO_OID_PARSING_ERROR

OID (や SET コマンドの型) のパースに失敗しました。 クエリは作成されませんでした。

SNMP::ERRNO_MULTIPLE_SET_QUERIES

要求された SET 操作で複数のクエリを使います。 この操作はトランザクション内の操作ではないので、 二番目以降のクエリに型や値の問題があれば失敗するかもしれません。

SNMP::ERRNO_ANY

すべての SNMP::ERRNO_* コードをビット OR したもの。

SNMP プロトコルバージョン

SNMP::VERSION_1

SNMP::VERSION_2C, SNMP::VERSION_2c

SNMP::VERSION_3

SNMPException クラス

はじめに

SNMP で発生するエラーを表します。自分のコードから SNMPException をスローしてはいけません。 PHP における例外処理の詳細な情報は 例外 を参照ください。

クラス概要

SNMPException
extends RuntimeException
/* 継承したプロパティ */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private Throwablenull $previous = null;
/* 継承したメソッド */
public Exception::__construct(string $message = "", int $code = 0, Throwablenull $previous = null)
final public string Exception::getMessage()
final public Throwablenull Exception::getPrevious()
final public int Exception::getCode()
final public string Exception::getFile()
final public int Exception::getLine()
final public array Exception::getTrace()
final public string Exception::getTraceAsString()
public string Exception::__toString()
private void Exception::__clone()

プロパティ

code

SNMP ライブラリのエラーコード。Exception::getCode でアクセスします。