Annotation of embedaddon/php/ext/snmp/tests/snmp-object.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--                                 
                      2: OO API
                      3: --CREDITS--
                      4: Boris Lytochkin
                      5: --SKIPIF--
                      6: <?php
                      7: require_once(dirname(__FILE__).'/skipif.inc');
                      8: ?>
                      9: --FILE--
                     10: <?php
                     11: require_once(dirname(__FILE__).'/snmp_include.inc');
                     12: 
                     13: //EXPECTF format is quickprint OFF
                     14: snmp_set_enum_print(false);
                     15: snmp_set_quick_print(false);
                     16: snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
                     17: snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
                     18: 
                     19: echo "SNMPv1\n";
                     20: $session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries);
                     21: $session->valueretrieval = SNMP_VALUE_LIBRARY;
                     22: var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
                     23: var_dump($session->get(array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0')));
                     24: var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
                     25: var_dump($session->close());
                     26: 
                     27: echo "SNMPv2\n";
                     28: $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
                     29: var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
                     30: var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
                     31: var_dump($session->close());
                     32: 
                     33: echo "GET with preserving original OID names\n";
                     34: $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
                     35: $orig = array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.5.0');
                     36: $result = $session->get($orig, TRUE);
                     37: foreach($orig as $oid){
                     38:        var_dump($result[$oid]);
                     39: }
                     40: var_dump($session->close());
                     41: 
                     42: echo "WALK multiple on single OID\n";
                     43: $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
                     44: $z = $session->walk('.1.3.6.1.2.1.1');
                     45: var_dump(gettype($z));
                     46: var_dump(count($z));
                     47: var_dump(key($z));
                     48: var_dump(array_shift($z));
                     49: var_dump($session->close());
                     50: 
                     51: echo "WALK multiple on single OID, max_repetitions set to 30\n";
                     52: $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
                     53: $z = $session->walk('.1.3.6.1.2.1.1', FALSE, 30);
                     54: var_dump(gettype($z));
                     55: var_dump(count($z));
                     56: var_dump(key($z));
                     57: var_dump(array_shift($z));
                     58: var_dump($session->close());
                     59: 
                     60: echo "WALK multiple on single OID, max_repetitions set to 30, non_repeaters set to 0\n";
                     61: $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
                     62: $z = $session->walk('.1.3.6.1.2.1.1', FALSE, 30, 0);
                     63: var_dump(gettype($z));
                     64: var_dump(count($z));
                     65: var_dump(key($z));
                     66: var_dump(array_shift($z));
                     67: var_dump($session->close());
                     68: 
                     69: echo "WALK multiple on single OID, max_oids set to 30\n";
                     70: $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
                     71: $session->max_oids = 30;
                     72: $z = $session->walk('.1.3.6.1.2.1.1');
                     73: var_dump(gettype($z));
                     74: var_dump(count($z));
                     75: var_dump(key($z));
                     76: var_dump(array_shift($z));
                     77: var_dump($session->close());
                     78: 
                     79: echo "WALK multiple on single OID with OID suffix as keys\n";
                     80: $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
                     81: $z = $session->walk('.1.3.6.1.2.1.1', TRUE);
                     82: var_dump(gettype($z));
                     83: var_dump(count($z));
                     84: var_dump(key($z));
                     85: var_dump(array_shift($z));
                     86: var_dump($session->close());
                     87: 
                     88: echo "SNMPv3 (default security settings)\n";
                     89: $session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
                     90: #$session->setSecurity($user_noauth, 'noAuthNoPriv', '', '', '', '', '', '');
                     91: var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
                     92: var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
                     93: var_dump($session->close());
                     94: 
                     95: echo "SNMPv3 (noAuthNoPriv)\n";
                     96: $session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
                     97: $session->setSecurity('noAuthNoPriv');
                     98: var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
                     99: var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
                    100: var_dump($session->close());
                    101: 
                    102: echo "SNMPv3 (authPriv)\n";
                    103: $session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
                    104: $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
                    105: var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
                    106: var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
                    107: var_dump($session->walk('.1.3.6.1.2.1.1.1.0'));
                    108: var_dump($session->close());
                    109: 
                    110: echo "SET single OID\n";
                    111: $session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
                    112: $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
                    113: $oid1 = 'SNMPv2-MIB::sysContact.0';
                    114: $oldvalue1 = $session->get($oid1);
                    115: $newvalue1 = $oldvalue1 . '0';
                    116: 
                    117: $z = $session->set($oid1, 's', $newvalue1);
                    118: var_dump($z);
                    119: var_dump(($session->get($oid1) === $newvalue1));
                    120: $z = $session->set($oid1, 's', $oldvalue1);
                    121: var_dump($z);
                    122: var_dump(($session->get($oid1) === $oldvalue1));
                    123: var_dump($session->close());
                    124: 
                    125: echo "Multiple OID with max_oids = 1\n";
                    126: $oid2 = 'SNMPv2-MIB::sysLocation.0';
                    127: $session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
                    128: $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
                    129: $session->max_oids = 1;
                    130: $oldvalue2 = $session->get($oid2);
                    131: $newvalue2 = $oldvalue2 . '0';
                    132: $z = $session->set(array($oid1, $oid2), array('s','s'), array($newvalue1, $newvalue2));
                    133: var_dump($z);
                    134: var_dump(($session->get($oid1) === $newvalue1));
                    135: var_dump(($session->get($oid2) === $newvalue2));
                    136: $z = $session->set(array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2));
                    137: var_dump($z);
                    138: var_dump(($session->get($oid1) === $oldvalue1));
                    139: var_dump(($session->get($oid2) === $oldvalue2));
                    140: var_dump($session->close());
                    141: 
                    142: echo "SNMPv3, setting contextEngineID (authPriv)\n";
                    143: $session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
                    144: $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '', 'aeeeff');
                    145: var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
                    146: var_dump($session->close());
                    147: 
                    148: ?>
                    149: --EXPECTF--
                    150: SNMPv1
                    151: string(%d) "%S"
                    152: array(2) {
                    153:   ["%s"]=>
                    154:   string(%d) "%S"
                    155:   ["%s"]=>
                    156:   string(%d) "%S"
                    157: }
                    158: string(%d) "%S"
                    159: bool(true)
                    160: SNMPv2
                    161: string(%d) "%S"
                    162: string(%d) "%S"
                    163: bool(true)
                    164: GET with preserving original OID names
                    165: string(%d) "%s"
                    166: string(%d) "%s"
                    167: bool(true)
                    168: WALK multiple on single OID
                    169: string(5) "array"
                    170: int(%d)
                    171: string(%d) "%S"
                    172: string(%d) "%S"
                    173: bool(true)
                    174: WALK multiple on single OID, max_repetitions set to 30
                    175: string(5) "array"
                    176: int(%d)
                    177: string(%d) "%S"
                    178: string(%d) "%S"
                    179: bool(true)
                    180: WALK multiple on single OID, max_repetitions set to 30, non_repeaters set to 0
                    181: string(5) "array"
                    182: int(%d)
                    183: string(%d) "%S"
                    184: string(%d) "%S"
                    185: bool(true)
                    186: WALK multiple on single OID, max_oids set to 30
                    187: string(5) "array"
                    188: int(%d)
                    189: string(%d) "%S"
                    190: string(%d) "%S"
                    191: bool(true)
                    192: WALK multiple on single OID with OID suffix as keys
                    193: string(5) "array"
                    194: int(%d)
                    195: string(3) "1.0"
                    196: string(%d) "%s"
                    197: bool(true)
                    198: SNMPv3 (default security settings)
                    199: string(%d) "%S"
                    200: string(%d) "%S"
                    201: bool(true)
                    202: SNMPv3 (noAuthNoPriv)
                    203: string(%d) "%S"
                    204: string(%d) "%S"
                    205: bool(true)
                    206: SNMPv3 (authPriv)
                    207: string(%d) "%S"
                    208: string(%d) "%S"
                    209: array(1) {
                    210:   [%s]=>
                    211:   string(%d) "%S"
                    212: }
                    213: bool(true)
                    214: SET single OID
                    215: bool(true)
                    216: bool(true)
                    217: bool(true)
                    218: bool(true)
                    219: bool(true)
                    220: Multiple OID with max_oids = 1
                    221: 
                    222: Warning: SNMP::set(): Can not fit all OIDs for SET query into one packet, using multiple queries in %s on line %d
                    223: bool(true)
                    224: bool(true)
                    225: bool(true)
                    226: 
                    227: Warning: SNMP::set(): Can not fit all OIDs for SET query into one packet, using multiple queries in %s on line %d
                    228: bool(true)
                    229: bool(true)
                    230: bool(true)
                    231: bool(true)
                    232: SNMPv3, setting contextEngineID (authPriv)
                    233: string(%d) "%S"
                    234: bool(true)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>