line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SNMP::Insight; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: SNMP Moose interface |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
16031
|
use 5.010; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
153
|
|
6
|
4
|
|
|
4
|
|
16
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
117
|
|
7
|
4
|
|
|
4
|
|
15
|
use warnings FATAL => 'all'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
377
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.001'; # TRIAL VERSION: |
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
548
|
use Module::Runtime 0.014 'use_package_optimistically'; |
|
4
|
|
|
|
|
1403
|
|
|
4
|
|
|
|
|
25
|
|
12
|
4
|
|
|
4
|
|
846
|
use Moose::Util 'is_role'; |
|
4
|
|
|
|
|
124892
|
|
|
4
|
|
|
|
|
32
|
|
13
|
4
|
|
|
4
|
|
2416
|
use SNMP::Insight::Device; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
2029
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub open { |
16
|
1
|
|
|
1
|
1
|
8
|
my %args = @_; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
2
|
my $session = $args{session}; |
19
|
1
|
50
|
|
|
|
3
|
if ( !defined($session) ) { |
20
|
0
|
|
0
|
|
|
0
|
my $session_class |
21
|
|
|
|
|
|
|
= $args{session_class} || 'SNMP::Insight::Session::NetSNMP'; |
22
|
0
|
|
|
|
|
0
|
$session = _load_class( |
23
|
|
|
|
|
|
|
$session_class, |
24
|
0
|
|
|
|
|
0
|
'SNMP::Insight::Session', @{ $args{snmp_params} } |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
38
|
my $device = SNMP::Insight::Device->new( session => $session ); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
50
|
|
|
6
|
my $classifier_class = $args{classifier} || 'SNMP::Insight::Classifier'; |
31
|
1
|
|
|
|
|
3
|
my $classifier = _load_class( |
32
|
|
|
|
|
|
|
$classifier_class, 'SNMP::Insight::Classifier', |
33
|
|
|
|
|
|
|
device => $device |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
435
|
my $device_role = $classifier->classify(); |
37
|
|
|
|
|
|
|
|
38
|
1
|
50
|
|
|
|
4
|
if ( !$device_role ) { |
39
|
0
|
0
|
|
|
|
0
|
debug() and print "debug: no info from classifier"; |
40
|
0
|
|
|
|
|
0
|
return $device; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
8
|
debug() and print "debug: classifier returned $device_role"; |
44
|
1
|
|
|
|
|
9
|
my $role_package |
45
|
|
|
|
|
|
|
= _load_device_role( $device_role, 'SNMP::Insight::Device' ); |
46
|
1
|
50
|
|
|
|
39
|
if ($role_package) { |
47
|
1
|
|
|
|
|
7
|
$role_package->meta->apply($device); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
0
|
|
|
|
|
0
|
warn "$role_package not found, using bare device"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
368241
|
return $device; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _load_class { |
57
|
1
|
|
|
1
|
|
3
|
my ( $class_name, $search_base, %options ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
3
|
my $possible_full_name = $search_base . "::" . $class_name; |
60
|
1
|
|
|
|
|
3
|
my @possible = ( $possible_full_name, $class_name ); |
61
|
1
|
|
|
|
|
2
|
for my $name (@possible) { |
62
|
2
|
|
|
|
|
6
|
my $package = use_package_optimistically($name); |
63
|
2
|
100
|
|
|
|
362
|
$package->can('new') and return $package->new(%options); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _load_device_role { |
70
|
1
|
|
|
1
|
|
2
|
my ( $role_name, $search_base ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
3
|
my $possible_full_name = $search_base . "::" . $role_name; |
73
|
1
|
|
|
|
|
3
|
my @possible = ( $possible_full_name, $role_name ); |
74
|
1
|
|
|
|
|
2
|
for my $name (@possible) { |
75
|
1
|
|
|
|
|
4
|
my $package = use_package_optimistically($name); |
76
|
1
|
|
|
|
|
13
|
use_package_optimistically($name); |
77
|
1
|
50
|
|
|
|
48
|
is_role($package) and return $package; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub debug { |
84
|
41
|
|
|
41
|
1
|
221
|
return $ENV{SNMP_EASY_DEBUG}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; # End of SNMP::Insight |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Local Variables: |
90
|
|
|
|
|
|
|
# mode: cperl |
91
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
92
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
93
|
|
|
|
|
|
|
# cperl-indent-parens-as-block: t |
94
|
|
|
|
|
|
|
# End: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=pod |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 NAME |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
SNMP::Insight - SNMP Moose interface |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 VERSION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
version 0.001 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SYNOPSIS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
SNMP Moose interface: |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
use SNMP::Insight; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $device = SNMP::Insight::open( |
115
|
|
|
|
|
|
|
snmp_params => { |
116
|
|
|
|
|
|
|
hostname => 'localhost', |
117
|
|
|
|
|
|
|
community => 'public', |
118
|
|
|
|
|
|
|
version => "2c", |
119
|
|
|
|
|
|
|
}); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
... |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 DESCRIPTION |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
SNMP::Insight is a Perl 5 module that provides a simple Object Oriented inteface to access SNMP enabled devices and to describe SNMP MIBs and devices. SNMP::Insight it's based on Moose and uses Net::SNMP for a pure Perl SNMP implementation. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Warning: this release is still alpha quality! |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 FUNCTIONS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 open() |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Create a SNMP::Insight::Device object, loading all the needed MIBS. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 debug |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Internal |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SEE ALSO |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 4 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
* In the SNMP::Insight distribution |
148
|
|
|
|
|
|
|
L<SNMP::Insight::Session> |
149
|
|
|
|
|
|
|
L<SNMP::Insight::Device> |
150
|
|
|
|
|
|
|
L<SNMP::Insight::Classifier> |
151
|
|
|
|
|
|
|
L<SNMP::Insight::MIB> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
* Similar modules on CPAN L<SNMP::Info> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 AUTHOR |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Gabriele Mambrini <g.mambrini@gmail.com> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Gabriele Mambrini. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
164
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |