| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# HEADER Basic perl functionality to a UDP agent |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
use NetSNMPTest; |
| 8 |
use Test; |
| 9 |
use SNMP; |
| 10 |
|
| 11 |
my $value; |
| 12 |
|
| 13 |
plan(tests => 10); |
| 14 |
|
| 15 |
ok(1,1,"started up"); |
| 16 |
|
| 17 |
# use a basic UDP port |
| 18 |
my $destination = "udp:localhost:9897"; |
| 19 |
|
| 20 |
my $test = new NetSNMPTest(agentaddress => $destination); |
| 21 |
|
| 22 |
# set it up with a snmpv3 USM user |
| 23 |
$test->config_agent("createuser testuser MD5 notareallpassword"); |
| 24 |
$test->config_agent("rwuser testuser"); |
| 25 |
$test->config_agent("syscontact itworked"); |
| 26 |
|
| 27 |
$test->DIE("failed to start the agent") if (!$test->start_agent()); |
| 28 |
|
| 29 |
# now create a session to test things with |
| 30 |
my $session = new SNMP::Session(DestHost => $destination, |
| 31 |
Version => '3', |
| 32 |
SecName => 'testuser', |
| 33 |
SecLevel => 'authNoPriv', |
| 34 |
AuthProto => 'MD5', |
| 35 |
AuthPass => 'notareallpassword'); |
| 36 |
|
| 37 |
ok(ref($session), 'SNMP::Session', "created a session"); |
| 38 |
|
| 39 |
|
| 40 |
###################################################################### |
| 41 |
# GET test |
| 42 |
$value = $session->get('sysContact.0'); |
| 43 |
|
| 44 |
ok($value, 'itworked'); |
| 45 |
|
| 46 |
###################################################################### |
| 47 |
# GETNEXT test |
| 48 |
$value = $session->getnext('sysContact'); |
| 49 |
|
| 50 |
ok($value, 'itworked'); |
| 51 |
|
| 52 |
###################################################################### |
| 53 |
# SET test |
| 54 |
$value = $session->get('sysLocation.0'); |
| 55 |
|
| 56 |
ok($value ne 'yep', 1, 'Ensuring the sysLocation setting is not "yep"'); |
| 57 |
|
| 58 |
my $varbind = new SNMP::Varbind(['sysLocation', '0', 'yep', 'OCTETSTR']); |
| 59 |
|
| 60 |
|
| 61 |
$value = $session->set($varbind); |
| 62 |
|
| 63 |
ok(($value == 0), 1, 'return value from set was a success'); |
| 64 |
|
| 65 |
$value = $session->get('sysLocation.0'); |
| 66 |
|
| 67 |
ok($value, 'yep'); |
| 68 |
|
| 69 |
###################################################################### |
| 70 |
# GETBULK test |
| 71 |
$varbind = new SNMP::Varbind(['sysContact']); |
| 72 |
my @values = $session->getbulk(0, 3, $varbind); |
| 73 |
|
| 74 |
ok($#values == 2); |
| 75 |
ok($values[0] eq 'itworked'); |
| 76 |
ok($values[2] eq 'yep'); |
| 77 |
|
| 78 |
###################################################################### |
| 79 |
# gettable() test |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
###################################################################### |
| 84 |
# cleanup |
| 85 |
$test->stop_agent(); |