Skip to content

Commit

Permalink
Added MacAddress and Hex_Generic roles.
Browse files Browse the repository at this point in the history
  • Loading branch information
aduitsis committed Oct 6, 2010
1 parent b3f931c commit 7bbabf2
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/SNMP/Class/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ sub textual_convention_of {
return get_attr($oid_name,'textualConvention');
}

sub has_textual_convention {
return defined(textual_convention_of($_[0]));
}

sub type_of {
my $oid_name = shift(@_) or croak "Incorrect call to type_of";
return get_attr($oid_name,'type');
}

sub has_type {
return defined(type_of($_[0]));
}

sub syntax_of {
return get_attr(shift,'syntax');
}
Expand Down
2 changes: 2 additions & 0 deletions lib/SNMP/Class/Varbind.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use Log::Log4perl qw(:easy);
use Data::Dumper;
use SNMP::Class::Varbind::SysUpTime;
use SNMP::Class::Varbind::Enum;
use SNMP::Class::Varbind::Hex_Generic;
use SNMP::Class::Varbind::MacAddress;

my $have_time_hires;
eval { require Time::HiRes };
Expand Down
38 changes: 38 additions & 0 deletions lib/SNMP/Class/Varbind/Hex_Generic.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package SNMP::Class::Varbind::Hex_Generic;

use Moose::Role;
use Carp;
use Data::Dumper;
use Log::Log4perl qw(:easy);



#we have to call the register_callback function in the INIT block to make sure
#that the SNMP::Class::Varbind module is actually loaded
INIT {
SNMP::Class::Varbind::register_plugin(__PACKAGE__);
DEBUG __PACKAGE__." plugin activated";
}

sub matches {
( $_[0]->has_label ) && (
( $_[0]->get_label eq 'snmpEngineID')
);
#DEBUG SNMP::Class::Utils::textual_convention_of( $_[0]->get_label );
#DEBUG SNMP::Class::Utils::syntax_of( $_[0]->get_label );
#DEBUG SNMP::Class::Utils::type_of( $_[0]->get_label );
}

sub adopt {
if(matches($_[0])) {
__PACKAGE__->meta->apply($_[0]);
DEBUG "Applying role ".__PACKAGE__." to ".$_[0]->get_label;
}
}

sub value {
return uc join(' ',(unpack '(H2)*',$_[0]->raw_value))
}


1;
42 changes: 42 additions & 0 deletions lib/SNMP/Class/Varbind/MacAddress.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package SNMP::Class::Varbind::MacAddress;

use Moose::Role;
use Carp;
use Data::Dumper;
use Log::Log4perl qw(:easy);



#we have to call the register_callback function in the INIT block to make sure
#that the SNMP::Class::Varbind module is actually loaded
INIT {
SNMP::Class::Varbind::register_plugin(__PACKAGE__);
DEBUG __PACKAGE__." plugin activated";
}

sub matches {
( $_[0]->has_label )
&&
( SNMP::Class::Utils::has_textual_convention( $_[0]->get_label ) )
&&
( SNMP::Class::Utils::textual_convention_of( $_[0]->get_label ) eq 'MacAddress')
;

#DEBUG SNMP::Class::Utils::textual_convention_of( $_[0]->get_label );
#DEBUG SNMP::Class::Utils::syntax_of( $_[0]->get_label );
#DEBUG SNMP::Class::Utils::type_of( $_[0]->get_label );
}

sub adopt {
if(matches($_[0])) {
__PACKAGE__->meta->apply($_[0]);
DEBUG "Applying role ".__PACKAGE__." to ".$_[0]->get_label;
}
}

sub value {
return uc join(':',(unpack '(H2)*',$_[0]->raw_value))
}


1;
2 changes: 1 addition & 1 deletion lib/SNMP/SNMP-Class.logger
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
log4perl.rootLogger=INFO, Screen
log4perl.rootLogger=DEBUG, Screen

log4perl.appender.Screen = Log::Log4perl::Appender::ScreenColoredLevels
log4perl.appender.Screen.stderr = 0
Expand Down

0 comments on commit 7bbabf2

Please sign in to comment.