| 1 | package SNMP::Insight::MIB; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | #ABSTRACT: Base role for MIBs | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 5 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 5 | our $VERSION = '0.002'; #TRIAL VERSION: | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 5 | requires 'session'; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 12 | ▶ | sub _mib_read_scalar { | ||||||||||||||||||
|
Subroutine
_mib_read_scalar: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 15 | 12 | my ( $self, $oid, $munger ) = @_; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 12 | my $v = $self->session->get_scalar($oid); | |||||||||||||||||||
| 18 | 12 | ▶ | $munger and $v = $munger->($v); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | 12 | return $v; | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 22 | ▶ | sub _mib_read_tablerow { | ||||||||||||||||||
|
Subroutine
_mib_read_tablerow: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 23 | 22 | my ( $self, $oid, $munger ) = @_; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 22 | my $row = $self->session->get_subtree($oid); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 22 | foreach (@$row) { | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # Don't optimize this RE! | ||||||||||||||||||||
| 30 | 44 | ▶ | $_->[0] =~ /^$oid\.(.*)/ and $_->[0] = $1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 44 | ▶ | $munger and $_->[1] = $munger->( $_->[1] ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 22 | return $row; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1 | ▶ | sub _mib_read_table { | ||||||||||||||||||
|
Subroutine
_mib_read_table: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 38 | 1 | my $self = shift; | |||||||||||||||||||
| 39 | 1 | my %args = @_; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 1 | my $index = $args{index}; | |||||||||||||||||||
| 42 | 1 | ▶ | my $columns = $args{columns} or croak "Missing parameter columns"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | my $table = {}; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # TODO index handling | ||||||||||||||||||||
| 47 | # if ( ! $self->can($index) ) { | ||||||||||||||||||||
| 48 | # carp "Cannot find index $index"; | ||||||||||||||||||||
| 49 | # } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 1 | for my $col (@$columns) { | |||||||||||||||||||
| 52 | 22 | my $col_values = $self->$col(); | |||||||||||||||||||
| 53 | 22 | foreach my $pair (@$col_values) { | |||||||||||||||||||
| 54 | 44 | $table->{ $pair->[0] }->{$col} = $pair->[1]; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 1 | return $table; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | ▶ | sub munge_bool { | ||||||||||||||||||
|
Subroutine
munge_bool: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 62 | 0 | my $bool = shift; | |||||||||||||||||||
| 63 | 0 | my @ARR = qw ( nop false true); | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | return $ARR[$bool]; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | ▶ | sub munge_ipaddress { | ||||||||||||||||||
|
Subroutine
munge_ipaddress: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 69 | 0 | my $ip = shift; | |||||||||||||||||||
| 70 | 0 | return join( '.', unpack( 'C4', $ip ) ); | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 2 | ▶ | sub munge_macaddress { | ||||||||||||||||||
|
Subroutine
munge_macaddress: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 74 | 2 | my $mac = shift; | |||||||||||||||||||
| 75 | 2 | ▶ | $mac or return ""; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 1 | $mac = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $mac ) ); | |||||||||||||||||||
| 77 | 1 | ▶ | return $mac if $mac =~ /^([0-9A-F][0-9A-F]:){5}[0-9A-F][0-9A-F]$/i; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 1 | return "ERROR"; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | ▶ | sub munge_octet2hex { | ||||||||||||||||||
|
Subroutine
munge_octet2hex: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 82 | 0 | my $oct = shift; | |||||||||||||||||||
| 83 | 0 | return join( '', map { sprintf "%x", $_ } unpack( 'C*', $oct ) ); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | sub munge_bits { | ||||||||||||||||||
|
Subroutine
munge_bits: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 87 | 0 | my $bits = shift; | |||||||||||||||||||
| 88 | 0 | ▶ | return unless defined $bits; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | return unpack( "B*", $bits ); | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | sub munge_counter64 { | ||||||||||||||||||
|
Subroutine
munge_counter64: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 94 | 0 | my $counter = shift; | |||||||||||||||||||
| 95 | 0 | ▶ | return unless defined $counter; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 0 | my $bigint = Math::BigInt->new($counter); | |||||||||||||||||||
| 97 | 0 | return $bigint; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | ▶ | sub munge_ifoperstatus { | ||||||||||||||||||
|
Subroutine
munge_ifoperstatus: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 101 | 0 | my $val = shift; | |||||||||||||||||||
| 102 | 0 | ▶ | return unless $val; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 0 | my %ifOperStatusMap = ( | |||||||||||||||||||
| 105 | '4' => 'unknown', | ||||||||||||||||||||
| 106 | '5' => 'dormant', | ||||||||||||||||||||
| 107 | '6' => 'notPresent', | ||||||||||||||||||||
| 108 | '7' => 'lowerLayerDown' | ||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||
| 110 | 0 | ▶ | return $ifOperStatusMap{$val} || $val; | ||||||||||||||||||
|
Condition0%0/3
$ifOperStatusMap{$val} || $val
MC/DC0%0/2
$ifOperStatusMap{$val} || $val
$ifOperStatusMap{$val}
$val
Truth table0%0/3
A || B
A= $ifOperStatusMap{$val}B= $val
| |||||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | ▶ | sub munge_port_list { | ||||||||||||||||||
|
Subroutine
munge_port_list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 114 | 0 | my $oct = shift; | |||||||||||||||||||
| 115 | 0 | ▶ | return unless defined $oct; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | my $list = [ split( //, unpack( "B*", $oct ) ) ]; | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 0 | return $list; | |||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 5 | 1; | |||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | # Local Variables: | ||||||||||||||||||||
| 125 | # mode: cperl | ||||||||||||||||||||
| 126 | # indent-tabs-mode: nil | ||||||||||||||||||||
| 127 | # cperl-indent-level: 4 | ||||||||||||||||||||
| 128 | # cperl-indent-parens-as-block: t | ||||||||||||||||||||
| 129 | # End: | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||