| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
. ../support/simple_eval_tools.sh |
| 4 |
|
| 5 |
HEADER 'snmpd embedded perl support (using NetSNMP::agent)' |
| 6 |
|
| 7 |
SKIPIF NETSNMP_DISABLE_SNMPV2C |
| 8 |
SKIPIFNOT NETSNMP_EMBEDDED_PERL |
| 9 |
SKIPIFNOT HAVE_SIGHUP |
| 10 |
SKIPIFNOT NETSNMP_SECMOD_USM |
| 11 |
|
| 12 |
# |
| 13 |
# Begin test |
| 14 |
# |
| 15 |
|
| 16 |
snmp_version=v2c |
| 17 |
TESTCOMMUNITY=testcommunity |
| 18 |
. ./Sv2cconfig |
| 19 |
|
| 20 |
TESTOID=.1.3.6.1.4.1.8872.9999.9999.1.0 |
| 21 |
TESTOID2=.1.3.6.1.4.1.8872.9999.9999.2.0 |
| 22 |
EMBPERL_AGENT=${SNMP_TMPDIR}/hello.pl |
| 23 |
cat >$EMBPERL_AGENT <<END |
| 24 |
#!/usr/bin/env perl |
| 25 |
# minimal embedded perl agent |
| 26 |
|
| 27 |
my \$regat = '.1.3.6.1.4.1.8872.9999.9999'; # netSnmpPlayPen |
| 28 |
my \$myoid = \$regat . ".1.0"; # the "hello world" OID |
| 29 |
my \$myoid2 = \$regat . ".2.0"; # the "hello again world" OID |
| 30 |
|
| 31 |
use NetSNMP::OID qw(:all); |
| 32 |
use NetSNMP::agent qw(:all); |
| 33 |
use NetSNMP::ASN qw(:all); |
| 34 |
use SNMP; |
| 35 |
|
| 36 |
my \$regoid = new NetSNMP::OID(\$regat); |
| 37 |
\$agent->register("hello", \$regoid, \&my_snmp_handler); |
| 38 |
|
| 39 |
sub my_snmp_handler { |
| 40 |
my (\$handler, \$registration_info, \$request_info, \$requests) = @_; |
| 41 |
for(my \$request = \$requests; \$request; \$request = \$request->next()) { |
| 42 |
if (\$request_info->getMode() == MODE_GET) { |
| 43 |
if (\$request->getOID() == new NetSNMP::OID(\$myoid)) { |
| 44 |
\$request->setValue(ASN_OCTET_STR, "hello world"); |
| 45 |
last; |
| 46 |
} elsif (\$request->getOID() == new NetSNMP::OID(\$myoid2)) { |
| 47 |
\$request->setValue(ASN_OCTET_STR, "hello again world"); |
| 48 |
last; |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
END |
| 54 |
|
| 55 |
echo "use blib qw(${SNMP_UPDIR}/perl);" > ${SNMP_TMPDIR}/snmp_perl.pl |
| 56 |
echo 'use NetSNMP::agent;' >> ${SNMP_TMPDIR}/snmp_perl.pl |
| 57 |
echo '$agent = new NetSNMP::agent('"'dont_init_agent' => 1, 'dont_init_lib' => 1);" >> ${SNMP_TMPDIR}/snmp_perl.pl |
| 58 |
|
| 59 |
CONFIGAGENT perlInitFile ${SNMP_TMPDIR}/snmp_perl.pl |
| 60 |
CONFIGAGENT "perl do '$EMBPERL_AGENT';" |
| 61 |
CONFIGAGENT 'perl print STDERR "registered_perl_agent_ok";' |
| 62 |
|
| 63 |
STARTAGENT |
| 64 |
|
| 65 |
## 1) SNMP GET against embedded perl mib module |
| 66 |
CAPTURE "snmpget -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT $TESTOID" |
| 67 |
CHECK "hello world" |
| 68 |
|
| 69 |
## 2) persistency: reconfigure (HUP), re-test |
| 70 |
HUPAGENT |
| 71 |
CAPTURE "snmpget -$snmp_version -c $TESTCOMMUNITY $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT $TESTOID2" |
| 72 |
CHECK "hello again world" |
| 73 |
|
| 74 |
## stop |
| 75 |
STOPAGENT |
| 76 |
|
| 77 |
FINISHED |