| 1 | package SNMPMonitor::Plugin; | ||
| 2 | |||
| 3 | use common::sense; | ||
| 4 | #use NetSNMP::ASN (':all'); | ||
| 5 | my $default_oid = '.1.3.6.1.4.1.9999.'; | ||
| 6 | my $debugging = 1; | ||
| 7 | |||
| 8 | sub new { | ||
| 9 | my $obj_class = shift; | ||
| 10 | my $root_oid = shift; | ||
| 11 | |||
| 12 | my $class = ref $obj_class || $obj_class; | ||
| 13 | my ($name) = $class =~ /::Plugin::(.*)/; | ||
| 14 | |||
| 15 | my $self = { | ||
| 16 | name => $name, | ||
| 17 | full_name => $class, | ||
| 18 | root_oid => $root_oid || $default_oid, | ||
| 19 | plugin_oid => '', | ||
| 20 | full_oid => '', | ||
| 21 | }; | ||
| 22 | |||
| 23 | bless $self, $class; | ||
| 24 | |||
| 25 | $self->set_accessors; | ||
| 26 | $self->set_oid; | ||
| 27 | return $self; | ||
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | sub set_accessors { | ||
| 32 | my $self = shift; | ||
| 33 | |||
| 34 | # create accessor methods for defined parameters | ||
| 35 | for my $datum (keys %{$self}) { | ||
| 36 | no strict "refs"; | ||
| 37 | |||
| 38 | *$datum = sub { | ||
| 39 | my $self = shift; # XXX: Don't ignore calling class/object | ||
| 40 | $self->{$datum} = shift if @_; | ||
| 41 | return $self->{$datum}; | ||
| 42 | }; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | # Set the OID using plugin defined OID. | ||
| 48 | sub set_oid { | ||
| 49 | my $self = shift; | ||
| 50 | $self->plugin_oid($self->set_plugin_oid); | ||
| 51 | $self->full_oid($self->root_oid . $self->plugin_oid); | ||
| 52 | } | ||
| 53 | |||
| 54 | # reset the OID, | ||
| 55 | sub reset_oid { | ||
| 56 | my $self = shift; | ||
| 57 | $self->full_oid($self->root_oid . $self->plugin_oid); | ||
| 58 | } | ||
| 59 | |||
| 60 | sub set_monitor { | ||
| 61 | my $self = shift; | ||
| 62 | my ($handler, $registration_info, $request_info, $requests) = @_; | ||
| 63 | my $FH = shift || 'STDOUT'; | ||
| 64 | |||
| 65 | # do { | ||
| 66 | # print $FH "refs: ",join(", ", ref($handler), ref($registration_info), | ||
| 67 | # ref($request_info), ref($requests)),"\n"; | ||
| 68 | # print $FH "processing a request of type " . $request_info->getMode() . "\n"; | ||
| 69 | # } if $debugging; | ||
| 70 | |||
| 71 | for (my $request = $requests; $request; $request = $request->next()) { | ||
| 72 | $self->monitor($request); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | 1; | ||
| 77 | __END__ |