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
|
#!/usr/bin/perl
#
# SNMPTT Net-SNMP-Test v1.0
#
# Copyright 2002-2022 Alex Burger
# alex_b@users.sourceforge.net
#
# 4/13/2003
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
##############################################################################
#
# http://www.sourceforge.net/projects/snmptt
#
###############################################################################
#
# OPTIONS START
#
# Allows you to set the MIBS environment variable used by SNMPTT
# Leave blank or comment out to have the systems enviroment settings used
# To have all MIBS processed, set to ALL
$mibs_environment = "RFC1213-MIB";
# This sets the best_guess parameter used by the UCD-SNMP / NET-SNMP Perl module for
# translating symbolic nams to OIDs and vice versa.
# For UCD-SNMP, and Net-SNMP 5.0.8 and previous versions, set this value to 0.
# For Net-SNMP 5.1, or any Net-SNMP with patch 722075 applied, set this value to 2.
# A value of 2 is equivalent to -IR on Net-SNMP command line utilities.
# UCD-SNMP and Net-SNMP 5.0.8 and previous may not be able to translate certain formats of
# symbolic names such as RFC1213-MIB::sysDescr. Net-SNMP 5.1 or patch 722075 will allow
# all possibilities to be translated.
$net_snmp_perl_best_guess = 1;
#
# OPTIONS END
#
#############################################################################
#
$snmpttnet_snmp_test_version = "v1.0";
sub showversion
{
print "\nSNMPTT Net-SNMP Test $snmpttnet_snmp_test_version\n";
print "(c) 2003 Alex Burger\n";
print "http://snmptt.sourceforge.net\n\n";
}
##############################################################################
# Process command line arguments
$| = 1;
use Getopt::Long;
$DEBUGGING = 0;
$version = 0;
$debug = 0;
$help = 0;
GetOptions ('version' => \$version,
'help' => \$help,
'best_guess:i' => \$best_guess);
if ($version == 1)
{
&showversion;
exit(0);
}
if ($help == 1)
{
$USAGE = qq/This program is used to perform various translations of numeric and symbolic
OIDS using the UCD-SNMP \/ NET-SNMP Perl module and the translateObj function.
The test results should assist with determining if the installed Perl module
will function as expected with SNMPTT.
For UCD-SNMP, and Net-SNMP 5.0.8 and previous versions, use --best_guess=0.
For Net-SNMP 5.1, or any Net-SNMP with patch 722075 applied, use
--best_guess=2.
Usage:
net-snmp-test [<options>]
Options:
--help Display this message
--version Display author and version information
--best_guess=n Display author and version information
/;
&showversion;
print $USAGE . "\n";
exit(0);
}
use SNMP;
&showversion;
if (defined ($mibs_environment))
{
$ENV{'MIBS'} = $mibs_environment;
}
$SNMP::save_descriptions = 1;
&SNMP::initMib();
if (defined ($best_guess))
{
$SNMP::best_guess = $best_guess;
}
else
{
$SNMP::best_guess = $net_snmp_perl_best_guess;
}
$include_module = 1;
my $test;
my $long_names;
my $include_module;
print "MIBS:$mibs_environment\n";
print "best_guess: $SNMP::best_guess\n";
print "\n\nTesting translateObj\n";
print "********************\n";
$test = '.1.3.6.1.2.1.1.1';
$expect = 'sysDescr';
$long_names = 0;
$include_module = 0;
&translate($test, $expect, $long_names, $include_module);
$test = '.1.3.6.1.2.1.1.1';
$expect = 'RFC1213-MIB::sysDescr';
$long_names = 0;
$include_module = 1;
&translate($test, $expect, $long_names, $include_module);
$test = '.1.3.6.1.2.1.1.1';
$expect = '.iso.org.dod.internet.mgmt.mib-2.system.sysDescr';
$long_names = 1;
$include_module = 0;
&translate($test, $expect, $long_names, $include_module);
if ($SNMP::VERSION =~ /^4./)
{
print "Note: UCD-SNMP v$SNMP::VERSION detected. UCD-SNMP does not normally\n return the entire tree when requesting a long name\n";
}
$test = '.1.3.6.1.2.1.1.1';
$expect = 'RFC1213-MIB::.iso.org.dod.internet.mgmt.mib-2.system.sysDescr';
$long_names = 1;
$include_module = 1;
&translate($test, $expect, $long_names, $include_module);
$test = 'sysDescr';
$expect = '.1.3.6.1.2.1.1.1';
$long_names = 0;
$include_module = 0;
&translate($test, $expect, $long_names, $include_module);
$test = 'RFC1213-MIB::sysDescr';
$expect = '.1.3.6.1.2.1.1.1';
$long_names = 0;
$include_module = 0;
&translate($test, $expect, $long_names, $include_module);
$test = 'system.sysDescr';
$expect = '.1.3.6.1.2.1.1.1';
$long_names = 0;
$include_module = 0;
&translate($test, $expect, $long_names, $include_module);
$test = 'RFC1213-MIB::system.sysDescr';
$expect = '.1.3.6.1.2.1.1.1';
$long_names = 0;
$include_module = 0;
&translate($test, $expect, $long_names, $include_module);
$test = '.iso.org.dod.internet.mgmt.mib-2.system.sysDescr';
$expect = '.1.3.6.1.2.1.1.1';
$long_names = 0;
$include_module = 0;
&translate($test, $expect, $long_names, $include_module);
print "\n\nTesting getType\n";
print "***************\n";
$test = '.1.3.6.1.2.1.4.1'; # ipForwarding
$expect = 'INTEGER';
&my_getType($test, $expect,);
$test = 'ipForwarding'; # ipForwarding
$expect = 'INTEGER';
&my_getType($test, $expect,);
print "\n\nTesting Description\n";
print "*******************\n";
$test = '.1.3.6.1.2.1.4.1'; # ipForwarding
$expect = 'The indication of whether this entity is acting';
&my_getDescription($test, $expect,);
print "\n";
sub translate
{
my $test = shift;
my $expect = shift;
my $long_names = shift;
my $include_module = shift;
print "\nTesting: $test, long_names=" . ($long_names == 1 ? "enabled" : "disabled") . ", include_module=" . ($include_module == 1 ? "enabled" : "disabled") . "\n";
$translated = &SNMP::translateObj("$test",$long_names,$include_module);
if ($translated eq $expect)
{
print "Test passed. Result: $translated\n";
}
else
{
print "Test FAILED! Expected: $expect\n";
print " Received: $translated\n";
}
}
sub my_getType
{
my $test = shift;
my $expect = shift;
print "\nTesting: $test\n";
$type = &SNMP::getType("$test");
if ($type eq $expect)
{
print "Test passed. Result: $type\n";
}
else
{
print "Test FAILED! Expected: $expect\n";
print " Received: $type\n";
}
}
sub my_getDescription
{
my $test = shift;
my $expect = shift;
my $description_temp = $SNMP::MIB{$test}->{description};
$description_temp =~ s/\n\s+/\n/g;
if ($description_temp =~ $expect)
{
print "Test passed. Result:\n";
print "-------------------------------------------------\n";
print "$description_temp\n";
print "-------------------------------------------------\n";
}
else
{
print "Test FAILED! Expected a string containing:\n";
print "$expect\n\n";
print "Received:\n";
print "-------------------------------------------------\n";
print "$description_temp\n";
print "-------------------------------------------------\n";
}
}
|