[root@elara object_problem]# perl snmp_monitor.pl
starting snmp_monitor.pl
Found Plugins:
Plugin: SNMPMonitor::Plugin::Atest
Plugin: SNMPMonitor::Plugin::Btest
--> Plugins Dump:
$VAR1 = 'SNMPMonitor::Plugin::Atest';
$VAR2 = 'SNMPMonitor::Plugin::Btest';
--> Objects Dump:
$VAR1 = bless( {
'plugin_oid' => '0.0.0',
'name' => 'Atest',
'root_oid' => '.1.3.6.1.4.1.99999.',
'full_name' => 'SNMPMonitor::Plugin::Atest',
'full_oid' => '.1.3.6.1.4.1.99999.0.0.0'
}, 'SNMPMonitor::Plugin::Atest' );
$VAR2 = bless( {
'plugin_oid' => '1.1.1',
'name' => 'Btest',
'root_oid' => '.1.3.6.1.4.1.99999.',
'full_name' => 'SNMPMonitor::Plugin::Btest',
'full_oid' => '.1.3.6.1.4.1.99999.1.1.1'
}, 'SNMPMonitor::Plugin::Btest' );
In Atest
Print Test:
0Full Name: SNMPMonitor::Plugin::Btest
Name: Btest
OID: 1.1.1
Root OID: .1.3.6.1.4.1.99999.
Full OID: .1.3.6.1.4.1.99999.1.1.1
In Btest
Print Test:
0Full Name: SNMPMonitor::Plugin::Btest
Name: Btest
OID: 1.1.1
Root OID: .1.3.6.1.4.1.99999.
Full OID: .1.3.6.1.4.1.99999.1.1.1
####
#!/usr/bin/perl
use Data::Dumper;
use strict;
use warnings;
use common::sense;
use lib '/root/snmp_monitor/trunk';
use SNMPMonitor;
use SNMPMonitor::Plugin;
BEGIN {
print STDERR "starting $0\n";
}
# Private vars
my $root_oid = '.1.3.6.1.4.1.99999.';
my $monitor = SNMPMonitor->new;
my @plugins = $monitor->plugins();
#print "Found Plugins: \n" . Dumper @plugins;
print STDERR "\nFound Plugins: \n";
print STDERR "Plugin: $_ \n" foreach @plugins;
print STDERR "\n";
my @objects;
push @objects, $_->new($root_oid) foreach @plugins;
print STDERR "\n\n--> Plugins Dump:\n" . Dumper @plugins;
print STDERR "\n\n--> Objects Dump:\n" . Dumper @objects;
foreach my $obj (@objects) {
print STDERR "Print Test; \n" . $obj->print_test;
print STDERR "Full Name: " . $obj->full_name . "\n";
print STDERR "Name: " . $obj->name . "\n";
print STDERR "OID: " . $obj->plugin_oid . "\n";
print STDERR "Root OID: " . $obj->root_oid . "\n";
print STDERR "Full OID: " . $obj->full_oid . "\n\n";
}
####
package SNMPMonitor;
use Module::Pluggable require => 1;
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
}
sub evaluate_plugin {
}
1;
__END__
####
package SNMPMonitor::Plugin;
use common::sense;
#use NetSNMP::ASN (':all');
sub new {
my $obj_class = shift;
my $root_oid = shift;
my $class = ref $obj_class || $obj_class;
my ($name) = $class =~ /::Plugin::(.*)/;
my $self = {
name => $name,
full_name => $class,
root_oid => $root_oid,
plugin_oid => '',
full_oid => '',
};
bless $self, $class;
# create accessor methods for defined parameters
for my $datum (keys %{$self}) {
no strict "refs";
*$datum = sub {
shift; # XXX: ignore calling class/object
$self->{$datum} = shift if @_;
return $self->{$datum};
};
}
$self->set_oid();
return $self;
}
# Set the OID using plugin defined OID.
sub set_oid {
my $self = shift;
$self->plugin_oid($self->set_plugin_oid);
$self->full_oid($self->root_oid . $self->plugin_oid);
}
1;
__END__
####
package SNMPMonitor::Plugin::Atest;
use strict;
use warnings;
#use common::sense;
use NetSNMP::ASN (':all');
# use Smart::Comments;
my @ISA = qw(SNMPMonitor::Plugin);
sub set_plugin_oid {'0.0.0'};
sub monitor {
use Data::Dumper;
print STDERR "--> In Object \nDumper: " . Dumper @_;
my $class = shift;
my ($handler, $registration_info, $request_info, $requests) = @_;
my $request;
my $this_request = $requests->next();
$requests->setValue(ASN_OCTET_STR, "Test Successful");
}
sub print_test {
my $self = shift;
print STDERR "In " . $self->full_name . "\n";
}
1;
__END__
####
package SNMPMonitor::Plugin::Btest;
use strict;
use warnings;
#use common::sense;
use NetSNMP::ASN (':all');
# use Smart::Comments;
my @ISA = qw(SNMPMonitor::Plugin);
sub set_plugin_oid {'1.1.1'};
sub monitor {
use Data::Dumper;
print STDERR "--> In Object \nDumper: " . Dumper @_;
my $class = shift;
my ($handler, $registration_info, $request_info, $requests) = @_;
my $request;
# do {
# print STDERR "refs: ",join(", ", ref($handler), ref($registration_info),
# ref($request_info), ref($requests)),"\n";
# print STDERR "processing a request of type " . $request_info->getMode() . "\n";
# };
my $this_request = $requests->next();
$requests->setValue(ASN_OCTET_STR, "BTest Successful");
}
sub print_test {
my $self = shift;
print STDERR "In " . $self->{'name'} . "\n";
my $a = 0;
### @_;
}
1;
__END__