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

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));
1.1.1.2 ! misho      86: var_dump(key($z));
        !            87: array_shift($z);
        !            88: var_dump(key($z));
        !            89: array_shift($z);
        !            90: var_dump(key($z));
        !            91: array_shift($z);
        !            92: var_dump(key($z));
1.1       misho      93: var_dump($session->close());
                     94: 
                     95: echo "SNMPv3 (default security settings)\n";
                     96: $session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
                     97: #$session->setSecurity($user_noauth, '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 (noAuthNoPriv)\n";
                    103: $session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
                    104: $session->setSecurity('noAuthNoPriv');
                    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->close());
                    108: 
                    109: echo "SNMPv3 (authPriv)\n";
                    110: $session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
                    111: $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
                    112: var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
                    113: var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
                    114: var_dump($session->walk('.1.3.6.1.2.1.1.1.0'));
                    115: var_dump($session->close());
                    116: 
                    117: echo "SET single OID\n";
                    118: $session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
                    119: $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
                    120: $oid1 = 'SNMPv2-MIB::sysContact.0';
                    121: $oldvalue1 = $session->get($oid1);
                    122: $newvalue1 = $oldvalue1 . '0';
                    123: 
                    124: $z = $session->set($oid1, 's', $newvalue1);
                    125: var_dump($z);
                    126: var_dump(($session->get($oid1) === $newvalue1));
                    127: $z = $session->set($oid1, 's', $oldvalue1);
                    128: var_dump($z);
                    129: var_dump(($session->get($oid1) === $oldvalue1));
                    130: var_dump($session->close());
                    131: 
                    132: echo "Multiple OID with max_oids = 1\n";
                    133: $oid2 = 'SNMPv2-MIB::sysLocation.0';
                    134: $session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
                    135: $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
                    136: $session->max_oids = 1;
                    137: $oldvalue2 = $session->get($oid2);
                    138: $newvalue2 = $oldvalue2 . '0';
                    139: $z = $session->set(array($oid1, $oid2), array('s','s'), array($newvalue1, $newvalue2));
                    140: var_dump($z);
                    141: var_dump(($session->get($oid1) === $newvalue1));
                    142: var_dump(($session->get($oid2) === $newvalue2));
                    143: $z = $session->set(array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2));
                    144: var_dump($z);
                    145: var_dump(($session->get($oid1) === $oldvalue1));
                    146: var_dump(($session->get($oid2) === $oldvalue2));
                    147: var_dump($session->close());
                    148: 
                    149: echo "SNMPv3, setting contextEngineID (authPriv)\n";
                    150: $session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
                    151: $session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '', 'aeeeff');
                    152: var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
                    153: var_dump($session->close());
                    154: 
                    155: ?>
                    156: --EXPECTF--
                    157: SNMPv1
                    158: string(%d) "%S"
                    159: array(2) {
                    160:   ["%s"]=>
                    161:   string(%d) "%S"
                    162:   ["%s"]=>
                    163:   string(%d) "%S"
                    164: }
                    165: string(%d) "%S"
                    166: bool(true)
                    167: SNMPv2
                    168: string(%d) "%S"
                    169: string(%d) "%S"
                    170: bool(true)
                    171: GET with preserving original OID names
                    172: string(%d) "%s"
                    173: string(%d) "%s"
                    174: bool(true)
                    175: WALK multiple on single OID
                    176: string(5) "array"
                    177: int(%d)
                    178: string(%d) "%S"
                    179: string(%d) "%S"
                    180: bool(true)
                    181: WALK multiple on single OID, max_repetitions set to 30
                    182: string(5) "array"
                    183: int(%d)
                    184: string(%d) "%S"
                    185: string(%d) "%S"
                    186: bool(true)
                    187: WALK multiple on single OID, max_repetitions set to 30, non_repeaters set to 0
                    188: string(5) "array"
                    189: int(%d)
                    190: string(%d) "%S"
                    191: string(%d) "%S"
                    192: bool(true)
                    193: WALK multiple on single OID, max_oids set to 30
                    194: string(5) "array"
                    195: int(%d)
                    196: string(%d) "%S"
                    197: string(%d) "%S"
                    198: bool(true)
                    199: WALK multiple on single OID with OID suffix as keys
                    200: string(5) "array"
                    201: int(%d)
                    202: string(3) "1.0"
                    203: string(%d) "%s"
1.1.1.2 ! misho     204: string(3) "2.0"
        !           205: string(3) "3.0"
        !           206: string(3) "4.0"
        !           207: string(3) "5.0"
1.1       misho     208: bool(true)
                    209: SNMPv3 (default security settings)
                    210: string(%d) "%S"
                    211: string(%d) "%S"
                    212: bool(true)
                    213: SNMPv3 (noAuthNoPriv)
                    214: string(%d) "%S"
                    215: string(%d) "%S"
                    216: bool(true)
                    217: SNMPv3 (authPriv)
                    218: string(%d) "%S"
                    219: string(%d) "%S"
                    220: array(1) {
                    221:   [%s]=>
                    222:   string(%d) "%S"
                    223: }
                    224: bool(true)
                    225: SET single OID
                    226: bool(true)
                    227: bool(true)
                    228: bool(true)
                    229: bool(true)
                    230: bool(true)
                    231: Multiple OID with max_oids = 1
                    232: 
                    233: Warning: SNMP::set(): Can not fit all OIDs for SET query into one packet, using multiple queries in %s on line %d
                    234: bool(true)
                    235: bool(true)
                    236: bool(true)
                    237: 
                    238: Warning: SNMP::set(): Can not fit all OIDs for SET query into one packet, using multiple queries in %s on line %d
                    239: bool(true)
                    240: bool(true)
                    241: bool(true)
                    242: bool(true)
                    243: SNMPv3, setting contextEngineID (authPriv)
                    244: string(%d) "%S"
                    245: bool(true)

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