use
POE
qw/Component::SNMP/
;
my
$CONF
=
do
"config.cache"
;
if
(
$CONF
->{skip_all_tests} ) {
POE::Kernel->run();
plan
skip_all
=>
'No SNMP data specified.'
;
}
else
{
if
(1) {
plan
tests
=> 7;
}
else
{
$poe_kernel
->run();
plan
skip_all
=>
'not done yet'
;
}
}
my
%system
= (
sysName
=>
'.1.3.6.1.2.1.1.5.0'
,
);
my
@oids
=
values
%system
;
my
$base_oid
=
'.1.3.6.1.2.1.1'
;
POE::Session->create(
inline_states
=>
{
_start
=> \
&_start
,
snmp_handler
=> \
&snmp_handler
,
_stop
=> \
&stop_session
,
}
);
my
$done
= 0;
sub
_start {
my
(
$kernel
,
$heap
) =
@_
[KERNEL, HEAP];
POE::Component::SNMP->create(
alias
=>
'snmp'
,
hostname
=>
$CONF
->{
'hostname'
},
community
=>
$CONF
->{
'community'
},
version
=>
'snmpv2c'
,
debug
=>
$CONF
->{debug},
);
ok
$kernel
->alias_resolve(
'snmp'
),
"1st session created"
;
$kernel
->post(
snmp
=>
get
=>
snmp_handler
=>
-varbindlist
=> \
@oids
);
}
sub
snmp_handler {
my
(
$kernel
,
$heap
,
$request
,
$response
) =
@_
[KERNEL, HEAP, ARG0, ARG1];
my
(
$alias
,
$host
,
$cmd
,
@args
) =
@$request
;
my
(
$results
,
@callback_args
) =
@$response
;
ok get_seen(
$heap
);
if
(
ref
$results
) {
ok
ref
$results
eq
'HASH'
;
}
else
{
print
STDERR
"$host SNMP error ($cmd => @args):\n$results\n"
;
}
$kernel
->post(
snmp
=>
'finish'
);
$kernel
->delay(
'_start'
, 1)
unless
$done
++;
}
sub
stop_session {
my
$r
=
$_
[HEAP]->{results};
ok 1;
}
$poe_kernel
->run();