/usr/share/perl5/SNMP/Info.pm is in libsnmp-info-perl 3.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 | # SNMP::Info
#
# Copyright (c) 2003-2012 Max Baker and SNMP::Info Developers
# All rights reserved.
#
# Portions Copyright (c) 2002-2003, Regents of the University of California
# All rights reserved.
#
# See COPYRIGHT at bottom
package SNMP::Info;
use warnings;
use strict;
use Exporter;
use SNMP;
use Carp;
use Math::BigInt;
@SNMP::Info::ISA = qw/Exporter/;
@SNMP::Info::EXPORT_OK = qw//;
use vars
qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG %SPEED_MAP
$NOSUCH $BIGINT $REPEATERS/;
$VERSION = '3.11';
=head1 NAME
SNMP::Info - OO Interface to Network devices and MIBs through SNMP
=head1 VERSION
SNMP::Info - Version 3.11
=head1 AUTHOR
SNMP::Info is maintained by team of Open Source authors headed by Eric Miller,
Bill Fenner, Max Baker, Jeroen van Ingen and Oliver Gorwits.
Please visit L<http://sourceforge.net/projects/snmp-info/> for most up-to-date
list of developers.
SNMP::Info was originally created at UCSC for the Netdisco project L<http://netdisco.org>
by Max Baker.
=head1 DEVICES SUPPORTED
See L<http://netdisco.org/doc/DeviceMatrix.html> or L<DeviceMatrix.txt> for more details.
=head1 SYNOPSIS
use SNMP::Info;
my $info = new SNMP::Info(
# Auto Discover more specific Device Class
AutoSpecify => 1,
Debug => 1,
# The rest is passed to SNMP::Session
DestHost => 'router',
Community => 'public',
Version => 2
) or die "Can't connect to device.\n";
my $err = $info->error();
die "SNMP Community or Version probably wrong connecting to device. $err\n" if defined $err;
$name = $info->name();
$class = $info->class();
print "SNMP::Info is using this device class : $class\n";
# Find out the Duplex status for the ports
my $interfaces = $info->interfaces();
my $i_duplex = $info->i_duplex();
# Get CDP Neighbor info
my $c_if = $info->c_if();
my $c_ip = $info->c_ip();
my $c_port = $info->c_port();
# Print out data per port
foreach my $iid (keys %$interfaces){
my $duplex = $i_duplex->{$iid};
# Print out physical port name, not snmp iid
my $port = $interfaces->{$iid};
print "$port: ";
print "$duplex duplex" if defined $duplex;
# The CDP Table has table entries different than the interface tables.
# So we use c_if to get the map from cdp table to interface table.
my %c_map = reverse %$c_if;
my $c_key = $c_map{$iid};
unless (defined $c_key) {
print "\n\n";
next;
}
my $neighbor_ip = $c_ip->{$c_key};
my $neighbor_port = $c_port->{$c_key};
print " connected to $neighbor_ip / $neighbor_port\n" if defined $neighbor_ip;
print "\n";
}
=head1 SUPPORT
Please direct all support, help, and bug requests to the snmp-info-users
Mailing List at <http://lists.sourceforge.net/lists/listinfo/snmp-info-users>.
=head1 DESCRIPTION
SNMP::Info gives an object oriented interface to information obtained through
SNMP.
This module is geared towards network devices. Subclasses exist for a number
of network devices and common MIBs.
The idea behind this module is to give a common interface to data from network
devices, leaving the device-specific hacks behind the scenes in subclasses.
In the SYNOPSIS example we fetch the name of all the ports on the device and
the duplex setting for that port with two methods -- interfaces() and
i_duplex().
The information may be coming from any number of MIB files and is very vendor
specific. SNMP::Info provides you a common method for all supported devices.
Adding support for your own device is easy, and takes little SNMP knowledge.
The module is not limited to network devices. Any MIB or device can be given
an objected oriented front-end by making a module that consists of a couple
hashes. See EXTENDING SNMP::INFO.
=head1 REQUIREMENTS
=over
=item 1. Net-SNMP
To use this module, you must have Net-SNMP installed on your system.
More specifically you need the Perl modules that come with it.
DO NOT INSTALL SNMP:: or Net::SNMP from CPAN!
The SNMP module is matched to an install of net-snmp, and must be installed
from the net-snmp source tree.
The Perl module C<SNMP> is found inside the net-snmp distribution. Go to the
F<perl/> directory of the distribution to install it, or run
C<./configure --with-perl-modules> from the top directory of the net-snmp
distribution.
Net-SNMP can be found at http://net-snmp.sourceforge.net
Version 5.3.2 or greater is recommended.
Versions 5.0.1, 5.0301 and 5.0203 have issues with bulkwalk and are not supported.
B<Redhat Users>: Some versions that come with certain versions of
Redhat/Fedora don't have the Perl library installed. Uninstall the RPM and
install by hand.
=item 2. MIBS
SNMP::Info operates on textual descriptors found in MIBs.
If you are using SNMP::Info separate from Netdisco,
download the Netdisco MIB package at L<http://sourceforge.net/project/showfiles.php?group_id=80033&package_id=135517>
Make sure that your snmp.conf is updated to point to your MIB directory
and that the MIBs are world-readable.
=back
=head1 DESIGN GOALS
=over
=item 1. Use of textual MIB leaf identifier and enumerated values
=over
=item * All values are retrieved via MIB Leaf node names
For example SNMP::Info has an entry in its %GLOBALS hash for ``sysName''
instead of 1.3.6.1.2.1.1.5.
=item * Data returned is in the enumerated value form.
For Example instead of looking up 1.3.6.1.2.1.2.2.1.3 and getting back C<23>
SNMP::Info will ask for C<RFC1213-MIB::ifType> and will get back C<ppp>.
=back
=item 2. SNMP::Info is easily extended to new devices
You can create a new subclass for a device by providing four hashes :
%GLOBALS, %MIBS, %FUNCS, and %MUNGE.
Or you can override any existing methods from a parent class by making a short
subroutine.
See the section EXTENDING SNMP::INFO for more details.
When you make a new subclass for a device, please be sure to send it back to
the developers (via Source Forge or the mailing list) for inclusion in the
next version.
=back
=head1 SUBCLASSES
These are the subclasses that implement MIBs and support devices:
Required MIBs not included in the install instructions above are noted here.
=head2 MIB Subclasses
These subclasses implement method to access one or more MIBs. These are not
used directly, but rather inherited from device subclasses.
For more info run C<perldoc> on any of the following module names.
=over
=item SNMP::Info::AdslLine
SNMP Interface to the ADSL-LINE-MIB for ADSL interfaces.
Requires the F<ADSL-LINE-MIB>, down loadable from Cisco.
See documentation in L<SNMP::Info::AdslLine> for details.
=item SNMP::Info::Aggregate
SNMP Interface to F<IF-MIB> C<ifStackTable> Aggregated Links
See documentation in L<SNMP::Info::Aggregate> for details.
=item SNMP::Info::Airespace
F<AIRESPACE-WIRELESS-MIB> and F<AIRESPACE-SWITCHING-MIB>. Inherited by
devices based on the Airespace wireless platform.
See documentation in L<SNMP::Info::Airespace> for details.
=item SNMP::Info::AMAP
F<ALCATEL-IND1-INTERSWITCH-PROTOCOL-MIB>. Alcatel Mapping Adjacency
Protocol (AMAP) Support.
See documentation in L<SNMP::Info::AMAP> for details.
=item SNMP::Info::Bridge
F<BRIDGE-MIB> (RFC1286). F<QBRIDGE-MIB>. Inherited by devices with Layer2
support.
See documentation in L<SNMP::Info::Bridge> for details.
=item SNMP::Info::CiscoAgg
SNMP Interface to Cisco Aggregated Links
See documentation in L<SNMP::Info::CiscoAgg> for details.
=item SNMP::Info::CDP
F<CISCO-CDP-MIB>. Cisco Discovery Protocol (CDP) Support. Inherited by
Cisco, Enterasys, and HP devices.
See documentation in L<SNMP::Info::CDP> for details.
=item SNMP::Info::CiscoConfig
F<CISCO-CONFIG-COPY-MIB>, F<CISCO-FLASH-MIB>, and F<OLD-CISCO-SYS-MIB>.
These OIDs facilitate the writing of configuration files.
See documentation in L<SNMP::Info::CiscoConfig> for details.
=item SNMP::Info::CiscoImage
F<CISCO-IMAGE-MIB>. A collection of OIDs providing IOS image characteristics.
See documentation in L<SNMP::Info::CiscoImage> for details.
=item SNMP::Info::CiscoPortSecurity
F<CISCO-PORT-SECURITY-MIB> and F<CISCO-PAE-MIB>.
See documentation in L<SNMP::Info::CiscoPortSecurity> for details.
=item SNMP::Info::CiscoPower
F<CISCO-POWER-ETHERNET-EXT-MIB>.
See documentation in L<SNMP::Info::CiscoPower> for details.
=item SNMP::Info::CiscoQOS
F<CISCO-CLASS-BASED-QOS-MIB>. A collection of OIDs providing information about
a Cisco device's QOS config.
See documentation in L<SNMP::Info::CiscoQOS> for details.
=item SNMP::Info::CiscoRTT
F<CISCO-RTTMON-MIB>. A collection of OIDs providing information about a Cisco
device's RTT values.
See documentation in L<SNMP::Info::CiscoRTT> for details.
=item SNMP::Info::CiscoStack
F<CISCO-STACK-MIB>.
See documentation in L<SNMP::Info::CiscoStack> for details.
=item SNMP::Info::CiscoStpExtensions
F<CISCO-STP-EXTENSIONS-MIB>
See documentation in L<SNMP::Info::CiscoStpExtensions> for details.
=item SNMP::Info::CiscoStats
F<OLD-CISCO-CPU-MIB>, F<CISCO-PROCESS-MIB>, and F<CISCO-MEMORY-POOL-MIB>.
Provides common interfaces for memory, cpu, and os statistics for Cisco
devices.
See documentation in L<SNMP::Info::CiscoStats> for details.
=item SNMP::Info::CiscoVTP
F<CISCO-VTP-MIB>, F<CISCO-VLAN-MEMBERSHIP-MIB>,
F<CISCO-VLAN-IFTABLE-RELATIONSHIP-MIB>
See documentation in L<SNMP::Info::CiscoVTP> for details.
=item SNMP::Info::EDP
Extreme Discovery Protocol. F<EXTREME-EDP-MIB>
See documentation in L<SNMP::Info::EDP> for details.
=item SNMP::Info::Entity
F<ENTITY-MIB>. Used for device info in Cisco and other vendors.
See documentation in L<SNMP::Info::Entity> for details.
=item SNMP::Info::EtherLike
F<EtherLike-MIB> (RFC1398) - Some Layer3 devices implement this MIB, as well
as some Aironet Layer 2 devices (non Cisco).
See documentation in L<SNMP::Info::EtherLike> for details.
=item SNMP::Info::FDP
Foundry (Brocade) Discovery Protocol. F<FOUNDRY-SN-SWITCH-GROUP-MIB>
See documentation in L<SNMP::Info::FDP> for details.
=item SNMP::Info::IPv6
SNMP Interface for obtaining configured IPv6 addresses and mapping IPv6
addresses to MAC addresses and interfaces, using information from F<IP-MIB>,
F<IPV6-MIB> and/or F<CISCO-IETF-IP-MIB>.
See documentation in L<SNMP::Info::IPv6> for details.
=item SNMP::Info::IEEE802dot11
F<IEEE802dot11-MIB>. A collection of OIDs providing information about
standards based 802.11 wireless devices.
See documentation in L<SNMP::Info::IEEE802dot11> for details.
=item SNMP::Info::IEEE802dot3ad
SNMP Interface to IEEE Aggregated Links. F<IEEE8023-LAG-MIB>
See documentation in L<SNMP::Info::IEEE802dot3ad> for details.
=item SNMP::Info::LLDP
F<LLDP-MIB>, F<LLDP-EXT-DOT1-MIB>, and F<LLDP-EXT-DOT3-MIB>. Link Layer
Discovery Protocol (LLDP) Support.
See documentation in L<SNMP::Info::LLDP> for details.
=item SNMP::Info::MAU
F<MAU-MIB> (RFC2668). Some Layer2 devices use this for extended Ethernet
(Media Access Unit) interface information.
See documentation in L<SNMP::Info::MAU> for details.
=item SNMP::Info::NortelStack
F<S5-AGENT-MIB>, F<S5-CHASSIS-MIB>.
See documentation in L<SNMP::Info::NortelStack> for details.
=item SNMP::Info::PowerEthernet
F<POWER-ETHERNET-MIB>
See documentation in L<SNMP::Info::PowerEthernet> for details.
=item SNMP::Info::RapidCity
F<RAPID-CITY>. Inherited by Avaya switches for duplex and VLAN information.
See documentation in L<SNMP::Info::RapidCity> for details.
=item SNMP::Info::SONMP
SynOptics Network Management Protocol (SONMP) F<SYNOPTICS-ROOT-MIB>,
F<S5-ETH-MULTISEG-TOPOLOGY-MIB>. Inherited by
Avaya/Nortel/Bay/Synoptics switches and hubs.
See documentation in L<SNMP::Info::SONMP> for details.
=back
=head2 Device Subclasses
These subclasses inherit from one or more classes to provide a common
interface to data obtainable from network devices.
All the required MIB files are included in the netdisco-mib package.
(See Above).
=over
=item SNMP::Info::Layer1
Generic Layer1 Device subclass.
See documentation in L<SNMP::Info::Layer1> for details.
=over
=item SNMP::Info::Layer1::Allied
Subclass for Allied Telesis Repeaters / Hubs.
Requires F<ATI-MIB>
See documentation in L<SNMP::Info::Layer1::Allied> for details.
=item SNMP::Info::Layer1::Asante
Subclass for Asante 1012 Hubs.
Requires F<ASANTE-HUB1012-MIB>
See documentation in L<SNMP::Info::Layer1::Asante> for details.
=item SNMP::Info::Layer1::Bayhub
Subclass for Nortel/Bay hubs. This includes System 5000, 100 series,
200 series, and probably more.
See documentation in L<SNMP::Info::Layer1::Bayhub> for details.
=item SNMP::Info::Layer1::Cyclades
Subclass for Cyclades terminal servers.
See documentation in L<SNMP::Info::Layer1::Cyclades> for details.
=item SNMP::Info::Layer1::S3000
Subclass for Bay/Synoptics hubs. This includes System 3000, 281X, and
probably more.
See documentation in L<SNMP::Info::Layer1::S3000> for details.
=back
=item SNMP::Info::Layer2
Generic Layer2 Device subclass.
See documentation in L<SNMP::Info::Layer2> for details.
=over
=item SNMP::Info::Layer2::Airespace
Subclass for Cisco (Airespace) wireless controllers.
See documentation in L<SNMP::Info::Layer2::Airespace> for details.
=item SNMP::Info::Layer2::Aironet
Class for Cisco Aironet wireless devices that run IOS. See also
Layer3::Aironet for Aironet devices that don't run IOS.
See documentation in L<SNMP::Info::Layer2::Aironet> for details.
=item SNMP::Info::Layer2::Allied
Allied Telesis switches.
See documentation in L<SNMP::Info::Layer2::Allied> for details.
=item SNMP::Info::Layer2::Baystack
Subclass for Avaya/Nortel/Bay Ethernet Switch/Baystack switches. This
includes 303, 304, 350, 380, 410, 420, 425, 450, 460, 470 series,
2500 series, 4000 series, 5000 series, Business Ethernet Switch (BES),
Business Policy Switch (BPS), VSP 7000 series, and probably others.
See documentation in L<SNMP::Info::Layer2::Baystack> for details.
=item SNMP::Info::Layer2::Kentrox
Class for Kentrox DataSMART DSU/CSU. See L<SNMP::Info::Layer2::Kentrox> for details.
=item SNMP::Info::Layer2::C1900
Subclass for Cisco Catalyst 1900 and 1900c Devices running CatOS.
See documentation in L<SNMP::Info::Layer2::C1900> for details.
=item SNMP::Info::Layer2::C2900
Subclass for Cisco Catalyst 2900, 2950, 3500XL, and 3548 devices running IOS.
See documentation in L<SNMP::Info::Layer2::C2900> for details.
=item SNMP::Info::Layer2::Catalyst
Subclass for Cisco Catalyst switches running CatOS. These switches usually
report a model number that starts with C<wsc>. Note that this class
does not support everything that has the name Catalyst.
See documentation in L<SNMP::Info::Layer2::Catalyst> for details.
=item SNMP::Info::Layer2::Centillion
Subclass for Nortel/Bay Centillion and 5000BH ATM switches.
See documentation in L<SNMP::Info::Layer2::Centillion> for details.
=item SNMP::Info::Layer2::Cisco
Generic Cisco subclass for layer2 devices that are not yet supported
in more specific subclasses.
See documentation in L<SNMP::Info::Layer2::Cisco> for details.
=item SNMP::Info::Layer2::CiscoSB
Subclass for Cisco's "Small Business" product line, acquired from
Linksys. This currently comprises the Sx300/500 line of switches.
See documentation in L<SNMP::Info::Layer2::CiscoSB> for details.
=item SNMP::Info::Layer2::HP
Subclass for more recent HP Procurve Switches
Requires F<HP-ICF-OID> and F<ENTITY-MIB> downloaded from HP.
See documentation in L<SNMP::Info::Layer2::HP> for details.
=item SNMP::Info::Layer2::HP4000
Subclass for older HP Procurve Switches
Requires F<HP-ICF-OID> and F<ENTITY-MIB> downloaded from HP.
See documentation in L<SNMP::Info::Layer2::HP4000> for details.
=item SNMP::Info::Layer2::HPVC
Subclass for HP Virtual Connect Switches
See documentation in L<SNMP::Info::Layer2::HPVC> for details.
=item SNMP::Info::Layer2::N2270
Subclass for Nortel 2270 wireless switches.
See documentation in L<SNMP::Info::Layer2::N2270> for details.
=item SNMP::Info::Layer2::NAP222x
Subclass for Nortel 222x series wireless access points.
See documentation in L<SNMP::Info::Layer2::NAP222x> for details.
=item SNMP::Info::Layer2::Netgear
Subclass for Netgear switches
See documentation in L<SNMP::Info::Layer2::Netgear> for details.
=item SNMP::Info::Layer2::NWSS2300
SNMP Interface to Avaya (Trapeze) Wireless Controllers
See documentation in L<SNMP::Info::Layer2::NWSS2300> for details.
=item SNMP::Info::Layer2::Orinoco
Subclass for Orinoco/Proxim wireless access points.
See documentation in L<SNMP::Info::Layer2::Orinoco> for details.
=item SNMP::Info::Layer2::Trapeze
SNMP Interface to Juniper (Trapeze) Wireless Controllers
See documentation in L<SNMP::Info::Layer2::Trapeze> for details.
=item SNMP::Info::Layer2::ZyXEL_DSLAM
Zyxel DSLAMs. Need I say more?
See documentation in L<SNMP::Info::Layer2::ZyXEL_DSLAM> for details.
=back
=item SNMP::Info::Layer3
Generic Layer3 and Layer2+3 Device subclass.
See documentation in L<SNMP::Info::Layer3> for details.
=over
=item SNMP::Info::Layer3::Aironet
Subclass for Cisco Aironet wireless access points (AP) not running IOS. These
are usually older devices.
MIBs for these devices now included in v2.tar.gz available from ftp.cisco.com.
Note Layer2::Aironet
See documentation in L<SNMP::Info::Layer3::Aironet> for details.
=item SNMP::Info::Layer3::AlcatelLucent
Alcatel-Lucent OmniSwitch Class.
See documentation in L<SNMP::Info::Layer3::AlcatelLucent> for details.
=item SNMP::Info::Layer3::AlteonAD
Subclass for Radware Alteon Series ADC switches and Nortel BladeCenter
Layer2-3 GbE Switch Modules.
See documentation in L<SNMP::Info::Layer3::AlteonAD> for details.
=item SNMP::Info::Layer3::Altiga
See documentation in L<SNMP::Info::Layer3::Altiga> for details.
=item SNMP::Info::Layer3::Arista
See documentation in L<SNMP::Info::Layer3::Arista> for details.
=item SNMP::Info::Layer3::Aruba
Subclass for Aruba wireless switches.
See documentation in L<SNMP::Info::Layer3::Aruba> for details.
=item SNMP::Info::Layer3::BayRS
Subclass for Avaya/Nortel/Bay Multiprotocol/BayRS routers. This includes
BCN, BLN, ASN, ARN, AN, 2430, and 5430 routers.
See documentation in L<SNMP::Info::Layer3::BayRS> for details.
=item SNMP::Info::Layer3::BlueCoatSG
Subclass for Blue Coat SG series proxy devices.
See documentation in L<SNMP::Info::Layer3::BlueCoatSG> for details.
=item SNMP::Info::Layer3::C3550
Subclass for Cisco Catalyst 3550,3540,3560 2/3 switches running IOS.
See documentation in L<SNMP::Info::Layer3::C3550> for details.
=item SNMP::Info::Layer3::C4000
This class covers Catalyst 4000s and 4500s.
See documentation in L<SNMP::Info::Layer3::C4000> for details.
=item SNMP::Info::Layer3::C6500
This class covers Catalyst 6500s in native mode, hybrid mode. Catalyst
3750's, 2970's and probably others.
See documentation in L<SNMP::Info::Layer3::C6500> for details.
=item SNMP::Info::Layer3::Cisco
This is a simple wrapper around Layer3 for IOS devices. It adds on CiscoVTP.
See documentation in L<SNMP::Info::Layer3::Cisco> for details.
=item SNMP::Info::Layer3::CiscoASA
Subclass for Cisco Adaptive Security Appliances.
See documentation in L<SNMP::Info::Layer3::CiscoASA> for details.
=item SNMP::Info::Layer3::CiscoFWSM
Subclass for Cisco Firewall Services Modules.
See documentation in L<SNMP::Info::Layer3::CiscoFWSM> for details.
=item SNMP::Info::Layer3::Contivity
Subclass for Avaya/Nortel Contivity/VPN Routers.
See documentation in L<SNMP::Info::Layer3::Contivity> for details.
=item SNMP::Info::Layer3::Dell
Subclass for Dell PowerConnect switches. D-Link, the IBM BladeCenter
Gigabit Ethernet Switch Module and some Linksys switches
also use this module based upon MIB support.
See documentation in L<SNMP::Info::Layer3::Dell> for details.
=item SNMP::Info::Layer3::Enterasys
Subclass for Enterasys devices.
See documentation in L<SNMP::Info::Layer3::Enterasys> for details.
=item SNMP::Info::Layer3::Extreme
Subclass for Extreme Networks switches.
See documentation in L<SNMP::Info::Layer3::Extreme> for details.
=item SNMP::Info::Layer3::F5
Subclass for F5 devices.
See documentation in L<SNMP::Info::Layer3::F5> for details.
=item SNMP::Info::Layer3::Force10
Subclass for Force10 devices.
See documentation in L<SNMP::Info::Layer3::Force10> for details.
=item SNMP::Info::Layer3::Foundry
Subclass for Brocade (Foundry) Network devices.
See documentation in L<SNMP::Info::Layer3::Foundry> for details.
=item SNMP::Info::Layer3::H3C
SNMP Interface to Layer 3 Devices, H3C & HP A-series.
See documentation in L<SNMP::Info::Layer3::H3C> for details.
=item SNMP::Info::Layer3::HP9300
Subclass for HP network devices which Foundry Networks was the
Original Equipment Manufacturer (OEM) such as the HP ProCurve 9300 and 6300 series.
See documentation in L<SNMP::Info::Layer3::HP9300> for details.
=item SNMP::Info::Layer3::IBMGbTor
SNMP Interface to IBM Rackswitch (formerly Blade Network Technologies)
network devices.
See documentation in L<SNMP::Info::Layer3::IBMGbTor> for details.
=item SNMP::Info::Layer3::Juniper
Subclass for Juniper devices
See documentation in L<SNMP::Info::Layer3::Juniper> for details.
=item SNMP::Info::Layer3::Lantronix
Subclass for Lantronix devices
See documentation in L<SNMP::Info::Layer3::Lantronix> for details.
=item SNMP::Info::Layer3::Microsoft
Subclass for Generic Microsoft Routers running Microsoft Windows OS.
See documentation in L<SNMP::Info::Layer3::Microsoft> for details.
=item SNMP::Info::Layer3::Mikrotik
Subclass for Mikrotik devices running RouterOS.
See documentation in L<SNMP::Info::Layer3::Mikrotik> for details.
=item SNMP::Info::Layer3::N1600
Subclass for Avaya/Nortel Ethernet Routing Switch 1600 series.
See documentation in L<SNMP::Info::Layer3::N1600> for details.
=item SNMP::Info::Layer3::NetSNMP
Subclass for host systems running Net-SNMP.
See documentation in L<SNMP::Info::Layer3::NetSNMP> for details.
=item SNMP::Info::Layer3::Netscreen
Subclass for Juniper NetScreen.
See documentation in L<SNMP::Info::Layer3::Netscreen> for details.
=item SNMP::Info::Layer3::Nexus
Subclass for Cisco Nexus devices running NX-OS
See documentation in L<SNMP::Info::Layer3::Nexus> for details.
=item SNMP::Info::Layer3::PacketFront
Subclass for PacketFront DRG series CPE.
See documentation in L<SNMP::Info::Layer3::PacketFront> for details.
=item SNMP::Info::Layer3::Passport
Subclass for Avaya/Nortel Ethernet Routing Switch/Passport 8000 series,
Accelar, and VSP 9000 series switches.
See documentation in L<SNMP::Info::Layer3::Passport> for details.
=item SNMP::Info::Layer3::Pf
Subclass for FreeBSD-Based Firewalls using Pf /Pf Sense
See documentation in L<SNMP::Info::Layer3::Pf> for details.
=item SNMP::Info::Layer3::Pica8
Subclass for Pica8 devices.
See documentation in L<SNMP::Info::Layer3::Pica8> for details.
=item SNMP::Info::Layer3::SonicWALL
Subclass for generic SonicWALL devices. See documentation in
L<SNMP::Info::Layer3::SonicWALL> for details.
=item SNMP::Info::Layer3::Steelhead
Subclass for Riverbed Steelhead WAN optimization appliances. See
documentation in L<SNMP::Info::Layer3::Steelhead> for details.
=item SNMP::Info::Layer3::Sun
Subclass for Generic Sun Routers running SunOS.
See documentation in L<SNMP::Info::Layer3::Sun> for details.
=item SNMP::Info::Layer3::Tasman
Subclass for Avaya Secure Routers.
See documentation in L<SNMP::Info::Layer3::Tasman> for details.
=item SNMP::Info::Layer3::Timetra
Alcatel-Lucent SR Class.
See documentation in L<SNMP::Info::Layer3::Timetra> for details.
=back
=back
=over 4
=item SNMP::Info::Layer7
Generic Layer7 Devices.
See documentation in L<SNMP::Info::Layer7> for details.
=over 4
=item SNMP::Info::Layer7::APC
SNMP Interface to APC UPS devices
See documentation in L<SNMP::Info::Layer7::APC> for details.
=item SNMP::Info::Layer7::Netscaler
SNMP Interface to Citrix Netscaler appliances
See documentation in L<SNMP::Info::Layer7::Netscaler> for details.
=item SNMP::Info::Layer7::Neoteris
SNMP Interface to Juniper SSL VPN appliances
See documentation in L<SNMP::Info::Layer7::Neoteris> for details.
=back
=back
=head1 Thanks
Thanks for testing and coding help (in no particular order) to :
Alexander Barthel, Andy Ford, Alexander Hartmaier, Andrew Herrick, Alex
Kramarov, Bernhard Augenstein, Bradley Baetz, Brian Chow, Brian Wilson,
Carlos Vicente, Dana Watanabe, David Pinkoski, David Sieborger, Douglas
McKeown, Greg King, Ivan Auger, Jean-Philippe Luiggi, Jeroen van Ingen,
Justin Hunter, Kent Hamilton, Matthew Tuttle, Michael Robbert, Mike Hunter,
Nicolai Petri, Ralf Gross, Robert Kerr and people listed on the Netdisco
README!
=head1 USAGE
=head2 Constructor
=over
=item new()
Creates a new object and connects via SNMP::Session.
my $info = new SNMP::Info( 'Debug' => 1,
'AutoSpecify' => 1,
'BigInt' => 1,
'BulkWalk' => 1,
'BulkRepeaters' => 20,
'IgnoreNetSNMPConf' => 1,
'LoopDetect' => 1,
'DestHost' => 'myrouter',
'Community' => 'public',
'Version' => 2,
'MibDirs' => ['dir1','dir2','dir3'],
) or die;
SNMP::Info Specific Arguments :
=over
=item AutoSpecify
Returns an object of a more specific device class
(default 0, which means "off")
=item BigInt
Return Math::BigInt objects for 64 bit counters. Sets on a global scope,
not object.
(default 0, which means "off")
=item BulkWalk
Set to C<0> to turn off BULKWALK commands for SNMPv2 connections.
Note that BULKWALK is turned off for Net-SNMP versions 5.1.x because of a bug.
(default 1, which means "on")
=item BulkRepeaters
Set number of MaxRepeaters for BULKWALK operation. See
C<perldoc SNMP> -> bulkwalk() for more info.
(default 20)
=item LoopDetect
Detects looping during getnext table column walks by comparing IIDs for each
instance. A loop is detected if the same IID is seen more than once and the
walk is aborted. Note: This will not detect loops during a bulkwalk
operation, Net-SNMP's internal bulkwalk function must detect the loop.
Set to C<0> to turn off loop detection.
(default 1, which means "on")
=item IgnoreNetSNMPConf
Net-SNMP version 5.0 and higher read configuration files, snmp.conf or
snmp.local.conf, from /etc/snmp, /usr/share/snmp, /usr/lib(64)/snmp, or
$HOME/.snmp and uses those settings to automatically parse MIB files, etc.
Set to C<1> "on" to ignore Net-SNMP configuration files by overriding the
C<SNMPCONFPATH> environmental variable during object initialization. Note:
MibDirs must be defined or Net-SNMP will not be able to load MIBs and
initialize the object.
(default 0, which means "off")
=item Debug
Prints Lots of debugging messages.
Pass 2 to print even more debugging messages.
(default 0, which means "off")
=item DebugSNMP
Set $SNMP::debugging level for Net-SNMP.
See F<SNMP> for more details.
=item MibDirs
Array ref to list of directories in which to look for MIBs. Note this will
be in addition to the ones setup in snmp.conf at the system level.
(default use net-snmp settings only)
=item RetryNoSuch
When using SNMP Version 1, try reading values even if they come back as "no
such variable in this MIB". Set to false if so desired. This feature lets
you read SNMPv2 data from an SNMP version 1 connection, and should probably
be left on.
(default 1, which means "on")
=item Session
SNMP::Session object to use instead of connecting on own.
(default creates session automatically)
=item OTHER
All other arguments are passed to SNMP::Session.
See SNMP::Session for a list of other possible arguments.
=back
A Note about the wrong Community string or wrong SNMP Version:
If a connection is using the wrong community string or the wrong SNMP version,
the creation of the object will not fail. The device still answers the call
on the SNMP port, but will not return information. Check the error() method
after you create the device object to see if there was a problem in
connecting.
A note about SNMP Versions :
Some older devices don't support SNMP version 2, and will not return anything
when a connection under Version 2 is attempted.
Some newer devices will support Version 1, but will not return all the data
they might have if you had connected under Version 1
When trying to get info from a new device, you may have to try version 2 and
then fallback to version 1.
=cut
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = @_;
my %sess_args = %args;
my $new_obj = {};
bless $new_obj, $class;
$new_obj->{class} = $class;
# load references to all the subclass data structures
{
no strict 'refs'; ## no critic (ProhibitNoStrict ProhibitProlongedStrictureOverride)
$new_obj->{init} = \${ $class . '::INIT' };
$new_obj->{mibs} = \%{ $class . '::MIBS' };
$new_obj->{globals} = \%{ $class . '::GLOBALS' };
$new_obj->{funcs} = \%{ $class . '::FUNCS' };
$new_obj->{munge} = \%{ $class . '::MUNGE' };
}
# SNMP::Info specific args :
if ( defined $args{Debug} ) {
$new_obj->debug( $args{Debug} );
delete $sess_args{Debug};
}
else {
$new_obj->debug( defined $DEBUG ? $DEBUG : 0 );
}
if ( defined $args{DebugSNMP} ) {
$SNMP::debugging = $args{DebugSNMP};
delete $sess_args{DebugSNMP};
}
my $auto_specific = 0;
if ( defined $args{AutoSpecify} ) {
$auto_specific = $args{AutoSpecify} || 0;
delete $sess_args{AutoSpecify};
}
if ( defined $args{BulkRepeaters} ) {
$new_obj->{BulkRepeaters} = $args{BulkRepeaters};
delete $sess_args{BulkRepeaters};
}
if ( defined $args{BulkWalk} ) {
$new_obj->{BulkWalk} = $args{BulkWalk};
delete $sess_args{BulkWalk};
}
if ( defined $args{LoopDetect} ) {
$new_obj->{LoopDetect} = $args{LoopDetect};
delete $sess_args{LoopDetect};
}
if ( defined $args{IgnoreNetSNMPConf} ) {
$new_obj->{IgnoreNetSNMPConf} = $args{IgnoreNetSNMPConf} || 0;
delete $sess_args{IgnoreNetSNMPConf};
}
my $sess = undef;
if ( defined $args{Session} ) {
$sess = $args{Session};
delete $sess_args{Session};
}
if ( defined $args{BigInt} ) {
$BIGINT = $args{BigInt};
delete $sess_args{BigInt};
}
if ( defined $args{MibDirs} ) {
$new_obj->{mibdirs} = $args{MibDirs};
delete $sess_args{MibDirs};
}
$new_obj->{nosuch} = $args{RetryNoSuch} || $NOSUCH;
# Initialize mibs if not done
my $init_ref = $new_obj->{init};
unless ( defined $$init_ref and $$init_ref ) {
$new_obj->init();
$$init_ref = 1;
}
# Connects to device unless open session is provided.
$sess = new SNMP::Session(
'UseEnums' => 1,
%sess_args, 'RetryNoSuch' => $new_obj->{nosuch}
) unless defined $sess;
# No session object created
unless ( defined $sess ) {
$new_obj->error_throw("SNMP::Info::new() Failed to Create Session. ");
return;
}
# Session object created but SNMP connection failed.
my $sess_err = $sess->{ErrorStr} || '';
if ($sess_err) {
$new_obj->error_throw(
"SNMP::Info::new() Net-SNMP session creation failed. $sess_err");
return;
}
# Table function store
my $store = {};
# Save Args for later
$new_obj->{store} = $store;
$new_obj->{sess} = $sess;
$new_obj->{args} = \%args;
$new_obj->{snmp_ver} = $args{Version} || 2;
$new_obj->{snmp_comm} = $args{Community} || 'public';
$new_obj->{snmp_user} = $args{SecName} || 'initial';
return $auto_specific ? $new_obj->specify() : $new_obj;
}
=item update()
Replace the existing session with a new one with updated values,
without re-identifying the device. The only supported changes are
to Community or Context.
Clears the object cache.
This is useful, e.g., when a device supports multiple contexts
(via changes to the Community string, or via the SNMPv3 Context
parameter), but a context that you want to access does not support
the objects (e.g., C<sysObjectID>, C<sysDescr>) that we use to identify
the device.
=cut
sub update {
my $obj = shift;
my %update_args = @_;
my %sess_args = ( %{ $obj->{args} }, %update_args );
# silently only update "the right" args
delete $sess_args{Debug};
delete $sess_args{DebugSNMP};
delete $sess_args{AutoSpecify};
delete $sess_args{BulkRepeaters};
delete $sess_args{BulkWalk};
delete $sess_args{LoopDetect};
delete $sess_args{IgnoreNetSNMPConf};
delete $sess_args{BigInt};
delete $sess_args{MibDirs};
my $sess = new SNMP::Session(
'UseEnums' => 1,
%sess_args, 'RetryNoSuch' => $obj->{nosuch}
);
unless ( defined $sess ) {
$obj->error_throw(
"SNMP::Info::update() Failed to Create new Session. ");
return;
}
# Session object created but SNMP connection failed.
my $sess_err = $sess->{ErrorStr} || '';
if ($sess_err) {
$obj->error_throw(
"SNMP::Info::update() Net-SNMP session creation failed. $sess_err"
);
return;
}
$obj->clear_cache();
return $obj->session($sess);
}
=back
=head2 Data is Cached
Methods and subroutines requesting data from a device will only load the data
once, and then return cached versions of that data.
Run $info->load_METHOD() where method is something like 'i_name' to reload
data from a method.
Run $info->clear_cache() to clear the cache to allow reload of both globals
and table methods.
=head2 Object Scalar Methods
These are for package related data, not directly supplied
from SNMP.
=over
=item $info->clear_cache()
Clears the cached data. This includes GLOBALS data and TABLE METHOD data.
=cut
sub clear_cache {
my $self = shift;
print "SNMP::Info::clear_cache() - Cache Cleared.\n" if $self->debug();
# Clear cached global values and table method flag for being cached
foreach my $key ( keys %$self ) {
next unless defined $key;
next unless $key =~ /^_/;
delete $self->{$key};
}
# Clear store for tables
return $self->store( {} );
}
=item $info->debug(1)
Returns current debug status, and optionally toggles debugging info for this
object.
=cut
sub debug {
my $self = shift;
my $debug = shift;
if ( defined $debug ) {
$self->{debug} = $debug;
}
return $self->{debug};
}
=item $info->bulkwalk([1|0])
Returns if bulkwalk is currently turned on for this object.
Optionally sets the bulkwalk parameter.
=cut
sub bulkwalk {
my $self = shift;
my $bw = shift;
if ( defined $bw ) {
$self->{BulkWalk} = $bw;
}
return $self->{BulkWalk};
}
=item $info->loopdetect([1|0])
Returns if loopdetect is currently turned on for this object.
Optionally sets the loopdetect parameter.
=cut
sub loopdetect {
my $self = shift;
my $ld = shift;
if ( defined $ld ) {
$self->{LoopDetect} = $ld;
}
return $self->{LoopDetect};
}
=item $info->device_type()
Returns the Subclass name for this device. C<SNMP::Info> is returned if no
more specific class is available.
First the device is checked for Layer 3 support and a specific subclass,
then Layer 2 support and subclasses are checked.
This means that Layer 2 / 3 switches and routers will fall under the
SNMP::Info::Layer3 subclasses.
If the device still can be connected to via SNMP::Info, then
SNMP::Info is returned.
See L<http://netdisco.org/doc/DeviceMatrix.html> or L<DeviceMatrix.txt> for more details
about device support, or view C<device_type()> in F<Info.pm>.
=cut
sub device_type {
my $info = shift;
my $objtype = "SNMP::Info";
my $layers = $info->layers() || '00000000';
my $desc = $info->description() || 'undef';
$desc =~ s/[\r\n\l]+/ /g;
# Some devices don't implement sysServices, but do return a description.
# In that case, log a warning and continue.
if ( $layers eq '00000000' ) {
if ($desc ne 'undef') {
carp("Device doesn't implement sysServices but did return sysDescr. Might give unexpected results.\n") if $info->debug();
} else {
# No sysServices, no sysDescr
return;
}
}
my $id = $info->id() || 'undef';
my $soid = $id;
# Hash for generic fallback to a device class if unable to determine using
# the sysDescr regex.
my %l3sysoidmap = (
9 => 'SNMP::Info::Layer3::Cisco',
11 => 'SNMP::Info::Layer2::HP',
18 => 'SNMP::Info::Layer3::BayRS',
42 => 'SNMP::Info::Layer3::Sun',
45 => 'SNMP::Info::Layer2::Baystack',
171 => 'SNMP::Info::Layer3::Dell',
244 => 'SNMP::Info::Layer3::Lantronix',
311 => 'SNMP::Info::Layer3::Microsoft',
674 => 'SNMP::Info::Layer3::Dell',
1872 => 'SNMP::Info::Layer3::AlteonAD',
1916 => 'SNMP::Info::Layer3::Extreme',
1991 => 'SNMP::Info::Layer3::Foundry',
2021 => 'SNMP::Info::Layer3::NetSNMP',
2272 => 'SNMP::Info::Layer3::Passport',
2636 => 'SNMP::Info::Layer3::Juniper',
2925 => 'SNMP::Info::Layer1::Cyclades',
3076 => 'SNMP::Info::Layer3::Altiga',
3224 => 'SNMP::Info::Layer3::Netscreen',
3375 => 'SNMP::Info::Layer3::F5',
3417 => 'SNMP::Info::Layer3::BlueCoatSG',
4526 => 'SNMP::Info::Layer2::Netgear',
5624 => 'SNMP::Info::Layer3::Enterasys',
6027 => 'SNMP::Info::Layer3::Force10',
6486 => 'SNMP::Info::Layer3::AlcatelLucent',
6527 => 'SNMP::Info::Layer3::Timetra',
8072 => 'SNMP::Info::Layer3::NetSNMP',
9303 => 'SNMP::Info::Layer3::PacketFront',
12325 => 'SNMP::Info::Layer3::Pf',
14525 => 'SNMP::Info::Layer2::Trapeze',
14988 => 'SNMP::Info::Layer3::Mikrotik',
17163 => 'SNMP::Info::Layer3::Steelhead',
25506 => 'SNMP::Info::Layer3::H3C',
26543 => 'SNMP::Info::Layer3::IBMGbTor',
30065 => 'SNMP::Info::Layer3::Arista',
35098 => 'SNMP::Info::Layer3::Pica8',
);
my %l2sysoidmap = (
9 => 'SNMP::Info::Layer2::Cisco',
11 => 'SNMP::Info::Layer2::HP',
45 => 'SNMP::Info::Layer2::Baystack',
171 => 'SNMP::Info::Layer3::Dell',
207 => 'SNMP::Info::Layer2::Allied',
674 => 'SNMP::Info::Layer3::Dell',
1872 => 'SNMP::Info::Layer3::AlteonAD',
1916 => 'SNMP::Info::Layer3::Extreme',
1991 => 'SNMP::Info::Layer3::Foundry',
2272 => 'SNMP::Info::Layer3::Passport',
2925 => 'SNMP::Info::Layer1::Cyclades',
3224 => 'SNMP::Info::Layer3::Netscreen',
3375 => 'SNMP::Info::Layer3::F5',
4526 => 'SNMP::Info::Layer2::Netgear',
5624 => 'SNMP::Info::Layer3::Enterasys',
6486 => 'SNMP::Info::Layer3::AlcatelLucent',
11898 => 'SNMP::Info::Layer2::Orinoco',
14179 => 'SNMP::Info::Layer2::Airespace',
14525 => 'SNMP::Info::Layer2::Trapeze',
14823 => 'SNMP::Info::Layer3::Aruba',
17163 => 'SNMP::Info::Layer3::Steelhead',
26543 => 'SNMP::Info::Layer3::IBMGbTor',
);
my %l7sysoidmap = (
318 => 'SNMP::Info::Layer7::APC',
5951 => 'SNMP::Info::Layer7::Netscaler',
14525 => 'SNMP::Info::Layer2::Trapeze',
12532 => 'SNMP::Info::Layer7::Neoteris',
);
# Get just the enterprise number for generic mapping
$id = $1 if ( defined($id) && $id =~ /^\.1\.3\.6\.1\.4\.1\.(\d+)/ );
if ($info->debug()) {
print "SNMP::Info $VERSION\n";
print "SNMP::Info::device_type() layers:$layers id:$id sysDescr:\"$desc\"\n";
}
# Layer 3 Supported
# (usually has layer2 as well, so we check for 3 first)
if ( $info->has_layer(3) ) {
$objtype = 'SNMP::Info::Layer3';
# Device Type Overrides
return $objtype unless ( defined $desc and length($desc) );
$objtype = 'SNMP::Info::Layer3::C3550' if $desc =~ /(C3550|C3560)/;
$objtype = 'SNMP::Info::Layer3::C4000' if $desc =~ /Catalyst 4[05]00/;
$objtype = 'SNMP::Info::Layer3::Foundry' if $desc =~ /foundry/i;
# Aironet - older non-IOS
$objtype = 'SNMP::Info::Layer3::Aironet'
if ($desc =~ /Cisco/
and $desc =~ /\D(CAP340|AP340|CAP350|350|1200)\D/ );
$objtype = 'SNMP::Info::Layer3::Aironet'
if ( $desc =~ /Aironet/ and $desc =~ /\D(AP4800)\D/ );
# Cat6k with older SUPs (hybrid CatOS/IOS?)
$objtype = 'SNMP::Info::Layer3::C6500' if $desc =~ /(c6sup2|c6sup1)/;
# Cat6k with Sup720, Sup720 or Sup2T (and Sup2 running native IOS?)
$objtype = 'SNMP::Info::Layer3::C6500'
if $desc =~ /(s72033_rp|s3223_rp|s32p3_rp|s222_rp|s2t54)/;
# Next one untested. Reported working by DA
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /cisco/i and $desc =~ /3750/ );
# IOS 15.x on Catalyst 3850
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /cisco/i and $desc =~ /CAT3K/ );
# Cisco 2970
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /(C2970|C2960)/ );
# Cisco 3400 w/ Layer3 capable image
$objtype = 'SNMP::Info::Layer3::C3550'
if ( $desc =~ /(ME340x)/ );
# Various Cisco blade switches, CBS30x0 and CBS31x0 models
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /cisco/i and $desc =~ /CBS3[0-9A-Za-z]{3}/ );
# Cisco Nexus running NX-OS
$objtype = 'SNMP::Info::Layer3::Nexus'
if ( $desc =~ /^Cisco\s+NX-OS/ );
# HP, older ProCurve models (1600, 2400, 2424m, 4000, 8000)
$objtype = 'SNMP::Info::Layer2::HP4000'
if $desc =~ /\b(J4093A|J4110A|J4120A|J4121A|J4122A|J4122B)\b/;
# HP, Foundry OEM
$objtype = 'SNMP::Info::Layer3::HP9300'
if $desc =~ /\b(J4874A|J4138A|J4139A|J4840A|J4841A)\b/;
# Nortel ERS (Passport) 1600 Series < version 2.1
$objtype = 'SNMP::Info::Layer3::N1600'
if $desc =~ /(Passport|Ethernet\s+Routing\s+Switch)-16/i;
# ERS - BayStack Numbered
$objtype = 'SNMP::Info::Layer2::Baystack'
if ( $desc
=~ /^(BayStack|Ethernet\s+Routing\s+Switch)\s[2345](\d){2,3}/i );
# Nortel Contivity
$objtype = 'SNMP::Info::Layer3::Contivity' if $desc =~ /(\bCES\b|\bNVR\sV\d)/;
# SonicWALL
$objtype = 'SNMP::Info::Layer3::SonicWALL' if $desc =~ /SonicWALL/i;
# Allied Telesis Layer2 managed switches. They report they have L3 support
$objtype = 'SNMP::Info::Layer2::Allied'
if ( $desc =~ /Allied.*AT-80\d{2}\S*/i );
# Cisco ASA, newer versions which report layer 3 functionality
# version >= 8.2 are known to do this
$objtype = 'SNMP::Info::Layer3::CiscoASA'
if ( $desc =~ /Cisco Adaptive Security Appliance/i );
# Cisco FWSM
$objtype = 'SNMP::Info::Layer3::CiscoFWSM'
if ( $desc =~ /Cisco Firewall Services Module/i );
# Avaya Secure Router
$objtype = 'SNMP::Info::Layer3::Tasman'
if ( $desc =~ /^(avaya|nortel)\s+(SR|secure\srouter)\s+\d{4}/i );
# HP Virtual Connect blade switches
$objtype = 'SNMP::Info::Layer2::HPVC'
if ( $desc =~ /HP\sVC\s/ );
# Aironet - IOS
# Starting with IOS 15, Aironet reports sysServices 6, even though
# it still is the same layer2 access point.
$objtype = 'SNMP::Info::Layer2::Aironet'
if ($desc =~ /\b(C1100|C1130|C1140|AP1200|C350|C1200|C1240|C1250)\b/
and $desc =~ /\bIOS\b/ );
# Generic device classification based upon sysObjectID
if ( ( $objtype eq 'SNMP::Info::Layer3' )
and ( defined($id) )
and ( exists( $l3sysoidmap{$id} ) ) )
{
$objtype = $l3sysoidmap{$id};
}
# Layer 2 Supported
}
elsif ( $info->has_layer(2) ) {
$objtype = 'SNMP::Info::Layer2';
return $objtype unless ( defined $desc and $desc !~ /^\s*$/ );
# Device Type Overrides
# Catalyst 1900 series override
$objtype = 'SNMP::Info::Layer2::C1900'
if ( $desc =~ /catalyst/i and $desc =~ /\D19\d{2}/ );
# Catalyst 2900 and 3500XL (IOS) series override
$objtype = 'SNMP::Info::Layer2::C2900'
if ( $desc =~ /(C2900XL|C2950|C3500XL|C2940|CGESM|CIGESM)/i );
# Catalyst WS-C series override 2926,4k,5k,6k in Hybrid
$objtype = 'SNMP::Info::Layer2::Catalyst' if ( $desc =~ /WS-C\d{4}/ );
# Catalyst 3550 / 3548 Layer2 only switches
# Cisco 3400 w/ MetroBase Image
$objtype = 'SNMP::Info::Layer3::C3550'
if ( $desc =~ /(C3550|ME340x)/ );
# Cisco blade switches, CBS30x0 and CBS31x0 models with L2 only
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /cisco/i and $desc =~ /CBS3[0-9A-Za-z]{3}/ );
# Cisco 2970
$objtype = 'SNMP::Info::Layer3::C6500'
if ( $desc =~ /(C2970|C2960)/ );
# Cisco Small Business (300 500) series override
# This is for enterprises(1).cisco(9).otherEnterprises(6).ciscosb(1)
$objtype = 'SNMP::Info::Layer2::CiscoSB'
if ( $soid =~ /^\.1\.3\.6\.1\.4\.1\.9\.6\.1/ );
# HP, older ProCurve models (1600, 2400, 2424m, 4000, 8000)
$objtype = 'SNMP::Info::Layer2::HP4000'
if $desc =~ /\b(J4093A|J4110A|J4120A|J4121A|J4122A|J4122B)\b/;
# HP, Foundry OEM
$objtype = 'SNMP::Info::Layer3::HP9300'
if $desc =~ /\b(J4874A|J4138A|J4139A|J4840A|J4841A)\b/;
# IBM BladeCenter 4-Port GB Ethernet Switch Module
$objtype = 'SNMP::Info::Layer3::Dell'
if ( $desc =~ /^IBM Gigabit Ethernet Switch Module$/ );
# Linksys 2024/2048
$objtype = 'SNMP::Info::Layer3::Dell'
if (
$desc =~ /^(24|48)-Port 10\/100\/1000 Gigabit Switch (with |w\/)WebView$/ );
# Centillion ATM
$objtype = 'SNMP::Info::Layer2::Centillion' if ( $desc =~ /MCP/ );
# BPS
$objtype = 'SNMP::Info::Layer2::Baystack'
if ( $desc =~ /Business\sPolicy\sSwitch/i );
# BayStack Numbered
$objtype = 'SNMP::Info::Layer2::Baystack'
if ( $desc
=~ /^(BayStack|Ethernet\s+(Routing\s+)??Switch)\s[2345](\d){2,3}/i
);
# Kentrox DataSMART DSU/CSU
$objtype = 'SNMP::Info::Layer2::Kentrox'
if ( $desc =~ /^DataSMART/i );
# Nortel Business Ethernet Switch
$objtype = 'SNMP::Info::Layer2::Baystack'
if ( $desc =~ /^Business Ethernet Switch\s[12]\d\d/i );
# Nortel AP 222X
$objtype = 'SNMP::Info::Layer2::NAP222x'
if ( $desc =~ /Access\s+Point\s+222/ );
# Orinoco
$objtype = 'SNMP::Info::Layer2::Orinoco'
if ( $desc =~ /(AP-\d{3}|WavePOINT)/ );
# Aironet - IOS
$objtype = 'SNMP::Info::Layer2::Aironet'
if ($desc =~ /\b(C1100|C1130|C1140|AP1200|C350|C1200|C1240|C1250)\b/
and $desc =~ /\bIOS\b/ );
# Aironet - non IOS
$objtype = 'SNMP::Info::Layer3::Aironet'
if ( $desc =~ /Cisco/ and $desc =~ /\D(BR500)\D/ );
# Airespace (WLC) Module
$objtype = 'SNMP::Info::Layer2::Airespace'
if ( $desc =~ /Cisco Controller/ );
#Nortel 2270
$objtype = 'SNMP::Info::Layer2::N2270'
if (
$desc =~ /Nortel\s+(Networks\s+)??WLAN\s+-\s+Security\s+Switch/ );
# HP Virtual Connect blade switches
$objtype = 'SNMP::Info::Layer2::HPVC'
if ( $desc =~ /HP\sVC\s/ );
# Generic device classification based upon sysObjectID
if ( ( $objtype eq 'SNMP::Info::Layer2' )
and ( defined($id) )
and ( exists( $l2sysoidmap{$id} ) ) )
{
$objtype = $l2sysoidmap{$id};
}
}
elsif ( $info->has_layer(1) ) {
$objtype = 'SNMP::Info::Layer1';
# Allied crap-o-hub
$objtype = 'SNMP::Info::Layer1::Allied' if ( $desc =~ /allied/i );
$objtype = 'SNMP::Info::Layer1::Asante' if ( $desc =~ /asante/i );
# Bay Hub
$objtype = 'SNMP::Info::Layer1::Bayhub'
if ( $desc =~ /\bNMM.*Agent/ );
$objtype = 'SNMP::Info::Layer1::Bayhub'
if ( $desc =~ /\bBay\s*Stack.*Hub/i );
# Synoptics Hub
# This will override Bay Hub only for specific devices supported by this class
$objtype = 'SNMP::Info::Layer1::S3000'
if ( $desc =~ /\bNMM\s+(281|3000|3030)/i );
# These devices don't claim to have Layer1-3 but we like em anyways.
}
else {
$objtype = 'SNMP::Info::Layer2::ZyXEL_DSLAM'
if ( $desc =~ /8-port .DSL Module\(Annex .\)/i );
# Aruba wireless switches
$objtype = 'SNMP::Info::Layer3::Aruba'
if ( $desc =~ /(ArubaOS|AirOS)/ );
# Alcatel-Lucent branded Aruba
$objtype = 'SNMP::Info::Layer3::Aruba'
if ( $desc =~ /^AOS-W/ );
# Cisco PIX
$objtype = 'SNMP::Info::Layer3::Cisco'
if ( $desc =~ /Cisco PIX Security Appliance/i );
# Cisco ASA, older version which doesn't report layer 3 functionality
$objtype = 'SNMP::Info::Layer3::CiscoASA'
if ( $desc =~ /Cisco Adaptive Security Appliance/i );
# HP Virtual Connect blade switches
$objtype = 'SNMP::Info::Layer2::HPVC'
if ( $desc =~ /HP\sVC\s/ );
# Nortel (Trapeze) WSS 2300 Series
$objtype = 'SNMP::Info::Layer2::NWSS2300'
if ( $desc =~ /\bWireless\sSecurity\sSwitch\s23[568][012]\b/);
# Generic device classification based upon sysObjectID
if ( defined($id) and $objtype eq 'SNMP::Info') {
if ( defined $l3sysoidmap{$id} ) {
$objtype = $l3sysoidmap{$id};
} elsif ( defined $l2sysoidmap{$id}) {
$objtype = $l2sysoidmap{$id};
} elsif ( defined $l7sysoidmap{$id}) {
$objtype = $l7sysoidmap{$id};
} elsif ($info->has_layer(7)) {
$objtype = 'SNMP::Info::Layer7'
}
}
}
return $objtype;
}
=item $info->error(no_clear)
Returns Error message if there is an error, or undef if there is not.
Reading the error will clear the error unless you set the no_clear flag.
=cut
sub error {
my $self = shift;
my $no_clear = shift;
my $err = $self->{error};
$self->{error} = undef unless defined $no_clear and $no_clear;
return $err;
}
=item $info->has_layer(3)
Returns non-zero if the device has the supplied layer in the OSI Model
Returns if the device doesn't support the layers() call.
=cut
sub has_layer {
my $self = shift;
my $check_for = shift;
my $layers = $self->layers();
return unless defined $layers;
return unless length($layers);
return substr( $layers, 8 - $check_for, 1 );
}
=item $info->snmp_comm()
Returns SNMP Community string used in connection.
=cut
sub snmp_comm {
my $self = shift;
if ( $self->{snmp_ver} == 3 ) {
return $self->{snmp_user};
}
else {
return $self->{snmp_comm};
}
}
=item $info->snmp_ver()
Returns SNMP Version used for this connection
=cut
sub snmp_ver {
my $self = shift;
return $self->{snmp_ver};
}
=item $info->specify()
Returns an object of a more-specific subclass.
my $info = new SNMP::Info(...);
# Returns more specific object type
$info = $info->specific();
Usually this method is called internally from new(AutoSpecify => 1)
See device_type() entry for how a subclass is chosen.
=cut
sub specify {
my $self = shift;
my $device_type = $self->device_type();
unless ( defined $device_type ) {
$self->error_throw(
"SNMP::Info::specify() - Could not get info from device");
return;
}
return $self if $device_type eq 'SNMP::Info';
# Load Subclass
# By evaling a string the contents of device_type now becomes a bareword.
eval "require $device_type;"; ## no critic
if ($@) {
croak "SNMP::Info::specify() Loading $device_type Failed. $@\n";
}
my $args = $self->args();
my $session = $self->session();
my $sub_obj = $device_type->new(
%$args,
'Session' => $session,
'AutoSpecify' => 0
);
unless ( defined $sub_obj ) {
$self->error_throw(
"SNMP::Info::specify() - Could not connect with new class ($device_type)"
);
return $self;
}
$self->debug()
and print "SNMP::Info::specify() - Changed Class to $device_type.\n";
return $sub_obj;
}
=item $info->cisco_comm_indexing()
Returns 0. Is an overridable method used for vlan indexing for
snmp calls on certain Cisco devices.
See L<ftp://ftp.cisco.com/pub/mibs/supportlists/wsc5000/wsc5000-communityIndexing.html>
=cut
sub cisco_comm_indexing {
return 0;
}
=back
=head2 Globals (Scalar Methods)
These are methods to return scalar data from RFC1213.
Some subset of these is probably available for any network device that speaks
SNMP.
=over
=item $info->uptime()
Uptime in hundredths of seconds since device became available.
(C<sysUpTime>)
=item $info->contact()
(C<sysContact>)
=item $info->name()
(C<sysName>)
=item $info->location()
(C<sysLocation>)
=item $info->layers()
This returns a binary encoded string where each
digit represents a layer of the OSI model served
by the device.
eg: 01000010 means layers 2 (physical) and 7 (Application)
are served.
Note: This string is 8 digits long.
See $info->has_layer()
(C<sysServices>)
=item $info->ports()
Number of interfaces available on this device.
Not too useful as the number of SNMP interfaces usually does not
correspond with the number of physical ports
(C<ifNumber>)
=item $info->ipforwarding()
The indication of whether the entity is acting as an IP gateway
Returns either forwarding or not-forwarding
(C<ipForwarding>)
=back
=head2 Table Methods
Each of these methods returns a hash_reference to a hash keyed on the
interface index in SNMP.
Example : $info->interfaces() might return
{ '1.12' => 'FastEthernet/0',
'2.15' => 'FastEthernet/1',
'9.99' => 'FastEthernet/2'
}
The key is what you would see if you were to do an snmpwalk, and in some cases
changes between reboots of the network device.
=head2 Partial Table Fetches
If you want to get only a part of an SNMP table or a single instance from the
table and you know the IID for the part of the table that you want, you can
specify it in the call:
$local_routes = $info->ipr_route('192.168.0');
This will only fetch entries in the table that start with C<192.168.0>, which
in this case are routes on the local network.
Remember that you must supply the partial IID (a numeric OID).
Partial table results are not cached.
=head2 Interface Information
=over
=item $info->interfaces()
This methods is overridden in each subclass to provide a
mapping between the Interface Table Index (iid) and the physical port name.
=item $info->if_ignore()
Returns a reference to a hash where key values that exist are
interfaces to ignore.
Ignored interfaces are ones that are usually not physical ports or Virtual
Lans (VLANs) such as the Loopback interface, or the CPU interface.
=cut
sub if_ignore {
my %nothing;
return \%nothing;
}
=item $info->bulkwalk_no()
Returns 0. Is an overridable method used for turn off bulkwalk for the
device class.
=cut
sub bulkwalk_no {
return 0;
}
=item $info->i_index()
Default SNMP IID to Interface index.
(C<ifIndex>)
=item $info->i_description()
Description of the interface. Usually a little longer single word name that is
both human and machine friendly. Not always.
(C<ifDescr>)
=item $info->i_type()
Interface type, such as Vlan, Ethernet, Serial
(C<ifType>)
=item $info->i_mtu()
INTEGER. Interface MTU value.
(C<ifMtu>)
=item $info->i_speed()
Speed of the link, human format. See munge_speed() later in document for
details.
(C<ifSpeed>, C<ifHighSpeed> if necessary)
=cut
sub i_speed {
my $info = shift;
my $partial = shift;
my $i_speed = $info->orig_i_speed($partial);
my $i_speed_high = undef;
foreach my $i ( keys %$i_speed ) {
if ( $i_speed->{$i} eq "4294967295" ) {
$i_speed_high = $info->i_speed_high($partial)
unless defined($i_speed_high);
$i_speed->{$i} = $i_speed_high->{$i} if ( $i_speed_high->{$i} );
}
}
return $i_speed;
}
=item $info->i_speed_raw()
Speed of the link in bits per second without munging.
If i_speed_high is available it will be used and multiplied by 1_000_000.
(C<ifSpeed>, C<ifHighSpeed> if necessary)
=cut
sub i_speed_raw {
my $info = shift;
my $partial = shift;
# remove the speed formating
my $munge_i_speed = delete $info->{munge}{i_speed};
# also for highspeed interfaces e.g. TenGigabitEthernet
my $munge_i_speed_high = delete $info->{munge}{i_speed_high};
my $i_speed_raw = $info->orig_i_speed($partial);
my $i_speed_high = undef;
foreach my $i ( keys %$i_speed_raw ) {
if ( $i_speed_raw->{$i} eq "4294967295" ) {
$i_speed_high = $info->i_speed_high($partial)
unless defined($i_speed_high);
$i_speed_raw->{$i} = ( $i_speed_high->{$i} * 1_000_000 )
if ( $i_speed_high->{$i} );
}
}
# restore the speed formating
$info->{munge}{i_speed} = $munge_i_speed;
$info->{munge}{i_speed_high} = $munge_i_speed_high;
return $i_speed_raw;
}
=item $info->i_speed_high()
Speed of a high-speed link, human format. See munge_highspeed() later in
document for details. You should not need to call this directly, as
i_speed() will call it if it needs to.
(C<ifHighSpeed>)
=item $info->i_mac()
MAC address of the interface. Note this is just the MAC of the port, not
anything connected to it.
(C<ifPhysAddress>)
=item $info->i_up()
Link Status of the interface. Typical values are 'up' and 'down'.
(C<ifOperStatus>)
=item $info->i_up_admin()
Administrative status of the port. Typical values are 'enabled' and 'disabled'.
(C<ifAdminStatus>)
=item $info->i_lastchange()
The value of C<sysUpTime> when this port last changed states (up,down).
(C<ifLastChange>)
=item $info->i_name()
Interface Name field. Supported by a smaller subset of devices, this fields
is often human set.
(C<ifName>)
=item $info->i_alias()
Interface Name field. For certain devices this is a more human friendly form
of i_description(). For others it is a human set field like i_name().
(C<ifAlias>)
=back
=head2 Interface Statistics
=over
=item $info->i_octet_in(), $info->i_octets_out(),
$info->i_octet_in64(), $info->i_octets_out64()
Bandwidth.
Number of octets sent/received on the interface including framing characters.
64 bit version may not exist on all devices.
NOTE: To manipulate 64 bit counters you need to use Math::BigInt, since the
values are too large for a normal Perl scalar. Set the global
$SNMP::Info::BIGINT to 1 , or pass the BigInt value to new() if you want
SNMP::Info to do it for you.
(C<ifInOctets>) (C<ifOutOctets>)
(C<ifHCInOctets>) (C<ifHCOutOctets>)
=item $info->i_errors_in(), $info->i_errors_out()
Number of packets that contained an error preventing delivery. See C<IF-MIB>
for more info.
(C<ifInErrors>) (C<ifOutErrors>)
=item $info->i_pkts_ucast_in(), $info->i_pkts_ucast_out(),
$info->i_pkts_ucast_in64(), $info->i_pkts_ucast_out64()
Number of packets not sent to a multicast or broadcast address.
64 bit version may not exist on all devices.
(C<ifInUcastPkts>) (C<ifOutUcastPkts>)
(C<ifHCInUcastPkts>) (C<ifHCOutUcastPkts>)
=item $info->i_pkts_nucast_in(), $info->i_pkts_nucast_out(),
Number of packets sent to a multicast or broadcast address.
These methods are deprecated by i_pkts_multi_in() and i_pkts_bcast_in()
according to C<IF-MIB>. Actual device usage may vary.
(C<ifInNUcastPkts>) (C<ifOutNUcastPkts>)
=item $info->i_pkts_multi_in() $info->i_pkts_multi_out(),
$info->i_pkts_multi_in64(), $info->i_pkts_multi_out64()
Number of packets sent to a multicast address.
64 bit version may not exist on all devices.
(C<ifInMulticastPkts>) (C<ifOutMulticastPkts>)
(C<ifHCInMulticastPkts>) (C<ifHCOutMulticastPkts>)
=item $info->i_pkts_bcast_in() $info->i_pkts_bcast_out(),
$info->i_pkts_bcast_in64() $info->i_pkts_bcast_out64()
Number of packets sent to a broadcast address on an interface.
64 bit version may not exist on all devices.
(C<ifInBroadcastPkts>) (C<ifOutBroadcastPkts>)
(C<ifHCInBroadcastPkts>) (C<ifHCOutBroadcastPkts>)
=item $info->i_discards_in() $info->i_discards_out()
"The number of inbound packets which were chosen to be discarded even though
no errors had been detected to prevent their being deliverable to a
higher-layer protocol. One possible reason for discarding such a packet could
be to free up buffer space." (C<IF-MIB>)
(C<ifInDiscards>) (C<ifOutDiscards>)
=item $info->i_bad_proto_in()
"For packet-oriented interfaces, the number of packets received via the
interface which were discarded because of an unknown or unsupported protocol.
For character-oriented or fixed-length interfaces that support protocol
multiplexing the number of transmission units received via the interface which
were discarded because of an unknown or unsupported protocol. For any
interface that does not support protocol multiplexing, this counter will always
be 0."
(C<ifInUnknownProtos>)
=item $info->i_qlen_out()
"The length of the output packet queue (in packets)."
(C<ifOutQLen>)
=item $info->i_specific()
See C<IF-MIB> for full description
(C<ifSpecific>)
=back
=head2 IP Address Table
Each entry in this table is an IP address in use on this device. Usually
this is implemented in Layer3 Devices.
=over
=item $info->ip_index()
Maps the IP Table to the IID
(C<ipAdEntIfIndex>)
=item $info->ip_table()
Maps the Table to the IP address
(C<ipAdEntAddr>)
=item $info->ip_netmask()
Gives netmask setting for IP table entry.
(C<ipAdEntNetMask>)
=item $info->ip_broadcast()
Gives broadcast address for IP table entry.
(C<ipAdEntBcastAddr>)
=back
=head2 IP Routing Table
=over
=item $info->ipr_route()
The route in question. A value of 0.0.0.0 is the default gateway route.
(C<ipRouteDest>)
=item $info->ipr_if()
The interface (IID) that the route is on. Use interfaces() to map.
(C<ipRouteIfIndex>)
=item $info->ipr_1()
Primary routing metric for this route.
(C<ipRouteMetric1>)
=item $info->ipr_2()
If metrics are not used, they should be set to -1
(C<ipRouteMetric2>)
=item $info->ipr_3()
(C<ipRouteMetric3>)
=item $info->ipr_4()
(C<ipRouteMetric4>)
=item $info->ipr_5()
(C<ipRouteMetric5>)
=item $info->ipr_dest()
From RFC1213:
"The IP address of the next hop of this route.
(In the case of a route bound to an interface
which is realized via a broadcast media, the value
of this field is the agent's IP address on that
interface.)"
(C<ipRouteNextHop>)
=item $info->ipr_type()
From RFC1213:
other(1), -- none of the following
invalid(2), -- an invalidated route
-- route to directly
direct(3), -- connected (sub-)network
-- route to a non-local
indirect(4) -- host/network/sub-network
"The type of route. Note that the values
direct(3) and indirect(4) refer to the notion of
direct and indirect routing in the IP
architecture.
Setting this object to the value invalid(2) has
the effect of invalidating the corresponding entry
in the ipRouteTable object. That is, it
effectively disassociates the destination
identified with said entry from the route
identified with said entry. It is an
implementation-specific matter as to whether the
agent removes an invalidated entry from the table.
Accordingly, management stations must be prepared
to receive tabular information from agents that
corresponds to entries not currently in use.
Proper interpretation of such entries requires
examination of the relevant ipRouteType object."
(C<ipRouteType>)
=item $info->ipr_proto()
From RFC1213:
other(1), -- none of the following
-- non-protocol information,
-- e.g., manually configured
local(2), -- entries
-- set via a network
netmgmt(3), -- management protocol
-- obtained via ICMP,
icmp(4), -- e.g., Redirect
-- the remaining values are
-- all gateway routing
-- protocols
egp(5),
ggp(6),
hello(7),
rip(8),
is-is(9),
es-is(10),
ciscoIgrp(11),
bbnSpfIgp(12),
ospf(13),
bgp(14)
(C<ipRouteProto>)
=item $info->ipr_age()
Seconds since route was last updated or validated.
(C<ipRouteAge>)
=item $info->ipr_mask()
Subnet Mask of route. 0.0.0.0 for default gateway.
(C<ipRouteMask>)
=item $info->ipr_info()
Reference to MIB definition specific to routing protocol.
(C<ipRouteInfo>)
=back
=head2 Topology Information
Based upon the manufacturer and software version devices may support some
combination of Layer 2 topology protocol information. SNMP::Info
supports querying Link Layer Discovery Protocol (LLDP), Cisco Discovery
Protocol (CDP), SynOptics/Bay/Nortel/Avaya Network Management Protocol
(SONMP), Foundry/Brocade Discovery Protocol (FDP), Extreme Discovery
Protocol (EDP), and Alcatel Mapping Adjacency Protocol (AMAP).
For protocol specific information and implementation:
=over
=item LLDP: See L<SNMP::Info::LLDP> for details.
=item CDP: See L<SNMP::Info::CDP> for details.
=item SONMP: See L<SNMP::Info::SONMP> for details.
=item FDP: See L<SNMP::Info::FDP> for details.
=item EDP: See L<SNMP::Info::EDP> for details.
=item AMAP: See L<SNMP::Info::AMAP> for details.
=back
=head3 Topology Capabilities
=over
=item $info->has_topo()
Reports Layer 2 topology protocols which are supported and running on
a device.
Returns either a reference to an array of protocols, possible values
being: C<lldp>, C<cdp>, C<sonmp>, C<fdp>, C<edp>, C<amap> or C<undef> if
no protocols are supported or running.
=back
=cut
sub has_topo {
my $self = shift;
my @topo_cap;
push( @topo_cap, 'lldp' )
if ( $self->can('hasLLDP') && $self->hasLLDP() );
push( @topo_cap, 'cdp' ) if $self->can('hasCDP') && $self->hasCDP();
push( @topo_cap, 'sonmp' )
if $self->can('hasSONMP') && $self->hasSONMP();
push( @topo_cap, 'fdp' ) if $self->can('hasFDP') && $self->hasFDP();
push( @topo_cap, 'edp' ) if $self->can('hasEDP') && $self->hasEDP();
push( @topo_cap, 'amap' ) if $self->can('hasAMAP') && $self->hasAMAP();
if (@topo_cap) {
return \@topo_cap;
}
else {
return;
}
}
sub _get_topo_data {
my $self = shift;
my $partial = shift;
my $topo_cap = shift;
my $method = shift;
return unless $method =~ /(ip|if|port|id|platform|cap)/;
my %t_data;
foreach my $proto (@$topo_cap) {
next unless $proto =~ /(lldp|cdp|sonmp|fdp|edp|amap)/;
my $method_name = "$proto" . "_$method";
my $cdp = $self->$method_name($partial) || {};
foreach my $iid ( keys %$cdp ) {
my $ip = $cdp->{$iid};
next unless defined $ip;
$t_data{$iid} = $ip;
}
}
return \%t_data;
}
=head3 Common Topology Table Information
The common topology table methods below will query the
device for information from the specified topology protocols and return a
single hash combining all information. As a result, there may be identical
topology information returned from the two protocols causing duplicate
entries. It is the calling program's responsibility to identify any
duplicate entries and remove duplicates if necessary. If it is necessary
to understand which protocol provided the information, utilize the protocol
specific methods directly rather than the generic methods.
The methods support partial table fetches by providing a partial as the
first argument.
If a reference to an array is provided as the second argument, those
protocols will be queried for information. The supported array values are:
C<lldp>, C<cdp>, C<sonmp>, C<fdp>, C<edp>, C<amap>.
If nothing is passed in as the second argument, the methods will call
has_topo() to determine supported and running topology protocols on the
device.
=over
=item $info->c_ip(partial, topology_protocol_arrayref)
Returns reference to hash. Key: iid, Value: remote IPv4 address
If multiple entries exist with the same local port, c_if(), with the
same IPv4 address, c_ip(), it may be a duplicate entry.
If multiple entries exist with the same local port, c_if(), with different
IPv4 addresses, c_ip(), there is either a device in between two or
more devices utilizing a different topology protocol or multiple devices
which are not directly connected.
Use the protocol specific methods to dig deeper.
=cut
sub c_ip {
my $self = shift;
my $partial = shift;
my $topo_cap = shift;
# Default to old behavior if not called with topo_cap
if ( !$topo_cap ) {
my $topo_test = $self->has_topo();
if ($topo_test) {
$topo_cap = $topo_test;
}
else {
return;
}
}
return _get_topo_data ($self, $partial, $topo_cap, 'ip');
}
=item $info->c_if(partial, topology_protocol_arrayref)
Returns reference to hash. Key: iid, Value: local device port (interfaces)
=cut
sub c_if {
my $self = shift;
my $partial = shift;
my $topo_cap = shift;
# Default to old behavior if not called with topo_cap
if ( !$topo_cap ) {
my $topo_test = $self->has_topo();
if ($topo_test) {
$topo_cap = $topo_test;
}
else {
return;
}
}
return _get_topo_data ($self, $partial, $topo_cap, 'if');
}
=item $info->c_port(partial, topology_protocol_arrayref)
Returns reference to hash. Key: iid, Value: remote port (interfaces)
=cut
sub c_port {
my $self = shift;
my $partial = shift;
my $topo_cap = shift;
# Default to old behavior if not called with topo_cap
if ( !$topo_cap ) {
my $topo_test = $self->has_topo();
if ($topo_test) {
$topo_cap = $topo_test;
}
else {
return;
}
}
return _get_topo_data ($self, $partial, $topo_cap, 'port');
}
=item $info->c_id(partial, topology_protocol_arrayref)
Returns reference to hash. Key: iid, Value: string value used to identify the
chassis component associated with the remote system.
Note: SONMP does not return this information.
=cut
sub c_id {
my $self = shift;
my $partial = shift;
my $topo_cap = shift;
# Default to old behavior if not called with topo_cap
if ( !$topo_cap ) {
my $topo_test = $self->has_topo();
if ($topo_test) {
$topo_cap = $topo_test;
}
else {
return;
}
}
return _get_topo_data ($self, $partial, $topo_cap, 'id');
}
=item $info->c_platform(partial, topology_protocol_arrayref)
Returns reference to hash. Key: iid, Value: Remote Device Type
Note: EDP does not provide this information. LLDP uses (C<lldpRemSysDesc>)
or C<lldp_rem_sysname> as the closest match.
=cut
sub c_platform {
my $self = shift;
my $partial = shift;
my $topo_cap = shift;
# Default to old behavior if not called with topo_cap
if ( !$topo_cap ) {
my $topo_test = $self->has_topo();
if ($topo_test) {
$topo_cap = $topo_test;
}
else {
return;
}
}
return _get_topo_data ($self, $partial, $topo_cap, 'platform');
}
=item $info->c_cap(partial, topology_protocol_arrayref)
Returns reference to hash of arrays. Key: iid, Value: Array of capabilities
supported by the device. See the specific protocol class for string values
which could be elements within the array.
Note: Only CDP and LLDP support this method.
=cut
sub c_cap {
my $self = shift;
my $partial = shift;
my $topo_cap = shift;
# Default to old behavior if not called with topo_cap
if ( !$topo_cap ) {
my $topo_test = $self->has_topo();
if ($topo_test) {
$topo_cap = $topo_test;
}
else {
return;
}
}
return _get_topo_data ($self, $partial, $topo_cap, 'cap');
}
=back
=head1 SETTING DATA VIA SNMP
This section explains how to use SNMP::Info to do SNMP Set operations.
=over
=item $info->set_METHOD($value)
Sets the global METHOD to value. Assumes that iid is .0
Returns if failed, or the return value from SNMP::Session::set() (snmp_errno)
$info->set_location("Here!");
=item $info->set_METHOD($value,$iid)
Table Methods. Set iid of method to value.
Returns if failed, or the return value from SNMP::Session::set() (snmp_errno)
# Disable a port administratively
my %if_map = reverse %{$info->interfaces()}
$info->set_i_up_admin('down', $if_map{'FastEthernet0/0'})
or die "Couldn't disable the port. ",$info->error(1);
=back
NOTE: You must be connected to your device with a C<ReadWrite> community
string in order for set operations to work.
NOTE: This will only set data listed in %FUNCS and %GLOBALS. For data
acquired from overridden methods (subroutines) specific set_METHOD()
subroutines will need to be added if they haven't been already.
=head1 Quiet Mode
SNMP::Info will not chirp anything to STDOUT unless there is a serious error
(in which case it will probably die).
To get lots of debug info, set the Debug flag when calling new() or
call $info->debug(1);
When calling a method check the return value. If the return value is undef
then check $info->error()
Beware, calling $info->error() clears the error.
my $name = $info->name() or die "Couldn't get sysName!" . $name->error();
=head1 EXTENDING SNMP::INFO
To support a new class (vendor or platform) of device, add a Perl package with
the data structures and methods listed below.
If this seems a little scary, then the SNMP::Info developers are usually happy
to accept the SNMP data from your device and make an attempt at the class
themselves. Usually a "beta" release will go to CPAN for you to verify the
implementation.
=head2 Gathering MIB data for SNMP::Info Developers
The preference is to open a feature request in the SourceForge project. This
allows all developers to have visibility into the request. Please include
pointers to the applicable platform MIBs. For development we will need an
C<snmpwalk> of the device. There is a tool now included in the SNMP::Info
distribution to help with this task, although you'll most likely need to
download the distribution from CPAN as it's included in the "C<t/util>"
directory.
The utility is named C<make_snmpdata.pl>. Run it with a command line like:
./make_snmpdata.pl -c community -i -d device_ip \
-m /home/netdisco-mibs/rfc:/home/netdisco-mibs/net-snmp:/home/netdisco-mibs/dir3 \
SNMPv2-MIB IF-MIB EtherLike-MIB BRIDGE-MIB Q-BRIDGE-MIB ENTITY-MIB \
POWER-ETHERNET-MIB IPV6-MIB LLDP-MIB DEVICE-SPECIFIC-MIB-NAME(s) > output.txt
This will print to the file every MIB entry with data in a format that the
developers can use to emulate read operations without needing access to the
device. Preference would be to mask any sensitive data in the output, zip the
file, and upload as an attachment to the Sourceforge tracker. However, if you
do not feel comfortable uploading the output to the tracker you could e-mail
it to the developer that has claimed the ticket.
=head2 Data Structures required in new Subclass
A class inheriting this class must implement these data structures :
=over
=item $INIT
Used to flag if the MIBs have been loaded yet.
=cut
$INIT = 0;
=item %GLOBALS
Contains a hash in the form ( method_name => SNMP MIB leaf name )
These are scalar values such as name, uptime, etc.
To resolve MIB leaf name conflicts between private MIBs, you may prefix the
leaf name with the MIB replacing each - (dash) and : (colon) with
an _ (underscore). For example, ALTEON_TIGON_SWITCH_MIB__agSoftwareVersion
would be used as the hash value instead of the net-snmp notation
ALTEON-TIGON-SWITCH-MIB::agSoftwareVersion.
When choosing the name for the methods, be aware that other new
Sub Modules might inherit this one to get it's features. Try to
choose a prefix for methods that will give it's own name space inside
the SNMP::Info methods.
=cut
%GLOBALS = (
# from SNMPv2-MIB
'id' => 'sysObjectID',
'description' => 'sysDescr',
'uptime' => 'sysUpTime',
'contact' => 'sysContact',
'name' => 'sysName',
'location' => 'sysLocation',
'layers' => 'sysServices',
'ports' => 'ifNumber',
'ipforwarding' => 'ipForwarding',
);
=item %FUNCS
Contains a hash in the form ( method_name => SNMP MIB leaf name)
These are table entries, such as the C<ifIndex>
To resolve MIB leaf name conflicts between private MIBs, you may prefix the
leaf name with the MIB replacing each - (dash) and : (colon) with
an _ (underscore). For example, ALTEON_TS_PHYSICAL_MIB__agPortCurCfgPortName
would be used as the hash value instead of the net-snmp notation
ALTEON-TS-PHYSICAL-MIB::agPortCurCfgPortName.
=cut
%FUNCS = (
'interfaces' => 'ifIndex',
'i_name' => 'ifName',
# IF-MIB::IfEntry
'i_index' => 'ifIndex',
'i_description' => 'ifDescr',
'i_type' => 'ifType',
'i_mtu' => 'ifMtu',
'i_speed' => 'ifSpeed',
'i_mac' => 'ifPhysAddress',
'i_up_admin' => 'ifAdminStatus',
'i_up' => 'ifOperStatus',
'i_lastchange' => 'ifLastChange',
'i_octet_in' => 'ifInOctets',
'i_pkts_ucast_in' => 'ifInUcastPkts',
'i_pkts_nucast_in' => 'ifInNUcastPkts',
'i_discards_in' => 'ifInDiscards',
'i_errors_in' => 'ifInErrors',
'i_bad_proto_in' => 'ifInUnknownProtos',
'i_octet_out' => 'ifOutOctets',
'i_pkts_ucast_out' => 'ifOutUcastPkts',
'i_pkts_nucast_out' => 'ifOutNUcastPkts',
'i_discards_out' => 'ifOutDiscards',
'i_errors_out' => 'ifOutErrors',
'i_qlen_out' => 'ifOutQLen',
'i_specific' => 'ifSpecific',
# IF-MIB::IfStackTable
'i_stack_status' => 'ifStackStatus',
# IP Address Table
'ip_index' => 'ipAdEntIfIndex',
'ip_table' => 'ipAdEntAddr',
'ip_netmask' => 'ipAdEntNetMask',
'ip_broadcast' => 'ipAdEntBcastAddr',
# ifXTable - Extension Table
'i_speed_high' => 'ifHighSpeed',
'i_pkts_multi_in' => 'ifInMulticastPkts',
'i_pkts_multi_out' => 'ifOutMulticastPkts',
'i_pkts_bcast_in' => 'ifInBroadcastPkts',
'i_pkts_bcast_out' => 'ifOutBroadcastPkts',
'i_octet_in64' => 'ifHCInOctets',
'i_octet_out64' => 'ifHCOutOctets',
'i_pkts_ucast_in64' => 'ifHCInUcastPkts',
'i_pkts_ucast_out64' => 'ifHCOutUcastPkts',
'i_pkts_multi_in64' => 'ifHCInMulticastPkts',
'i_pkts_multi_out64' => 'ifHCOutMulticastPkts',
'i_pkts_bcast_in64' => 'ifHCInBroadcastPkts',
'i_pkts_bcast_out64' => 'ifHCOutBroadcastPkts',
'i_alias' => 'ifAlias',
# IP Routing Table
'ipr_route' => 'ipRouteDest',
'ipr_if' => 'ipRouteIfIndex',
'ipr_1' => 'ipRouteMetric1',
'ipr_2' => 'ipRouteMetric2',
'ipr_3' => 'ipRouteMetric3',
'ipr_4' => 'ipRouteMetric4',
'ipr_5' => 'ipRouteMetric5',
'ipr_dest' => 'ipRouteNextHop',
'ipr_type' => 'ipRouteType',
'ipr_proto' => 'ipRouteProto',
'ipr_age' => 'ipRouteAge',
'ipr_mask' => 'ipRouteMask',
'ipr_info' => 'ipRouteInfo',
);
=item %MIBS
A list of each mib needed.
('MIB-NAME' => 'itemToTestForPresence')
The value for each entry should be a MIB object to check for to make sure
that the MIB is present and has loaded correctly.
$info->init() will throw an exception if a MIB does not load.
=cut
%MIBS = (
# The "main" MIBs are automagically loaded in Net-SNMP now.
);
=item %MUNGE
A map between method calls (from %FUNCS or %GLOBALS) and subroutine methods.
The subroutine called will be passed the data as it gets it from SNMP and
it should return that same data in a more human friendly format.
Sample %MUNGE:
(my_ip => \&munge_ip,
my_mac => \&munge_mac,
my_layers => \&munge_dec2bin
)
=cut
%MUNGE = (
'ip' => \&munge_ip,
'mac' => \&munge_mac,
'i_mac' => \&munge_mac,
'layers' => \&munge_dec2bin,
'i_speed' => \&munge_speed,
'i_speed_high' => \&munge_highspeed,
'i_octet_in64' => \&munge_counter64,
'i_octet_out64' => \&munge_counter64,
'i_pkts_ucast_in64' => \&munge_counter64,
'i_pkts_ucast_out64' => \&munge_counter64,
'i_pkts_mutli_in64' => \&munge_counter64,
'i_pkts_multi_out64' => \&munge_counter64,
'i_pkts_bcast_in64' => \&munge_counter64,
'i_pkts_bcast_out64' => \&munge_counter64,
'i_up' => \&munge_i_up,
);
=back
=head2 Sample Subclass
Let's make a sample Layer 2 Device subclass. This class
will inherit the Cisco Vlan module as an example.
----------------------- snip --------------------------------
# SNMP::Info::Layer2::Sample
package SNMP::Info::Layer2::Sample;
$VERSION = 0.1;
use strict;
use Exporter;
use SNMP::Info::Layer2;
use SNMP::Info::CiscoVTP;
@SNMP::Info::Layer2::Sample::ISA = qw/SNMP::Info::Layer2
SNMP::Info::CiscoVTP Exporter/;
@SNMP::Info::Layer2::Sample::EXPORT_OK = qw//;
use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/;
%MIBS = (%SNMP::Info::Layer2::MIBS,
%SNMP::Info::CiscoVTP::MIBS,
'SUPER-DOOPER-MIB' => 'supermibobject'
);
%GLOBALS = (%SNMP::Info::Layer2::GLOBALS,
%SNMP::Info::CiscoVTP::GLOBALS,
'name' => 'supermib_supername',
'favorite_color' => 'supermib_fav_color_object',
'favorite_movie' => 'supermib_fav_movie_val'
);
%FUNCS = (%SNMP::Info::Layer2::FUNCS,
%SNMP::Info::CiscoVTP::FUNCS,
# Super Dooper MIB - Super Hero Table
'super_hero_index' => 'SuperHeroIfIndex',
'super_hero_name' => 'SuperHeroIfName',
'super_hero_powers' => 'SuperHeroIfPowers'
);
%MUNGE = (%SNMP::Info::Layer2::MUNGE,
%SNMP::Info::CiscoVTP::MUNGE,
'super_hero_powers' => \&munge_powers
);
# OverRide uptime() method from %SNMP::Info::GLOBALS
sub uptime {
my $sample = shift;
my $name = $sample->name();
# this is silly but you get the idea
return '600' if defined $name ;
}
# Create our own munge function
sub munge_powers {
my $power = shift;
# Take the returned obscure value and return something useful.
return 'Fire' if $power =~ /reallyhot/i;
return 'Ice' if $power =~ /reallycold/i;
# Else
return $power;
}
# Copious Documentation here!!!
=head1 NAME
=head1 AUTHOR
=head1 SYNOPSIS
=head1 DESCRIPTION
=head2 Inherited Classes
=head2 Required MIBs
=head1 GLOBALS
=head2 Overrides
=head1 TABLE METHODS
=head2 Overrides
=cut
1; # don't forget this line
----------------------- snip --------------------------------
Be sure and send the debugged version to snmp-info-users@lists.sourceforge.net to be
included in the next version of SNMP::Info.
=head1 SNMP::INFO INTERNALS
=head2 Object Namespace
Internal data is stored with bareword keys. For example $info->{debug}
SNMP Data is stored or marked cached with keys starting with an underscore.
For example $info->{_name} is the cache for $info->name().
Cached Table data is stored in $info->store() and marked cached per above.
=head2 Package Globals
These set the default value for an object upon creation.
=over
=item $DEBUG
Default 0. Sends copious debug info to stdout. This global sets the object's
debug status in new() unless 'Debug' argument passed in new(). Change
objects' debug status with $info->debug().
=cut
$DEBUG = 0;
=item $BIGINT
Default 0. Set to true to have 64 bit counters return Math::BigInt objects
instead of scalar string values. See note under Interface Statistics about
64 bit values.
=cut
$BIGINT = 0;
=item $NOSUCH
Default 1. Set to false to disable RetryNoSuch option for SNMP::Session. Or
see method in new() to do it on an object scope.
=cut
$NOSUCH = 1;
=item $REPEATERS
Default 20. MaxRepeaters for BULKWALK operations. See C<perldoc SNMP> for
more info. Can change by passing L<BulkRepeaters> option in new()
=cut
$REPEATERS = 20;
=back
=head2 Data Munging Callback Subroutines
=over
=item munge_speed()
Makes human friendly speed ratings using %SPEED_MAP
%SPEED_MAP = (
'56000' => '56 kbps',
'64000' => '64 kbps',
'115000' => '115 kpbs',
'1500000' => '1.5 Mbps',
'1536000' => 'T1',
'1544000' => 'T1',
'2000000' => '2.0 Mbps',
'2048000' => '2.048 Mbps',
'3072000' => 'Dual T1',
'3088000' => 'Dual T1',
'4000000' => '4.0 Mbps',
'10000000' => '10 Mbps',
'11000000' => '11 Mbps',
'20000000' => '20 Mbps',
'16000000' => '16 Mbps',
'16777216' => '16 Mbps',
'44210000' => 'T3',
'44736000' => 'T3',
'45000000' => '45 Mbps',
'45045000' => 'DS3',
'46359642' => 'DS3',
'51850000' => 'OC-1',
'54000000' => '54 Mbps',
'64000000' => '64 Mbps',
'100000000' => '100 Mbps',
'149760000' => 'ATM on OC-3',
'155000000' => 'OC-3',
'155519000' => 'OC-3',
'155520000' => 'OC-3',
'400000000' => '400 Mbps',
'599040000' => 'ATM on OC-12',
'622000000' => 'OC-12',
'622080000' => 'OC-12',
'1000000000' => '1.0 Gbps',
'2488000000' => 'OC-48',
)
Note: high speed interfaces (usually 1 Gbps or faster) have their link
speed in C<ifHighSpeed>. i_speed() automatically determines whether to use
C<ifSpeed> or C<ifHighSpeed>; if the latter is used, the value is munged by
munge_highspeed(). SNMP::Info can return speeds up to terabit levels this way.
=cut
%SPEED_MAP = (
'56000' => '56 kbps',
'64000' => '64 kbps',
'115000' => '115 kpbs',
'1500000' => '1.5 Mbps',
'1536000' => 'T1',
'1544000' => 'T1',
'2000000' => '2.0 Mbps',
'2048000' => '2.048 Mbps',
'3072000' => 'Dual T1',
'3088000' => 'Dual T1',
'4000000' => '4.0 Mbps',
'10000000' => '10 Mbps',
'11000000' => '11 Mbps',
'20000000' => '20 Mbps',
'16000000' => '16 Mbps',
'16777216' => '16 Mbps',
'44210000' => 'T3',
'44736000' => 'T3',
'45000000' => '45 Mbps',
'45045000' => 'DS3',
'46359642' => 'DS3',
'51850000' => 'OC-1',
'54000000' => '54 Mbps',
'64000000' => '64 Mbps',
'100000000' => '100 Mbps',
'149760000' => 'ATM on OC-3',
'155000000' => 'OC-3',
'155519000' => 'OC-3',
'155520000' => 'OC-3',
'400000000' => '400 Mbps',
'599040000' => 'ATM on OC-12',
'622000000' => 'OC-12',
'622080000' => 'OC-12',
'1000000000' => '1.0 Gbps',
'2488000000' => 'OC-48',
);
sub munge_speed {
my $speed = shift;
my $map = $SPEED_MAP{$speed};
#print " $speed -> $map " if (defined $map);
return $map || $speed;
}
=item munge_highspeed()
Makes human friendly speed ratings for C<ifHighSpeed>
=cut
sub munge_highspeed {
my $speed = shift;
my $fmt = "%d Mbps";
if ( $speed > 9999999 ) {
$fmt = "%d Tbps";
$speed /= 1000000;
}
elsif ( $speed > 999999 ) {
$fmt = "%.1f Tbps";
$speed /= 1000000.0;
}
elsif ( $speed > 9999 ) {
$fmt = "%d Gbps";
$speed /= 1000;
}
elsif ( $speed > 999 ) {
$fmt = "%.1f Gbps";
$speed /= 1000.0;
}
return sprintf( $fmt, $speed );
}
=item munge_ip()
Takes a binary IP and makes it dotted ASCII
=cut
sub munge_ip {
my $ip = shift;
return join( '.', unpack( 'C4', $ip ) );
}
=item munge_mac()
Takes an octet stream (HEX-STRING) and returns a colon separated ASCII hex
string.
=cut
sub munge_mac {
my $mac = shift;
return unless defined $mac;
return unless length $mac;
$mac = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $mac ) );
return $mac if $mac =~ /^([0-9A-F][0-9A-F]:){5}[0-9A-F][0-9A-F]$/i;
return;
}
=item munge_prio_mac()
Takes an 8-byte octet stream (HEX-STRING) and returns a colon separated ASCII
hex string.
=cut
sub munge_prio_mac {
my $mac = shift;
return unless defined $mac;
return unless length $mac;
$mac = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $mac ) );
return $mac if $mac =~ /^([0-9A-F][0-9A-F]:){7}[0-9A-F][0-9A-F]$/i;
return;
}
=item munge_octet2hex()
Takes a binary octet stream and returns an ASCII hex string
=cut
sub munge_octet2hex {
my $oct = shift;
return join( '', map { sprintf "%x", $_ } unpack( 'C*', $oct ) );
}
=item munge_dec2bin()
Takes a binary char and returns its ASCII binary representation
=cut
sub munge_dec2bin {
my $num = shift;
return unless defined $num;
#return unless length($num);
$num = unpack( "B32", pack( "N", $num ) );
# return last 8 characters only
$num =~ s/.*(.{8})$/$1/;
return $num;
}
=item munge_bits
Takes a SNMP2 'BITS' field and returns the ASCII bit string
=cut
sub munge_bits {
my $bits = shift;
return unless defined $bits;
return unpack( "B*", $bits );
}
=item munge_counter64
If $BIGINT is set to true, then a Math::BigInt object is returned.
See Math::BigInt for details.
=cut
sub munge_counter64 {
my $counter = shift;
return unless defined $counter;
return $counter unless $BIGINT;
my $bigint = Math::BigInt->new($counter);
return $bigint;
}
=item munge_i_up
Net-SNMP tends to load C<RFC1213-MIB> first, and so ignores the
updated enumeration for C<ifOperStatus> in C<IF-MIB>. This munge
handles the "newer" definitions for the enumeration in IF-MIB.
TODO: Get the precedence of MIBs and overriding of MIB data in Net-SNMP
figured out. Heirarchy/precendence of MIBS in SNMP::Info.
=cut
sub munge_i_up {
my $i_up = shift;
return unless defined $i_up;
my %ifOperStatusMap = ( '4' => 'unknown',
'5' => 'dormant',
'6' => 'notPresent',
'7' => 'lowerLayerDown' );
return $ifOperStatusMap{$i_up} || $i_up;
}
=item munge_port_list
Takes an octet string representing a set of ports and returns a reference
to an array of binary values each array element representing a port.
If the element has a value of '1', then that port is included in the set of
ports; the port is not included if it has a value of '0'.
=cut
sub munge_port_list {
my $oct = shift;
return unless defined $oct;
my $list = [ split( //, unpack( "B*", $oct ) ) ];
return $list;
}
=item munge_null()
Removes control characters from a string
=cut
# munge_null() - removes nulls (\0) and other control characters
sub munge_null {
my $text = shift || return;
$text =~ s/[[:cntrl:]]//g;
return $text;
}
=item munge_e_type()
Takes an OID and return the object name if the right MIB is loaded.
=cut
sub munge_e_type {
my $oid = shift;
my $name = &SNMP::translateObj($oid);
return $name if defined($name);
return $oid;
}
=back
=head2 Internally Used Functions
=over
=item $info->init()
Used internally. Loads all entries in %MIBS.
=cut
sub init {
my $self = shift;
# Get MibDirs if provided
my $mibdirs = $self->{mibdirs} || [];
# SNMP::initMib and SNMP::addMibDirs both look for some initial MIBs
# so if we are not using Net-SNMP configuration files we need to
# specify where the MIBs are before those calls.
# Ignore snmp.conf and snmp.local.conf files if IgnoreNetSNMPConf
# specified
local $ENV{'SNMPCONFPATH'} = '' if $self->{IgnoreNetSNMPConf};
# We need to provide MIBDIRS if we are not getting them from a
# configuration file
my $mibdir = join (':', @$mibdirs);
local $ENV{'MIBDIRS'} = "$mibdir" if $self->{IgnoreNetSNMPConf};
SNMP::initMib;
my $version = $SNMP::VERSION;
my ( $major, $minor, $rev ) = split( '\.', $version );
if ( $major < 5 ) {
# Seems to work under 4.2.0
}
elsif ( $major == 5 and $minor == 0 and $rev < 2 ) {
carp("Net-SNMP 5.0.1 seems to be rather buggy. Upgrade.\n");
# This is a bug in net-snmp 5.0.1 perl module
# see http://groups.google.com/groups?th=47aed6bf7be6a0f5
SNMP::init_snmp("perl");
}
foreach my $d (@$mibdirs) {
next unless -d $d;
print "SNMP::Info::init() - Adding new mibdir:$d\n" if $self->debug();
SNMP::addMibDirs($d);
}
my $mibs = $self->mibs();
foreach my $mib ( keys %$mibs ) {
#print "SNMP::Info::init() - Loading mib:$mib\n" if $self->debug();
SNMP::loadModules("$mib");
unless ( defined $SNMP::MIB{ $mibs->{$mib} } ) {
croak "The $mib did not load. See README for $self->{class}\n";
}
}
return;
}
=item $info->args()
Returns a reference to the argument hash supplied to SNMP::Session
=cut
sub args {
my $self = shift;
return $self->{args};
}
=item $info->class()
Returns the class name of the object.
=cut
sub class {
my $self = shift;
return $self->{class};
}
=item $info->error_throw(error message)
Stores the error message for use by $info->error()
If $info->debug() is true, then the error message is carped too.
=cut
sub error_throw {
my $self = shift;
my $error = shift;
return unless defined $error;
$self->{error} = $error;
if ( $self->debug() ) {
$error =~ s/\n+$//;
carp($error);
}
return;
}
=item $info->funcs()
Returns a reference to the %FUNCS hash.
=cut
sub funcs {
my $self = shift;
return $self->{funcs};
}
=item $info->globals()
Returns a reference to the %GLOBALS hash.
=cut
sub globals {
my $self = shift;
return $self->{globals};
}
=item $info->mibs()
Returns a reference to the %MIBS hash.
=cut
sub mibs {
my $self = shift;
return $self->{mibs};
}
=item $info->munge()
Returns a reference of the %MUNGE hash.
=cut
sub munge {
my $self = shift;
return $self->{munge};
}
=item $info->nosuch()
Returns NoSuch value set or not in new()
=cut
sub nosuch {
my $self = shift;
return $self->{nosuch};
}
=item $info->session()
Gets or Sets the SNMP::Session object.
=cut
sub session {
my $self = shift;
$self->{sess} = $_[0] if @_;
return $self->{sess};
}
=item $info->store(new_store)
Returns or sets hash store for Table functions.
Store is a hash reference in this format :
$info->store = { attribute => { iid => value , iid2 => value2, ... } };
=cut
sub store {
my $self = shift;
$self->{store} = $_[0] if @_;
return $self->{store};
}
=item $info->_global()
Used internally by AUTOLOAD to create dynamic methods from %GLOBALS or a
single instance MIB Leaf node name from a loaded MIB.
Example: $info->name() on the first call dispatches to AUTOLOAD() which
calls $info->_global('name') creating the method name().
These methods return data as a scalar.
=cut
sub _global {
my $method = shift;
my $oid = shift;
return sub {
my $self = shift;
my $sess = $self->session();
return unless defined $sess;
my $load = $method =~ /^load/;
my $raw = $method =~ /raw$/;
my $attr = $method;
$attr =~ s/^(load|orig)_//;
$attr =~ s/_raw$//;
# Return cached data unless loading
# We now store in raw format so munge before returning
# unless expecting raw data
if ( defined $self->{"_$attr"} && !$load ) {
my $val = $self->{"_$attr"};
if ( !$raw ) {
return $self->_munge($attr, $val);
} else{
return $val;
}
}
if ( $self->debug() ) {
# Let's get the MIB Module and leaf name along with the OID
my $qual_leaf = SNMP::translateObj($oid,0,1) || '';
print "SNMP::Info::_global $method : $qual_leaf : $oid\n";
}
my $val = $sess->get($oid);
# Mark as gotten. Even if it fails below, we don't want to keep failing.
$self->{"_$attr"} = undef;
if ( $sess->{ErrorStr} ) {
$self->error_throw(
"SNMP::Info::_global($method) $sess->{ErrorStr}");
return;
}
if ( defined $val and $val eq 'NOSUCHOBJECT' ) {
$self->error_throw("SNMP::Info::_global($method) NOSUCHOBJECT");
return;
}
if ( defined $val and $val eq 'NOSUCHINSTANCE' ) {
$self->error_throw("SNMP::Info::_global($method) NOSUCHINSTANCE");
return;
}
# Save Cached Value
$self->_cache($attr, $val);
# Data Munging
if ( !$raw ) {
$val = $self->_munge($attr, $val);
}
return $val;
}
}
=item $info->_set(attr,val,iid,type)
Used internally by set_multi() to run an SNMP set command. When run
clears attr cache.
Attr can be passed as either a scalar or a reference to an array or array
of arrays when used with set_multi().
Example: $info->set_name('dog',3) uses autoload to resolve to
$info->_set('name','dog',3);
=cut
sub _set {
my ( $self, $attr, $val, $iid, $type ) = @_;
my $varbind_list_ref;
if ( !ref($attr) ) {
$varbind_list_ref = [ [ $attr, $iid, $val, $type ] ];
}
elsif ( ref($attr) =~ /ARRAY/ ) {
$varbind_list_ref = [$attr];
$varbind_list_ref = $attr if ref( $$attr[0] ) =~ /ARRAY/;
}
else {
$self->error_throw(
"SNMP::Info::_set($attr,$val) - Failed. Invalid argument for attr."
);
}
my $sess = $self->session();
return unless defined $sess;
my $funcs = $self->funcs();
my $globals = $self->globals();
foreach my $var_list (@$varbind_list_ref) {
my $list_attr = $var_list->[0];
my $list_iid = $var_list->[1];
my $list_val = $var_list->[2];
# Get rid of non-printable chars in $list_val for debug statements
$list_val =~ s/\W//;
# Instance is 0 for scalars without a supplied instance
$var_list->[1] = $list_iid = defined $list_iid ? $list_iid : '0';
# Check if this method is from a sub or from the tables.
if ( $self->can($list_attr) ) {
$self->error_throw(
"SNMP::Info::_set($list_attr,$list_val) - Failed. $list_attr is generated in a sub(). set_$list_attr sub required."
);
# if sub set_attr() existed, we wouldn't have gotten this far.
return;
}
# Lookup oid
my $oid = undef;
$oid = $list_attr if SNMP::translateObj($list_attr);
$oid = $globals->{$list_attr} if defined $globals->{$list_attr};
$oid = $funcs->{$list_attr} if defined $funcs->{$list_attr};
unless ( defined $oid ) {
$self->error_throw(
"SNMP::Info::_set($list_attr,$list_val) - Failed to find $list_attr in \%GLOBALS or \%FUNCS or loaded MIB."
);
return;
}
# Check for fully qualified attr
if ( $oid =~ /__/ ) {
$oid =~ s/__/::/;
$oid =~ s/_/-/g;
}
$var_list->[0] = $oid;
$self->debug()
and print
"SNMP::Info::_set $list_attr.$list_iid ($oid.$list_iid) = $list_val\n";
delete $self->{"_$list_attr"};
}
my $rv = $sess->set($varbind_list_ref);
if ( $sess->{ErrorStr} ) {
$self->error_throw("SNMP::Info::_set $sess->{ErrorStr}");
return;
}
return $rv;
}
=item $info->_make_setter(val,iid)
Used internally by AUTOLOAD to create dynamic methods from either %GLOBALS,
%FUNCS, or a valid mib leaf from a loaded MIB which runs an SNMP set command.
When run clears the attribute cache.
Example: $info->set_name('dog',3) dispatches to autoload to resolve to
$info->_set('name','dog',3) and _make_setter creates the set_name() method.
=cut
sub _make_setter {
my $method = shift;
my $oid = shift;
return sub {
my $self = shift;
my $val = shift;
my $iid = shift;
my $set_oid = $oid;
my $globals = $self->globals();
my $attr = $method;
$attr =~ s/^set_//;
# The only thing which may give us the iid in $oid should be
# a %GLOBALS entry appended with a number. In that case strip it
# from the OID and use it as $iid
if ( defined $globals->{$attr} && $globals->{$attr} =~ /(\.\d+$)/ ) {
$iid = $1;
$set_oid =~ s/$iid//;
}
# If we don't have $iid now we should be a %GLOBALS entry or single
# instance MIB leaf so default to zero
$iid = defined $iid ? $iid : '.0';
# prepend dot if necessary to $iid
$iid = ".$iid" unless $iid =~ /^\./;
my $sess = $self->session();
return unless defined $sess;
$set_oid .= "$iid";
$self->debug()
and print "SNMP::Info::_set $method$iid ($set_oid) = $val\n";
delete $self->{"_$attr"};
my $rv = $sess->set( $set_oid, $val );
if ( $sess->{ErrorStr} ) {
$self->error_throw("SNMP::Info::_set $sess->{ErrorStr}");
return;
}
return $rv;
}
}
=item $info->set_multi(arrayref)
Used to run an SNMP set command on several new values in the one request.
Returns the result of $info->_set(method).
Pass either a reference to a 4 element array [<obj>, <iid>, <val>, <type>] or
a reference to an array of 4 element arrays to specify multiple values.
<obj> - One of the following forms:
1) leaf identifier (e.g., C<'sysContact'>)
2) An entry in either %FUNCS, %GLOBALS (e.g., 'contact')
<iid> - The dotted-decimal, instance identifier. For scalar MIB objects
use '0'
<val> - The SNMP data value being set (e.g., 'netdisco')
<type> - Optional as the MIB should be loaded.
If one of the set assignments is invalid, then the request will be rejected
without applying any of the new values - regardless of the order they appear
in the list.
Example:
my $vlan_set = [
['qb_v_untagged',"$old_vlan_id","$old_untagged_portlist"],
['qb_v_egress',"$new_vlan_id","$new_egress_portlist"],
['qb_v_egress',"$old_vlan_id","$old_egress_portlist"],
['qb_v_untagged',"$new_vlan_id","$new_untagged_portlist"],
['qb_i_vlan',"$port","$new_vlan_id"],
];
$info->set_multi($vlan_set);
=cut
sub set_multi {
my $self = shift;
return $self->_set(@_);
}
=item $info->load_all()
Debugging routine. This does not include any overridden method or method
implemented by subroutine.
Runs $info->load_METHOD() for each entry in $info->funcs();
Returns $info->store() -- See store() entry.
Note return value has changed since version 0.3
=cut
sub load_all {
my $self = shift;
my $sess = $self->session();
return unless defined $sess;
my $funcs = $self->funcs();
foreach my $attrib ( keys %$funcs ) {
$attrib = "load_$attrib";
$self->$attrib();
}
$self->{_all}++;
return unless defined wantarray;
return $self->store();
}
=item $info->all()
Runs $info->load_all() once then returns $info->store();
Use $info->load_all() to reload the data.
Note return value has changed since version 0.3
=cut
sub all {
my $self = shift;
my $sess = $self->session();
return unless defined $sess;
$self->load_all() unless defined $self->{_all};
return $self->store();
}
=item $info->_load_attr()
Used internally by AUTOLOAD to create dynamic methods from %FUNCS
or a MIB Leaf node name contained within a table of a loaded MIB.
Supports partial table fetches and single instance table fetches.
See L<SNMP::Info/"Partial Table Fetches">.
These methods return data as a reference to a hash.
=cut
sub _load_attr {
my $method = shift;
my $oid = shift;
return sub {
my $self = shift;
my $partial = shift;
my $sess = $self->session();
return unless defined $sess;
my $ver = $self->snmp_ver();
my $nosuch = $self->nosuch();
my $store = $self->store();
my $load = $method =~ /^load/;
my $raw = $method =~ /raw$/;
my $attr = $method;
$attr =~ s/^(load|orig)_//;
$attr =~ s/_raw$//;
# Return cached data unless loading or partial
# We now store in raw format so munge before returning
# unless expecting raw data
return $self->_show_attr($attr, $raw)
if ( defined $self->{"_${attr}"}
&& !$load
&& !defined $partial );
# We want the qualified leaf name so that we can
# specify the Module (MIB) in the case of private leaf naming
# conflicts. Example: ALTEON-TIGON-SWITCH-MIB::agSoftwareVersion
# and ALTEON-CHEETAH-SWITCH-MIB::agSoftwareVersion
# Third argument to translateObj specifies the Module prefix
my $qual_leaf = SNMP::translateObj($oid,0,1) || '';
# We still want just the leaf since a SNMP get in the case of a
# partial fetch may strip the Module portion upon return. We need
# the match to make sure we didn't leave the table during getnext
# requests
my ($leaf) = $qual_leaf =~ /::(\w+)$/;
$self->debug()
and print "SNMP::Info::_load_attr $method : $qual_leaf",
defined $partial ? "($partial)" : '', " : $oid" ,
defined $partial ? ".$partial" : '', "\n";
my $var = new SNMP::Varbind( [$qual_leaf, $partial] );
# So devices speaking SNMP v.1 are not supposed to give out
# data from SNMP2, but most do. Net-SNMP, being very precise
# will tell you that the SNMP OID doesn't exist for the device.
# They have a flag RetryNoSuch that is used for get() operations,
# but not for getnext(). We set this flag normally, and if we're
# using V1, let's try and fetch the data even if we get one of those.
my $localstore = undef;
my $errornum = 0;
my %seen = ();
my $vars = [];
my $bulkwalk_no
= $self->can('bulkwalk_no') ? $self->bulkwalk_no() : 0;
my $bulkwalk_on = defined $self->{BulkWalk} ? $self->{BulkWalk} : 1;
my $can_bulkwalk = $bulkwalk_on && !$bulkwalk_no;
my $repeaters = $self->{BulkRepeaters} || $REPEATERS;
my $bulkwalk = $can_bulkwalk && $ver != 1;
my $loopdetect
= defined $self->{LoopDetect} ? $self->{LoopDetect} : 1;
if ( defined $partial ) {
# Try a GET, in case the partial is a leaf OID.
# Would like to only do this if we know the OID is
# long enough; implementing that would require a
# lot of MIB mucking.
my $try = $sess->get($var);
$errornum = $sess->{ErrorNum};
if ( defined($try) && $errornum == 0 && $try !~ /^NOSUCH/ ) {
$var->[2] = $try;
$vars = [$var];
$bulkwalk = 1; # fake a bulkwalk return
}
# We want to execute the while loop below for the getnext request.
if ( $ver == 1
and $sess->{ErrorNum}
and $sess->{ErrorStr} =~ /nosuch/i )
{
$errornum = 0;
}
}
# Use BULKWALK if we can because its faster
if ( $bulkwalk && @$vars == 0 ) {
($vars) = $sess->bulkwalk( 0, $repeaters, $var );
if ( $sess->{ErrorNum} ) {
$self->error_throw(
"SNMP::Info::_load_atrr: BULKWALK " . $sess->{ErrorStr},
"\n" );
return;
}
}
while ( !$errornum ) {
if ($bulkwalk) {
$var = shift @$vars or last;
}
else {
# GETNEXT instead of BULKWALK
$sess->getnext($var);
$errornum = $sess->{ErrorNum};
}
if ( $self->debug() > 1 ) {
use Data::Dumper;
print "SNMP::Info::_load_attr $method : leaf = $oid , var = ",
Dumper($var);
}
# Check if we've left the requested subtree
last if $var->[0] !~ /$leaf$/;
my $iid = $var->[1];
my $val = $var->[2];
unless ( defined $iid ) {
$self->error_throw(
"SNMP::Info::_load_attr: $method not here");
next;
}
# Check to make sure we are still in partial land
if ( defined $partial
and $iid !~ /^$partial$/
and $iid !~ /^$partial\./ )
{
$self->debug()
and print "$iid makes us leave partial land.\n";
last;
}
# Check if last element, V2 devices may report ENDOFMIBVIEW even if
# instance or object doesn't exist.
if ( $val eq 'ENDOFMIBVIEW' ) {
last;
}
# Similarly for SNMPv1 - noSuchName return results in both $iid
# and $val being empty strings.
if ( $val eq '' and $iid eq '' ) {
last;
}
# Another check for SNMPv1 - noSuchName return may results in an $iid
# we've already seen and $val an empty string. If we don't catch
# this here we erronously report a loop below.
if ( defined $seen{$iid} and $seen{$iid} and $val eq '' ) {
last;
}
if ($loopdetect) {
# Check to see if we've already seen this IID (looping)
if ( defined $seen{$iid} and $seen{$iid} ) {
$self->error_throw("Looping on: $method iid:$iid. ");
last;
}
else {
$seen{$iid}++;
}
}
if ( $val eq 'NOSUCHOBJECT' ) {
$self->error_throw(
"SNMP::Info::_load_attr: $method : NOSUCHOBJECT");
next;
}
if ( $val eq 'NOSUCHINSTANCE' ) {
$self->error_throw(
"SNMP::Info::_load_attr: $method : NOSUCHINSTANCE");
next;
}
$localstore->{$iid} = $val;
}
# Cache data if we are not getting partial data:
if ( !defined $partial ) {
$self->_cache($attr, $localstore);
}
# Data Munging
if ( !$raw ) {
$localstore = $self->_munge($attr, $localstore);
}
return $localstore;
}
}
=item $info->_show_attr()
Used internally by AUTOLOAD to return data called by methods listed in %FUNCS.
=cut
sub _show_attr {
my $self = shift;
my $attr = shift;
my $raw = shift;
my $store = $self->store();
if ( !$raw ) {
my $localstore = $store->{$attr};
return $self->_munge($attr, $localstore);
}
else {
return $store->{$attr};
}
}
=item $info->snmp_connect_ip(ip)
Returns true or false based upon snmp connectivity to an IP.
=cut
sub snmp_connect_ip {
my $self = shift;
my $ip = shift;
my $ver = $self->snmp_ver();
my $comm = $self->snmp_comm();
return if ( $ip eq '0.0.0.0' ) or ( $ip =~ /^127\./ );
# Create session object
my $snmp_test = new SNMP::Session(
'DestHost' => $ip,
'Community' => $comm,
'Version' => $ver
);
# No session object created
unless ( defined $snmp_test ) {
return;
}
# Session object created but SNMP connection failed.
my $sess_err = $snmp_test->{ErrorStr} || '';
if ($sess_err) {
return;
}
# Try to get some data from IP
my $layers = $snmp_test->get('sysServices.0');
$sess_err = $snmp_test->{ErrorStr} || '';
if ($sess_err) {
return;
}
return 1;
}
=item modify_port_list(portlist,offset,replacement)
Replaces the specified bit in a port_list array and
returns the packed bitmask
=cut
sub modify_port_list {
my ( $self, $portlist, $offset, $replacement ) = @_;
print "Original port list: @$portlist \n" if $self->debug();
@$portlist[$offset] = $replacement;
# Some devices do not populate the portlist with all possible ports.
# If we have lengthened the list fill all undefined elements with zero.
foreach my $item (@$portlist) {
$item = '0' unless ( defined($item) );
}
print "Modified port list: @$portlist \n" if $self->debug();
return pack( "B*", join( '', @$portlist ) );
}
=item $info->_cache(attr, data)
Cache retrieved data so that if it's asked for again, we use the cache instead
of going back to Net-SNMP. Data is cached inside the blessed hashref C<$self>.
Accepts the leaf and value (scalar, or hashref for a table). Does not return
anything useful.
=cut
sub _cache {
my $self = shift;
my ($attr, $data) = @_;
my $store = $self->store();
if (ref {} eq ref $data) {
$self->{"_${attr}"}++;
$store->{$attr} = $data;
}
else {
$self->{"_$attr"} = $data;
}
}
=item $info->_munge(attr, data)
Raw data returned from Net-SNMP might not be formatted correctly or might have
platform-specific bugs or mistakes. The MUNGE feature of SNMP::Info allows for
fixups to take place.
Accepts the leaf and value (scalar, or hashref for a table) and returns the raw
or the munged data, as appropriate. That is, you do not need to know whether
MUNGE is installed, and it's safe to call this method regardless.
=cut
sub _munge {
my $self = shift;
my ($attr, $data) = @_;
my $munge = $self->munge();
return $data unless defined $munge->{$attr};
if (ref {} eq ref $data) {
my $subref = $munge->{$attr};
my %munged;
foreach my $key ( keys %$data ) {
my $value = $data->{$key};
next unless defined $value;
$munged{$key} = $subref->($value);
}
return \%munged;
}
else {
return unless $data;
my $subref = $munge->{$attr};
return $subref->($data);
}
}
=item _validate_autoload_method(method)
Used internally by AUTOLOAD to validate that a dynamic method should be
created. Returns the OID of the MIB leaf node the method will get or set.
=over
=item 1. Returns unless method is listed in %FUNCS, %GLOBALS, or is MIB Leaf
node name in a loaded MIB for given class.
=item 2. Translates the MIB Leaf node name to an OID.
=item 3. Checks to see if the method access type is allowed for the resolved
OID. Write access for set_ methods, read access for others.
=back
=cut
sub _validate_autoload_method {
my $self = shift;
my $method = shift;
my $setter = $method =~ /^set/;
my $attr = $method;
$attr =~ s/^(load|set|orig)_//;
$attr =~ s/_raw$//;
my $globals = $self->globals();
my $funcs = $self->funcs();
my $leaf_name = $globals->{$attr} || $funcs->{$attr} || $attr;
# Check for fully qualified name
if ( $leaf_name =~ /__/ ) {
$leaf_name =~ s/__/::/;
$leaf_name =~ s/_/-/g;
}
# Translate MIB leaf node name to OID
my $oid = SNMP::translateObj($leaf_name);
if ( $leaf_name =~ /^[.]?\d[\.\d]+$/ ) {
$oid = $leaf_name;
}
unless ( defined $oid ) {
print
"SNMP::Info::_validate_autoload_method($leaf_name) Unable to resolve method.\n"
if $self->debug();
return;
}
# Validate that we have proper access for the operation
my $access = $SNMP::MIB{$oid}{'access'} || '';
# If we were given a fully qualified OID because we don't have the MIB
# file, it will translate above but we won't be able to check access so
# skip the check and return
if ($access) {
unless ( ( $method =~ /^set/ && $access =~ /Write|Create/ )
|| $access =~ /Read|Create/ )
{
print
"SNMP::Info::_validate_autoload_method($attr : $oid) Not accessable for requested operation.\n"
if $self->debug();
return;
}
}
# If the parent of the leaf has indexes it is contained within a table
my $indexes = $SNMP::MIB{$oid}{'parent'}{'indexes'};
my $table_leaf = 0;
if ( !$globals->{$attr}
&& ( defined $indexes && scalar( @{$indexes} ) > 0 ) )
{
$table_leaf = 1;
}
# Tag on .0 for %GLOBALS and single instance MIB leafs unless
# the leaf ends in a digit or we are going to use for a set operation
if ( $table_leaf == 0 && ( $globals->{$attr} || $leaf_name ne $oid ) ) {
unless ( $leaf_name =~ /\d$/ || $setter ) {
$oid .= ".0";
}
}
my $return = [ $oid, $table_leaf ];
return $return;
}
=item $info->can()
Overrides UNIVERSAL::can() so that objects will correctly report their
capabilities to include dynamic methods generated at run time via AUTOLOAD.
Calls parent can() first to see if method exists, if not validates that a
method should be created then dispatches to the appropriate internal method
for creation. The newly created method is inserted into the symbol table
returning to AUTOLOAD only for the initial method call.
Returns undef if the method does not exist and can not be created.
=cut
sub can {
my $self = shift;
my $method = shift;
# use results of parent can()
return $self->SUPER::can($method) if $self->SUPER::can($method);
my $validated = $self->_validate_autoload_method($method);
return unless $validated;
my ($oid, $table) = @$validated;
# _validate_autoload_method validates, so we need to check for
# set_ , funcs, table leafs, and everything else goes to _global
my $funcs = $self->funcs();
# We need to resolve funcs with a prefix or suffix
my $f_method = $method;
$f_method =~ s/^(load|orig)_//;
$f_method =~ s/_raw$//;
no strict 'refs'; ## no critic (ProhibitNoStrict )
# Check for set_ ing.
if ( $method =~ /^set_/ ) {
return *{$AUTOLOAD} = _make_setter( $method, $oid, @_ );
}
elsif ( defined $funcs->{$f_method} || $table ) {
return *{$AUTOLOAD} = _load_attr( $method, $oid, @_ );
}
else {
return *{$AUTOLOAD} = _global( $method, $oid );
}
}
=back
=head2 AUTOLOAD
Each entry in either %FUNCS, %GLOBALS, or MIB Leaf node names present in
loaded MIBs are used by AUTOLOAD() to create dynamic methods. Generated
methods are inserted into the symbol table so that subsequent calls can avoid
AUTOLOAD() and dispatch directly.
=over
=item 1. Returns unless method is listed in %FUNCS, %GLOBALS, or is a MIB
Leaf node name in a loaded MIB for given class.
=item 2. If the method exists in %GLOBALS or is a single instance MIB Leaf
node name from a loaded MIB, _global() generates the method.
=item 3. If a set_ prefix is present _make_setter() generates the method.
=item 4. If the method exists in %FUNCS or is a MIB Leaf node name contained
within a table from a loaded MIB, _load_attr() generates the method.
=item 5. A load_ prefix forces reloading of data and does not use cached data.
=item 6. A _raw suffix returns data ignoring any munge routines.
=back
Override any dynamic method listed in %GLOBALS, %FUNCS, or MIB Leaf node
name a by creating a subroutine with the same name.
For example to override $info->name() create `` sub name {...}'' in your
subclass.
=cut
sub AUTOLOAD {
my $self = shift;
my ($sub_name) = $AUTOLOAD =~ /::(\w+)$/;
return if $sub_name =~ /DESTROY$/;
# Typos in function calls in SNMP::Info subclasses turn into
# AUTOLOAD requests for non-methods. While this is deprecated,
# we'll still get called, so report a less confusing error.
if ( ref($self) !~ /^SNMP::Info/ ) {
# croak reports one level too high. die reports here.
# I would really like to get the place that's likely to
# have the typo, but perl doesn't want me to.
croak(
"SNMP::Info::AUTOLOAD($AUTOLOAD) called with no class (probably typo of function call to $sub_name)"
);
}
# This enables us to use SUPER:: for AUTOLOAD methods as well
# as the true OO methods. Method needs to be renamed to prevent
# namespace collision when we insert into the symbol table later.
if ( $AUTOLOAD =~ /SUPER::$sub_name$/ ) {
$AUTOLOAD =~ s/SUPER::$sub_name/orig_$sub_name/;
$sub_name = "orig_$sub_name";
}
return unless my $meth_ref = $self->can($sub_name, @_);
return $self->$meth_ref(@_);
}
1;
=head1 COPYRIGHT AND LICENSE
Changes from SNMP::Info Version 0.7 and on are:
Copyright (c) 2003-2010 Max Baker and SNMP::Info Developers
All rights reserved.
Original Code is:
Copyright (c) 2002-2003, Regents of the University of California
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University of California, Santa Cruz nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
|