mirror of
https://github.com/php/php-src.git
synced 2024-12-19 23:11:42 +08:00
move SNMP VERSION constants into SNMP class itself
This commit is contained in:
parent
0db6d3b16c
commit
edd80c571d
@ -2385,10 +2385,10 @@ PHP_MINIT_FUNCTION(snmp)
|
||||
REGISTER_LONG_CONSTANT("SNMP_INTEGER", ASN_INTEGER, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("SNMP_COUNTER64", ASN_COUNTER64, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("SNMP_VERSION_1", SNMP_VERSION_1, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("SNMP_VERSION_2c", SNMP_VERSION_2c, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("SNMP_VERSION_2C", SNMP_VERSION_2c, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("SNMP_VERSION_3", SNMP_VERSION_3, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_SNMP_CLASS_CONST_LONG("VERSION_1", (long)SNMP_VERSION_1);
|
||||
REGISTER_SNMP_CLASS_CONST_LONG("VERSION_2c", (long)SNMP_VERSION_2c);
|
||||
REGISTER_SNMP_CLASS_CONST_LONG("VERSION_2C", (long)SNMP_VERSION_2c);
|
||||
REGISTER_SNMP_CLASS_CONST_LONG("VERSION_3", (long)SNMP_VERSION_3);
|
||||
|
||||
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_NOERROR", (long)PHP_SNMP_ERRNO_NOERROR);
|
||||
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_GENERIC", (long)PHP_SNMP_ERRNO_GENERIC);
|
||||
|
@ -17,27 +17,27 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
|
||||
snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
|
||||
|
||||
echo "SNMP::ERRNO_NOERROR\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->getErrno() == SNMP::ERRNO_NOERROR);
|
||||
var_dump($session->getError());
|
||||
$session->close();
|
||||
|
||||
echo "SNMP::ERRNO_TIMEOUT\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, 'timeout_community_432', $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, 'timeout_community_432', $timeout, $retries);
|
||||
$session->valueretrieval = SNMP_VALUE_LIBRARY;
|
||||
var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->getErrno() == SNMP::ERRNO_TIMEOUT);
|
||||
var_dump($session->getError());
|
||||
$session->close();
|
||||
echo "SNMP::ERRNO_ERROR_IN_REPLY\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
var_dump(@$session->get('.1.3.6.1.2.1.1.1.110'));
|
||||
var_dump($session->getErrno() == SNMP::ERRNO_ERROR_IN_REPLY);
|
||||
var_dump($session->getError());
|
||||
$session->close();
|
||||
echo "SNMP::ERRNO_GENERIC\n";
|
||||
$session = new SNMP(SNMP_VERSION_3, $hostname, 'somebogususer', $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_3, $hostname, 'somebogususer', $timeout, $retries);
|
||||
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
|
||||
var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->getErrno() == SNMP::ERRNO_GENERIC);
|
||||
|
@ -15,17 +15,17 @@ snmp_set_quick_print(false);
|
||||
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
|
||||
|
||||
try {
|
||||
var_dump(new SNMP(SNMP_VERSION_1, $hostname));
|
||||
var_dump(new SNMP(SNMP::VERSION_1, $hostname));
|
||||
} catch (Exception $e) {
|
||||
print $e->getMessage() . "\n";
|
||||
}
|
||||
try {
|
||||
var_dump(new SNMP(SNMP_VERSION_1, $hostname, $community, ''));
|
||||
var_dump(new SNMP(SNMP::VERSION_1, $hostname, $community, ''));
|
||||
} catch (Exception $e) {
|
||||
print $e->getMessage() . "\n";
|
||||
}
|
||||
try {
|
||||
var_dump(new SNMP(SNMP_VERSION_1, $hostname, $community, $timeout, ''));
|
||||
var_dump(new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, ''));
|
||||
} catch (Exception $e) {
|
||||
print $e->getMessage() . "\n";
|
||||
}
|
||||
@ -36,7 +36,7 @@ var_dump(new SNMP(7, $hostname, $community));
|
||||
}
|
||||
|
||||
echo "Open normal session\n";
|
||||
$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||
$session->valueretrieval = 67;
|
||||
var_dump($session->valueretrieval);
|
||||
echo "Closing session\n";
|
||||
@ -45,7 +45,7 @@ var_dump($session->close());
|
||||
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->close());
|
||||
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
var_dump($session->walk('.1.3.6.1.2.1.1', FALSE, ''));
|
||||
var_dump($session->walk('.1.3.6.1.2.1.1', FALSE, 0, ''));
|
||||
var_dump($session->get());
|
||||
|
@ -18,7 +18,7 @@ snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
|
||||
|
||||
echo "Check working\n";
|
||||
|
||||
$session = new SNMP(SNMP_VERSION_1, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries);
|
||||
var_dump($session);
|
||||
|
||||
$session->max_oids = 40;
|
||||
|
@ -14,7 +14,7 @@ require_once(dirname(__FILE__).'/snmp_include.inc');
|
||||
snmp_set_quick_print(false);
|
||||
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
|
||||
|
||||
$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||
$session->setSecurity('noAuthNoPriv');
|
||||
|
||||
#echo "Checking error handling\n";
|
||||
|
@ -17,7 +17,7 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
|
||||
snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
|
||||
|
||||
echo "SNMPv1\n";
|
||||
$session = new SNMP(SNMP_VERSION_1, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries);
|
||||
$session->valueretrieval = SNMP_VALUE_LIBRARY;
|
||||
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->get(array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0')));
|
||||
@ -25,13 +25,13 @@ var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "SNMPv2\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "GET with preserving original OID names\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$orig = array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.5.0');
|
||||
$result = $session->get($orig, TRUE);
|
||||
foreach($orig as $oid){
|
||||
@ -40,7 +40,7 @@ foreach($orig as $oid){
|
||||
var_dump($session->close());
|
||||
|
||||
echo "WALK multiple on single OID\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$z = $session->walk('.1.3.6.1.2.1.1');
|
||||
var_dump(gettype($z));
|
||||
var_dump(count($z));
|
||||
@ -49,7 +49,7 @@ var_dump(array_shift($z));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "WALK multiple on single OID, non_repeaters set to 0\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$z = $session->walk('.1.3.6.1.2.1.1', 0);
|
||||
var_dump(gettype($z));
|
||||
var_dump(count($z));
|
||||
@ -58,7 +58,7 @@ var_dump(array_shift($z));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "WALK multiple on single OID, non_repeaters set to 0, max_repetitions set to 30\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$z = $session->walk('.1.3.6.1.2.1.1', 0, 30);
|
||||
var_dump(gettype($z));
|
||||
var_dump(count($z));
|
||||
@ -67,7 +67,7 @@ var_dump(array_shift($z));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "WALK multiple on single OID, max_oids set to 30\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session->max_oids = 30;
|
||||
$z = $session->walk('.1.3.6.1.2.1.1');
|
||||
var_dump(gettype($z));
|
||||
@ -77,7 +77,7 @@ var_dump(array_shift($z));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "WALK multiple on single OID with OID suffix as keys\n";
|
||||
$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||
$z = $session->walk('.1.3.6.1.2.1.1', TRUE);
|
||||
var_dump(gettype($z));
|
||||
var_dump(count($z));
|
||||
@ -86,21 +86,21 @@ var_dump(array_shift($z));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "SNMPv3 (default security settings)\n";
|
||||
$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||
#$session->setSecurity($user_noauth, 'noAuthNoPriv', '', '', '', '', '', '');
|
||||
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "SNMPv3 (noAuthNoPriv)\n";
|
||||
$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||
$session->setSecurity('noAuthNoPriv');
|
||||
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "SNMPv3 (authPriv)\n";
|
||||
$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
|
||||
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
|
||||
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
|
||||
@ -108,7 +108,7 @@ var_dump($session->walk('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "SET single OID\n";
|
||||
$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
|
||||
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
|
||||
$oid1 = 'SNMPv2-MIB::sysContact.0';
|
||||
$oldvalue1 = $session->get($oid1);
|
||||
@ -123,7 +123,7 @@ var_dump(($session->get($oid1) === $oldvalue1));
|
||||
var_dump($session->close());
|
||||
|
||||
echo "SNMPv3, setting contextEngineID (authPriv)\n";
|
||||
$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries);
|
||||
$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
|
||||
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '', 'aeeeff');
|
||||
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
|
||||
var_dump($session->close());
|
||||
|
Loading…
Reference in New Issue
Block a user