line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SNMP::Insight::MIB; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#ABSTRACT: Base role for MIBs |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
17978
|
use Moose::Role; |
|
5
|
|
|
|
|
356307
|
|
|
5
|
|
|
|
|
29
|
|
6
|
5
|
|
|
5
|
|
20166
|
use Carp; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
380
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; #TRIAL VERSION: |
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
537
|
use namespace::autoclean; |
|
5
|
|
|
|
|
1230
|
|
|
5
|
|
|
|
|
29
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
requires 'session'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _mib_read_scalar { |
15
|
12
|
|
|
12
|
|
21
|
my ( $self, $oid, $munger ) = @_; |
16
|
|
|
|
|
|
|
|
17
|
12
|
|
|
|
|
313
|
my $v = $self->session->get_scalar($oid); |
18
|
12
|
50
|
|
|
|
34753
|
$munger and $v = $munger->($v); |
19
|
12
|
|
|
|
|
33
|
return $v; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _mib_read_tablerow { |
23
|
22
|
|
|
22
|
|
35
|
my ( $self, $oid, $munger ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
22
|
|
|
|
|
1073
|
my $row = $self->session->get_subtree($oid); |
26
|
|
|
|
|
|
|
|
27
|
22
|
|
|
|
|
158997
|
foreach (@$row) { |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Don't optimize this RE! |
30
|
44
|
50
|
|
|
|
777
|
$_->[0] =~ /^$oid\.(.*)/ and $_->[0] = $1; |
31
|
44
|
100
|
|
|
|
115
|
$munger and $_->[1] = $munger->( $_->[1] ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
22
|
|
|
|
|
97
|
return $row; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _mib_read_table { |
38
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
39
|
1
|
|
|
|
|
5
|
my %args = @_; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
2
|
my $index = $args{index}; |
42
|
1
|
50
|
|
|
|
4
|
my $columns = $args{columns} or croak "Missing parameter columns"; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
2
|
my $table = {}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# TODO index handling |
47
|
|
|
|
|
|
|
# if ( ! $self->can($index) ) { |
48
|
|
|
|
|
|
|
# carp "Cannot find index $index"; |
49
|
|
|
|
|
|
|
# } |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
3
|
for my $col (@$columns) { |
52
|
22
|
|
|
|
|
151
|
my $col_values = $self->$col(); |
53
|
22
|
|
|
|
|
177
|
foreach my $pair (@$col_values) { |
54
|
44
|
|
|
|
|
140
|
$table->{ $pair->[0] }->{$col} = $pair->[1]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
7
|
return $table; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub munge_bool { |
62
|
0
|
|
|
0
|
1
|
0
|
my $bool = shift; |
63
|
0
|
|
|
|
|
0
|
my @ARR = qw ( nop false true); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
return $ARR[$bool]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub munge_ipaddress { |
69
|
0
|
|
|
0
|
1
|
0
|
my $ip = shift; |
70
|
0
|
|
|
|
|
0
|
return join( '.', unpack( 'C4', $ip ) ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub munge_macaddress { |
74
|
2
|
|
|
2
|
1
|
3
|
my $mac = shift; |
75
|
2
|
100
|
|
|
|
7
|
$mac or return ""; |
76
|
1
|
|
|
|
|
9
|
$mac = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $mac ) ); |
|
15
|
|
|
|
|
27
|
|
77
|
1
|
50
|
|
|
|
7
|
return $mac if $mac =~ /^([0-9A-F][0-9A-F]:){5}[0-9A-F][0-9A-F]$/i; |
78
|
1
|
|
|
|
|
3
|
return "ERROR"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub munge_octet2hex { |
82
|
0
|
|
|
0
|
1
|
|
my $oct = shift; |
83
|
0
|
|
|
|
|
|
return join( '', map { sprintf "%x", $_ } unpack( 'C*', $oct ) ); |
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub munge_bits { |
87
|
0
|
|
|
0
|
1
|
|
my $bits = shift; |
88
|
0
|
0
|
|
|
|
|
return unless defined $bits; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return unpack( "B*", $bits ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub munge_counter64 { |
94
|
0
|
|
|
0
|
1
|
|
my $counter = shift; |
95
|
0
|
0
|
|
|
|
|
return unless defined $counter; |
96
|
0
|
|
|
|
|
|
my $bigint = Math::BigInt->new($counter); |
97
|
0
|
|
|
|
|
|
return $bigint; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub munge_ifoperstatus { |
101
|
0
|
|
|
0
|
1
|
|
my $val = shift; |
102
|
0
|
0
|
|
|
|
|
return unless $val; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my %ifOperStatusMap = ( |
105
|
|
|
|
|
|
|
'4' => 'unknown', |
106
|
|
|
|
|
|
|
'5' => 'dormant', |
107
|
|
|
|
|
|
|
'6' => 'notPresent', |
108
|
|
|
|
|
|
|
'7' => 'lowerLayerDown' |
109
|
|
|
|
|
|
|
); |
110
|
0
|
|
0
|
|
|
|
return $ifOperStatusMap{$val} || $val; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub munge_port_list { |
114
|
0
|
|
|
0
|
1
|
|
my $oct = shift; |
115
|
0
|
0
|
|
|
|
|
return unless defined $oct; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $list = [ split( //, unpack( "B*", $oct ) ) ]; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return $list; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
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__ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=pod |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 NAME |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
SNMP::Insight::MIB - Base role for MIBs |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 VERSION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
version 0.002 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 FUNCTIONS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 munge_bool() |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Takes a BOOLEAN and makes it a nop|true|false string |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 munge_ipaddress() |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Takes a binary IP and makes it dotted ASCII |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 munge_macaddress() |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Takes an octet stream (HEX-STRING) and returns a colon separated ASCII hex |
156
|
|
|
|
|
|
|
string. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 munge_octet2hex() |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Takes a binary octet stream and returns an ASCII hex string |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 munge_bits |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Takes a 'BITS' field and returns to an ASCII bit string |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 munge_counter64 |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Return a Math::BigInt object. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 munge_ifoperstatus |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Munge enumeration for C<ifOperStatus> in C<IF-MIB>. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 munge_port_list |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Takes an octet string representing a set of ports and returns a reference |
177
|
|
|
|
|
|
|
to an array of binary values each array element representing a port. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHOR |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Gabriele Mambrini <g.mambrini@gmail.com> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Gabriele Mambrini. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
188
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |