1#!/usr/bin/perl 2# Before `make install' is performed this script should be runnable with 3# `make test'. After `make install' it should work as `perl Net-SNMPTrapd.t' 4 5use strict; 6use warnings; 7use Test::Simple tests => 5; 8use ExtUtils::MakeMaker qw(prompt); 9 10my $NUM_TESTS = 5; 11my $VERBOSE = 0; 12 13use Net::SNMPTrapd; 14ok(1, "Loading Module"); # If we made it this far, we're ok. 15 16######################### 17 18print <<STOP; 19 20 Net::SNMPTrapd needs the Net::SNMP module to perform 21 the full set of tests. If you're not sure if you have 22 the Net::SNMP module, this will test for it before 23 running. 24 25 To continue without running the tests (if perhaps you 26 know Net::SNMP is not available), simply press 'Enter'. 27 28 29STOP 30 31my $answer = prompt("Continue with tests? ('y' and 'Enter')", 'n'); 32 33if (lc($answer) ne 'y') { 34 for (2..$NUM_TESTS) { 35 ok(1, "Skipping test ...") 36 } 37 exit 38} 39 40######################### 41# Test 2 42sub start_server { 43 my $snmptrapd = Net::SNMPTrapd->new(); 44 if (defined($snmptrapd)) { 45 return $snmptrapd 46 } else { 47 printf "Error: %s\nDo you have a SNMP Trap receiver listening already?\n ('netstat -an | grep 162')\n", Net::SNMPTrapd->error; 48 return undef 49 } 50} 51my $snmptrapd = start_server(); 52if (!defined($snmptrapd)) { 53 ok(1, "Starting Server - Skipping remaining tests"); 54 for (3..$NUM_TESTS) { 55 ok(1, "Skipping test ...") 56 } 57 exit 58} else { 59 ok(1, "Starting Server"); 60} 61 62######################### 63# Test 3 64if ($snmptrapd->server->sockport == 162) { 65 ok(1, "server() accessor"); 66} else { 67 ok(0, "server() accessor"); 68} 69 70######################### 71# Test 4 72sub test4 { 73 74 eval 'use Net::SNMP qw(:ALL)'; 75 if ($@) { 76 print "Error: Net::SNMP not found - skipping test ...\n"; 77 return 255 78 } 79 80 # Start Server 81 my $FAILED = 0; 82 83 # Fork: Server = Parent, Client = Child 84 my $pid = fork(); 85 86 if (!defined($pid)) { 87 print "Error: fork() - $!\n"; 88 return 1 89 } elsif ($pid == 0) { 90 #child 91 sleep 2; 92 93 # SNMPv1 Trap 94 my ($session, $error) = Net::SNMP->session( 95 -hostname => 'localhost', 96 -version => 1, 97 -community => 'public', 98 -port => 162 99 ); 100 101 if (!defined($session)) { 102 printf "Error: Starting SNMP session (v1 trap) - %s\n", $error; 103 return 1 104 } 105 106 my $result = $session->trap( 107 -enterprise => '1.3.6.1.4.1.50000', 108 -generictrap => 6, 109 -specifictrap => 1, 110 -timestamp => time(), 111 -varbindlist => [ 112 '1.3.6.1.4.1.50000.1.3', 0x02, 1, 113 '1.3.6.1.4.1.50000.1.4', 0x04, 'String', 114 '1.3.6.1.4.1.50000.1.5', 0x06, '1.2.3.4.5.6.7.8.9', 115 '1.3.6.1.4.1.50000.1.6', 0x40, '10.10.10.1', 116 '1.3.6.1.4.1.50000.1.7', 0x41, 32323232, 117 '1.3.6.1.4.1.50000.1.8', 0x42, 42424242, 118 '1.3.6.1.4.1.50000.1.9', 0x43, time(), 119 '1.3.6.1.4.1.50000.1.10', 0x44, 'opaque data' 120 ] 121 ); 122 $session->close; 123 124 # SNMPv2 Trap 125 ($session, $error) = Net::SNMP->session( 126 -hostname => 'localhost', 127 -version => 2, 128 -community => 'public', 129 -port => 162 130 ); 131 132 if (!defined($session)) { 133 printf "Error: Starting SNMP session (v2c trap) - %s\n", $error; 134 return 1 135 } 136 137 $result = $session->snmpv2_trap( 138 -varbindlist => [ 139 '1.3.6.1.2.1.1.3.0', 0x43, time(), 140 '1.3.6.1.6.3.1.1.4.1.0', 0x06, '1.3.6.1.4.1.50000', 141 '1.3.6.1.4.1.50000.1.3', 0x02, 1, 142 '1.3.6.1.4.1.50000.1.4', 0x04, 'String', 143 '1.3.6.1.4.1.50000.1.5', 0x06, '1.2.3.4.5.6.7.8.9', 144 '1.3.6.1.4.1.50000.1.6', 0x40, '10.10.10.1', 145 '1.3.6.1.4.1.50000.1.7', 0x41, 32323232, 146 '1.3.6.1.4.1.50000.1.8', 0x42, 42424242, 147 '1.3.6.1.4.1.50000.1.9', 0x43, time(), 148 '1.3.6.1.4.1.50000.1.10', 0x44, 'opaque data' 149 ] 150 ); 151 $session->close; 152 153 # SNMPv2 InformRequest 154 # This will keep sending until a Response is successfully sent from the Server or until timeout 155 ($session, $error) = Net::SNMP->session( 156 -hostname => 'localhost', 157 -version => 2, 158 -community => 'public', 159 -port => 162 160 ); 161 162 if (!defined($session)) { 163 printf "Error: Starting SNMP session (v2c InformRequest) - %s\n", $error; 164 return 1 165 } 166 167 $result = $session->inform_request( 168 -varbindlist => [ 169 '1.3.6.1.2.1.1.3.0', 0x43, time(), 170 '1.3.6.1.6.3.1.1.4.1.0', 0x06, '1.3.6.1.4.1.50000', 171 '1.3.6.1.4.1.50000.1.3', 0x02, 1, 172 '1.3.6.1.4.1.50000.1.4', 0x04, 'String', 173 '1.3.6.1.4.1.50000.1.5', 0x06, '1.2.3.4.5.6.7.8.9', 174 '1.3.6.1.4.1.50000.1.6', 0x40, '10.10.10.1', 175 '1.3.6.1.4.1.50000.1.7', 0x41, 32323232, 176 '1.3.6.1.4.1.50000.1.8', 0x42, 42424242, 177 '1.3.6.1.4.1.50000.1.9', 0x43, time(), 178 '1.3.6.1.4.1.50000.1.10', 0x44, 'opaque data' 179 ] 180 ); 181 $session->close; 182 exit 183 } else { 184 # parent 185 186 # PDU Type counter, see each PDU type (4, 7, 6) only once each 187 my %T; 188 189 # Loop 4 times, once for each PDU type and extra to see if InformRequest (6) 190 # is send again meaning the server Response didn't work 191 for (1..4) { 192 my $trap; 193 if (!($trap = $snmptrapd->get_trap())) { 194 if (((my $error = sprintf "%s", Net::SNMPTrapd->error) eq "Timed out waiting for datagram") && ($_ == 4)) { 195 return $FAILED 196 } else { 197 printf "Error: %s\n", Net::SNMPTrapd->error; 198 return 1 199 } 200 } 201 if (!(defined($trap->process_trap()))) { 202 printf "Error: %s\n", Net::SNMPTrapd->error; 203 return 1 204 } else { 205if ($VERBOSE) { 206 print " -- $_ --\n"; 207 print " remoteaddr = "; if (defined($trap->remoteaddr) && ($trap->remoteaddr eq "127.0.0.1")) { printf "%s\n", $trap->remoteaddr } else { printf " !ERROR! - %s\n", $trap->remoteaddr; $FAILED++ } 208 print " remoteport = "; if (defined($trap->remoteport) && ($trap->remoteport =~ /^\d{1,5}$/)) { printf "%s\n", $trap->remoteport } else { printf " !ERROR! - %s\n", $trap->remoteport; $FAILED++ } 209 210 print " version = "; if (defined($trap->version) && ($trap->version =~ /^[12]$/)) { printf "%s\n", $trap->version } else { printf " !ERROR! - %s\n", $trap->version; $FAILED++ } 211 print " community = "; if (defined($trap->community) && ($trap->community eq 'public')) { printf "%s\n", $trap->community } else { printf " !ERROR! - %s\n", $trap->community; $FAILED++ } 212 print " pdu_type = "; if (defined($trap->pdu_type) && ($trap->pdu_type(1) =~ /^[467]$/)) { printf "%s\n", $trap->pdu_type; $T{$trap->pdu_type(1)}++ } else { printf " !ERROR! - %s\n", $trap->pdu_type; $FAILED++ } 213 # Make sure we've seen each PDU type only once 214 for (keys(%T)) { 215 if ($T{$_} > 1) { 216 print " !ERROR! - PDU type $_ seen $T{$_} times\n"; $FAILED++ 217 } 218 } 219 if ($trap->version == 1) { 220 print " ent_OID = "; if (defined($trap->ent_OID) && ($trap->ent_OID eq "1.3.6.1.4.1.50000")) { printf "%s\n", $trap->ent_OID } else { printf " !ERROR! - %s\n", $trap->ent_OID; $FAILED++ } 221 print " agentaddr = "; if (defined($trap->agentaddr) && ($trap->agentaddr eq "127.0.0.1")) { printf "%s\n", $trap->agentaddr } else { printf " !ERROR! - %s\n", $trap->agentaddr; $FAILED++ } 222 print " generic = "; if (defined($trap->generic_trap) && ($trap->generic_trap eq "ENTERPRISESPECIFIC")) { printf "%s\n", $trap->generic_trap } else { printf " !ERROR! - %s\n", $trap->generic_trap; $FAILED++ } 223 print " specific = "; if (defined($trap->specific_trap) && ($trap->specific_trap == 1)) { printf "%s\n", $trap->specific_trap } else { printf " !ERROR! - %s\n", $trap->Specific_trap; $FAILED++ } 224 print " timeticks = "; if (defined($trap->timeticks) && ($trap->timeticks =~ /^\d+$/)) { printf "%s\n", $trap->timeticks } else { printf " !ERROR! - %s\n", $trap->timeticks; $FAILED++ } 225 print " varbind = "; if (defined($trap->varbinds->[0]->{'1.3.6.1.4.1.50000.1.3'}) && ($trap->varbinds->[0]->{'1.3.6.1.4.1.50000.1.3'} == 1)) { printf "%s\n", $trap->varbinds->[0]->{'1.3.6.1.4.1.50000.1.3'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[0]->{'1.3.6.1.4.1.50000.1.3'}; $FAILED++ } 226 print " varbind = "; if (defined($trap->varbinds->[1]->{'1.3.6.1.4.1.50000.1.4'}) && ($trap->varbinds->[1]->{'1.3.6.1.4.1.50000.1.4'} eq 'String')) { printf "%s\n", $trap->varbinds->[1]->{'1.3.6.1.4.1.50000.1.4'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[1]->{'1.3.6.1.4.1.50000.1.4'}; $FAILED++ } 227 print " varbind = "; if (defined($trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.5'}) && ($trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.5'} eq '1.2.3.4.5.6.7.8.9')) { printf "%s\n", $trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.5'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.5'}; $FAILED++ } 228 print " varbind = "; if (defined($trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.6'}) && ($trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.6'} eq '10.10.10.1')) { printf "%s\n", $trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.6'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.6'}; $FAILED++ } 229 print " varbind = "; if (defined($trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.7'}) && ($trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.7'} == 32323232)) { printf "%s\n", $trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.7'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.7'}; $FAILED++ } 230 print " varbind = "; if (defined($trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.8'}) && ($trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.8'} == 42424242)) { printf "%s\n", $trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.8'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.8'}; $FAILED++ } 231 print " varbind = "; if (defined($trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.9'}) && ($trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.9'} =~ /^\d+$/)) { printf "%s\n", $trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.9'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.9'}; $FAILED++ } 232 print " varbind = "; if (defined($trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.10'}) && ($trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.10'} eq 'opaque data')) { printf "%s\n", $trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.10'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.10'}; $FAILED++ } 233 } else { 234 print " requestID = "; if (defined($trap->request_ID) && ($trap->request_ID =~ /^\d+$/)) { printf "%s\n", $trap->request_ID } else { printf " !ERROR! - %s\n", $trap->request_ID; $FAILED++ } 235 print " errorstat = "; if (defined($trap->error_status) && ($trap->error_status =~ /^\d+$/)) { printf "%s\n", $trap->error_status } else { printf " !ERROR! - %s\n", $trap->error_status; $FAILED++ } 236 print " errorindx = "; if (defined($trap->error_index) && ($trap->error_index =~ /^\d+$/)) { printf "%s\n", $trap->error_index } else { printf " !ERROR! - %s\n", $trap->error_index; $FAILED++ } 237 print " varbind = "; if (defined($trap->varbinds->[0]->{'1.3.6.1.2.1.1.3.0'}) && ($trap->varbinds->[0]->{'1.3.6.1.2.1.1.3.0'} =~ /^\d+$/)) { printf "%s\n", $trap->varbinds->[0]->{'1.3.6.1.2.1.1.3.0'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[0]->{'1.3.6.1.2.1.1.3.0'}; $FAILED++ } 238 print " varbind = "; if (defined($trap->varbinds->[1]->{'1.3.6.1.6.3.1.1.4.1.0'}) && ($trap->varbinds->[1]->{'1.3.6.1.6.3.1.1.4.1.0'} eq '1.3.6.1.4.1.50000')) { printf "%s\n", $trap->varbinds->[1]->{'1.3.6.1.6.3.1.1.4.1.0'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[1]->{'1.3.6.1.6.3.1.1.4.1.0'}; $FAILED++ } 239 print " varbind = "; if (defined($trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.3'}) && ($trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.3'} == 1)) { printf "%s\n", $trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.3'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.3'}; $FAILED++ } 240 print " varbind = "; if (defined($trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.4'}) && ($trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.4'} eq 'String')) { printf "%s\n", $trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.4'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.4'}; $FAILED++ } 241 print " varbind = "; if (defined($trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.5'}) && ($trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.5'} eq '1.2.3.4.5.6.7.8.9')) { printf "%s\n", $trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.5'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.5'}; $FAILED++ } 242 print " varbind = "; if (defined($trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.6'}) && ($trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.6'} eq '10.10.10.1')) { printf "%s\n", $trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.6'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.6'}; $FAILED++ } 243 print " varbind = "; if (defined($trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.7'}) && ($trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.7'} == 32323232)) { printf "%s\n", $trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.7'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.7'}; $FAILED++ } 244 print " varbind = "; if (defined($trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.8'}) && ($trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.8'} == 42424242)) { printf "%s\n", $trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.8'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.8'}; $FAILED++ } 245 print " varbind = "; if (defined($trap->varbinds->[8]->{'1.3.6.1.4.1.50000.1.9'}) && ($trap->varbinds->[8]->{'1.3.6.1.4.1.50000.1.9'} =~ /^\d+$/)) { printf "%s\n", $trap->varbinds->[8]->{'1.3.6.1.4.1.50000.1.9'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[8]->{'1.3.6.1.4.1.50000.1.9'}; $FAILED++ } 246 print " varbind = "; if (defined($trap->varbinds->[9]->{'1.3.6.1.4.1.50000.1.10'}) && ($trap->varbinds->[9]->{'1.3.6.1.4.1.50000.1.10'} eq 'opaque data')) { printf "%s\n", $trap->varbinds->[9]->{'1.3.6.1.4.1.50000.1.10'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[9]->{'1.3.6.1.4.1.50000.1.10'}; $FAILED++ } 247 } 248} 249 } 250 } 251 } 252 return $FAILED 253} 254my $result = test4(); 255if ($result == 0) { 256 ok(1, "Received Message") 257} elsif ($result == 255) { 258 ok(1, "Received Message - Can't test since no Net::SNMP") 259} else { 260 ok(0, "Received Message") 261} 262 263$snmptrapd = undef; 264 265######################### 266# Test 5 267sub test5 { 268 269 eval 'use Net::SNMP qw(:ALL)'; 270 if ($@) { 271 print "Error: Net::SNMP not found - skipping test ...\n"; 272 return 255 273 } 274 275 # Start Server 276 my $FAILED = 0; 277 278 use IO::Socket::INET; 279 my $snmptrapd = IO::Socket::INET->new( 280 'Proto' => 'udp', 281 'LocalPort' => 162, 282 'Timeout' => 10 283 ); 284 285 if (!defined($snmptrapd)) { 286 print "Error: creating socket\n"; 287 return 1 288 } 289 290 # Fork: Server = Parent, Client = Child 291 my $pid = fork(); 292 293 if (!defined($pid)) { 294 print "Error: fork() - $!\n"; 295 return 1 296 } elsif ($pid == 0) { 297 #child 298 sleep 2; 299 300 # SNMPv2 InformRequest 301 # This will keep sending until a Response is successfully sent from the Server or until timeout 302 my ($session, $error) = Net::SNMP->session( 303 -hostname => 'localhost', 304 -version => 2, 305 -community => 'public', 306 -port => 162 307 ); 308 309 if (!defined($session)) { 310 printf "Error: Starting SNMP session (v2c InformRequest) - %s\n", $error; 311 return 1 312 } 313 314 $result = $session->inform_request( 315 -varbindlist => [ 316 '1.3.6.1.2.1.1.3.0', 0x43, time(), 317 '1.3.6.1.6.3.1.1.4.1.0', 0x06, '1.3.6.1.4.1.50000', 318 '1.3.6.1.4.1.50000.1.3', 0x02, 1, 319 '1.3.6.1.4.1.50000.1.4', 0x04, 'String', 320 '1.3.6.1.4.1.50000.1.5', 0x06, '1.2.3.4.5.6.7.8.9', 321 '1.3.6.1.4.1.50000.1.6', 0x40, '10.10.10.1', 322 '1.3.6.1.4.1.50000.1.7', 0x41, 32323232, 323 '1.3.6.1.4.1.50000.1.8', 0x42, 42424242, 324 '1.3.6.1.4.1.50000.1.9', 0x43, time(), 325 '1.3.6.1.4.1.50000.1.10', 0x44, 'opaque data' 326 ] 327 ); 328 $session->close; 329 exit 330 } else { 331 # parent 332 333 my $buffer; 334 $snmptrapd->recv($buffer, 1500); 335 my $trap; 336 if (!defined($trap = Net::SNMPTrapd->process_trap($buffer))) { 337 if ((my $error = sprintf "%s", Net::SNMPTrapd->error) eq "Error sending InformRequest Response - Server not defined") { 338if ($VERBOSE) { 339 printf " -- Datagram with no address --\n %s\n", Net::SNMPTrapd->error 340} 341 } else { 342 return 1 343 } 344 } 345 346 if (!defined($trap = Net::SNMPTrapd->process_trap(-datagram => $buffer, -noresponse => 1))) { 347 printf "Error: %s\n", Net::SNMPTrapd->error; 348 return 1 349 } else { 350if ($VERBOSE) { 351 print " -- process_trap() as sub --\n"; 352 print " version = "; if (defined($trap->version) && ($trap->version =~ /^[12]$/)) { printf "%s\n", $trap->version } else { printf " !ERROR! - %s\n", $trap->version; $FAILED++ } 353 print " community = "; if (defined($trap->community) && ($trap->community eq 'public')) { printf "%s\n", $trap->community } else { printf " !ERROR! - %s\n", $trap->community; $FAILED++ } 354 print " pdu_type = "; if (defined($trap->pdu_type) && ($trap->pdu_type(1) =~ /^[467]$/)) { printf "%s\n", $trap->pdu_type; } else { printf " !ERROR! - %s\n", $trap->pdu_type; $FAILED++ } 355 print " requestID = "; if (defined($trap->request_ID) && ($trap->request_ID =~ /^\d+$/)) { printf "%s\n", $trap->request_ID } else { printf " !ERROR! - %s\n", $trap->request_ID; $FAILED++ } 356 print " errorstat = "; if (defined($trap->error_status) && ($trap->error_status =~ /^\d+$/)) { printf "%s\n", $trap->error_status } else { printf " !ERROR! - %s\n", $trap->error_status; $FAILED++ } 357 print " errorindx = "; if (defined($trap->error_index) && ($trap->error_index =~ /^\d+$/)) { printf "%s\n", $trap->error_index } else { printf " !ERROR! - %s\n", $trap->error_index; $FAILED++ } 358 print " varbind = "; if (defined($trap->varbinds->[0]->{'1.3.6.1.2.1.1.3.0'}) && ($trap->varbinds->[0]->{'1.3.6.1.2.1.1.3.0'} =~ /^\d+$/)) { printf "%s\n", $trap->varbinds->[0]->{'1.3.6.1.2.1.1.3.0'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[0]->{'1.3.6.1.2.1.1.3.0'}; $FAILED++ } 359 print " varbind = "; if (defined($trap->varbinds->[1]->{'1.3.6.1.6.3.1.1.4.1.0'}) && ($trap->varbinds->[1]->{'1.3.6.1.6.3.1.1.4.1.0'} eq '1.3.6.1.4.1.50000')) { printf "%s\n", $trap->varbinds->[1]->{'1.3.6.1.6.3.1.1.4.1.0'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[1]->{'1.3.6.1.6.3.1.1.4.1.0'}; $FAILED++ } 360 print " varbind = "; if (defined($trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.3'}) && ($trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.3'} == 1)) { printf "%s\n", $trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.3'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[2]->{'1.3.6.1.4.1.50000.1.3'}; $FAILED++ } 361 print " varbind = "; if (defined($trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.4'}) && ($trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.4'} eq 'String')) { printf "%s\n", $trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.4'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[3]->{'1.3.6.1.4.1.50000.1.4'}; $FAILED++ } 362 print " varbind = "; if (defined($trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.5'}) && ($trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.5'} eq '1.2.3.4.5.6.7.8.9')) { printf "%s\n", $trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.5'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[4]->{'1.3.6.1.4.1.50000.1.5'}; $FAILED++ } 363 print " varbind = "; if (defined($trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.6'}) && ($trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.6'} eq '10.10.10.1')) { printf "%s\n", $trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.6'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[5]->{'1.3.6.1.4.1.50000.1.6'}; $FAILED++ } 364 print " varbind = "; if (defined($trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.7'}) && ($trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.7'} == 32323232)) { printf "%s\n", $trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.7'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[6]->{'1.3.6.1.4.1.50000.1.7'}; $FAILED++ } 365 print " varbind = "; if (defined($trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.8'}) && ($trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.8'} == 42424242)) { printf "%s\n", $trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.8'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[7]->{'1.3.6.1.4.1.50000.1.8'}; $FAILED++ } 366 print " varbind = "; if (defined($trap->varbinds->[8]->{'1.3.6.1.4.1.50000.1.9'}) && ($trap->varbinds->[8]->{'1.3.6.1.4.1.50000.1.9'} =~ /^\d+$/)) { printf "%s\n", $trap->varbinds->[8]->{'1.3.6.1.4.1.50000.1.9'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[8]->{'1.3.6.1.4.1.50000.1.9'}; $FAILED++ } 367 print " varbind = "; if (defined($trap->varbinds->[9]->{'1.3.6.1.4.1.50000.1.10'}) && ($trap->varbinds->[9]->{'1.3.6.1.4.1.50000.1.10'} eq 'opaque data')) { printf "%s\n", $trap->varbinds->[9]->{'1.3.6.1.4.1.50000.1.10'} } else { printf " !ERROR! - %s\n", $trap->varbinds->[9]->{'1.3.6.1.4.1.50000.1.10'}; $FAILED++ } 368} 369 } 370 371 my ($rin, $rout, $ein, $eout) = ('', '', '', ''); 372 vec($rin, fileno($snmptrapd), 1) = 1; 373 374 # check if a message is waiting 375 if (select($rout=$rin, undef, $eout=$ein, 10)) { 376 if ($snmptrapd->recv($buffer, 1500)) { 377if ($VERBOSE) { 378 print " -- OK! Received extra InformRequest due to -noresponse --\n" 379} 380 } else { 381if ($VERBOSE) { 382 print " -- FAIL! recv() error waiting for extra InformRequest --\n" 383} 384 } 385 } else { 386if ($VERBOSE) { 387 print " -- FAIL! Did *NOT* receive extra InformRequest --\n" 388} 389 } 390 } 391 return $FAILED 392} 393$result = test5(); 394if ($result == 0) { 395 ok(1, "Process as sub") 396} elsif ($result == 255) { 397 ok(1, "Process as sub - Can't test since no Net::SNMP") 398} else { 399 ok(0, "Process as sub") 400} 401