Debian Codegraph @

perl/SNMP/t/get.t

raw
1 #!./perl
2
3 use strict;
4 use warnings;
5 use Test;
6
7 BEGIN {
8 eval "use Cwd qw(abs_path)";
9 plan tests => 17
10 }
11 use SNMP;
12 require "t/startagent.pl";
13 use vars qw($agent_host $agent_port $comm);
14 $SNMP::debugging = 0;
15 $SNMP::verbose = 0;
16 $SNMP::dump_packet = 0;
17
18 my $junk_oid = ".1.3.6.1.2.1.1.1.1.1.1";
19 my $oid = '.1.3.6.1.2.1.1.1';
20 my $junk_name = 'fooDescr';
21 my $junk_host = 'no.host.here';
22 my $name = "gmarzot\@nortelnetworks.com";
23 my $s1;
24
25 # create list of varbinds for GETS, val field can be null or omitted
26 my $vars = new SNMP::VarList(
27 ['sysDescr', '0', ''],
28 ['sysObjectID', '0'],
29 ['sysUpTime', '0'],
30 ['sysContact', '0'],
31 ['sysName', '0'],
32 ['sysLocation', '0'],
33 ['sysServices', '0'],
34
35 ['snmpInPkts', '0'],
36 ['snmpInBadVersions', '0'],
37 ['snmpInBadCommunityNames', '0'],
38 ['snmpInBadCommunityUses', '0'],
39 ['snmpInASNParseErrs', '0'],
40 ['snmpEnableAuthenTraps', '0'],
41
42 ['sysORID', '1'],
43 ['sysORDescr', '1'],
44 ['sysORUpTime', '1'],
45 ['sysORLastChange', '0'],
46 ['snmpSilentDrops', '0'],
47 ['snmpProxyDrops', '0'],
48
49 ## not all agents we know will support these objects
50 # ['hrStorageType', '2'],
51 # ['hrSystemDate', '0'],
52 # ['sysORIndex', '1'],
53 # ['ifName', '1'],
54 # ['ifNumber', '0'],
55 # ['ifDescr', '1'],
56 # ['ifSpeed', '1'],
57 # ['snmpTrapEnterprise', '2'],
58 # ['ipInHdrErrors', '0'],
59 # ['ipDefaultTTL', '0'],
60 # ['ipInHdrErrors', '0'],
61
62 );
63 ################################################################
64 # Yet to do:
65 # test for the max limit the 'get' can provide.
66 # Figure out why the IP and Physical address are not getting printed.
67 # why ifname is not getting printed?
68 ################################################################
69 # ['ipNetToMediaPhysAddress', '0'],
70 # ['ipAdEntAddr', '0'],
71 # ['snmpTrapOID', '0'],
72 # ['hrSystemNumUsers', '0'],
73 # ['hrFSLastFullBackupDate', '0'],
74 # ['ifPromiscuousMode', '0'],
75
76
77
78 ######################################################################
79 # Fire up a session.
80 $s1 =
81 new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$agent_port);
82 ok(defined($s1));
83
84 ######################################################################
85 # Get the standard Vars and check that we got some defined vars back
86 my @ret = $s1->get($vars);
87 ok(!$s1->{ErrorStr} and defined($ret[0]));
88 #print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n";
89 ######################################################################
90 # Check that we got back the number we asked for.
91 ok($#ret == $#{$vars});
92 #print("dude : $#ret\n");
93 ################################################
94
95 # Test for a string
96 my $contact = $s1->get('sysContact.0');
97 #print("contact is : $contact\n");
98 ok( defined($contact));
99
100
101 $name = $s1->get('sysName.0');
102 #print("Name is : $name\n");
103 ok( defined($name));
104
105
106 my $location = $s1->get('sysLocation.0');
107 #print("Location is : $location\n");
108 ok( defined($location));
109 #########################################
110
111
112 # Test for an integer
113 my $ttl = $s1->get('ipDefaultTTL.0');
114 #print("TTL is : $ttl\n");
115 ok( defined($ttl));
116 ########################################
117
118
119 # Test for a TimeTicks
120 my $time = $s1->get('sysUpTime.0');
121 #print("up time is : $time hundredths of a second\n");
122 ok( defined($time));
123 #########################################
124
125
126 #Test for a Counter32 type.
127 my $totalDatagramsReceived = $s1->get('ipInHdrErrors.0');
128 #print("totalDatagramsReceived is : $totalDatagramsReceived\n");
129 ok( defined($totalDatagramsReceived));
130 ################################################
131
132
133 #Test for a PhysicalAddr type
134 my $physaddr = $s1->get('ipNetToMediaPhysAddress.0');
135 #print("physical addr is : $physaddr \n");
136 ok( defined($physaddr));
137 ##############################################
138
139
140 #Test for a IpAddr type
141 my $ipaddr = $s1->get('ipAdEntAddr.0');
142 #print("Ip address is : $ipaddr \n");
143 ok( defined($ipaddr));
144 ##############################################
145
146
147 #Test for a OID type
148 my $trapOID = $s1->get('snmpTrapOID.0');
149 #print("trap OID is : $trapOID $s1->{ErrorStr}\n");
150 ok( defined($trapOID));
151 ##############################################
152
153
154 #Test for a Gauge type
155 #$numusers = $s1->get('hrSystemNumUsers.0');
156 #print("Number of users is : $numusers \n");
157 #ok( defined($numusers));
158 ##############################################
159
160 #nosuchname
161 #Test for a date & time type
162 #$datetime = $s1->get('hrFSLastFullBackupDate.0');
163 #print("Number of users is : $datetime \n");
164 #ok( defined($datetime));
165 ##############################################
166
167 #nosuchname
168 #Test for a Truth value type
169 #$mode = $s1->get('ifPromiscuousMode.16');
170 #print("Truth value(1 true, 2 false) is : $mode \n");
171 #ok( defined($mode));
172 ##############################################
173
174 # Time stamp test
175 $time = $s1->get('sysORLastChange.0');
176 #print("time stamp is : $time \n");
177 ok(defined($time));
178 #############################################
179
180 # Integer test
181 #$index = $s1->get('sysORIndex.0');
182 #print("index is : $index\n");
183 #ok(defined($index));
184 #############################################
185
186 # OID test
187 $oid = $s1->get('sysORID.1');
188 #print("index is : $oid\n");
189 ok(defined($oid));
190 #############################################
191
192 # String test
193 my $descr = $s1->get('sysORDescr.1');
194 #print("Sys Descr is : $descr\n");
195 ok(defined($descr));
196 #############################################
197
198 # string String test
199 my $ifname = $s1->get('ifDescr.1');
200 #print("ifname is : $ifname $s1->{ErrorStr}\n");
201 ok(defined($ifname));
202 #############################################
203
204
205 # Try getting some unknown(wrong ?) data
206 my $unknown = $s1->get('ifmyData.0');
207 ok(!defined($unknown));
208 ##############################################
209
210
211 snmptest_cleanup();
212
213