line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SNMP::Mixin::System; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1902
|
use 5.006; |
|
4
|
|
|
|
|
10
|
|
4
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
93
|
|
5
|
4
|
|
|
4
|
|
17
|
use strict; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
109
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# store this package name in a handy variable, |
8
|
|
|
|
|
|
|
# used for unambiguous prefix of mixin attributes |
9
|
|
|
|
|
|
|
# storage in object hash |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
my $prefix = __PACKAGE__; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# this module import config |
14
|
|
|
|
|
|
|
# |
15
|
4
|
|
|
4
|
|
12
|
use Carp (); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
69
|
|
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
4
|
|
15
|
use Net::SNMP::Mixin::Util qw/push_error get_init_slot/; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
22
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# this module export config |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
my @mixin_methods; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN { |
24
|
4
|
|
|
4
|
|
1035
|
@mixin_methods = ( qw/get_system_group/); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
|
|
33
|
use Sub::Exporter -setup => { |
28
|
|
|
|
|
|
|
exports => [@mixin_methods], |
29
|
|
|
|
|
|
|
groups => { default => [@mixin_methods], }, |
30
|
4
|
|
|
4
|
|
18
|
}; |
|
4
|
|
|
|
|
3
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# SNMP oid constants used in this module |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
use constant { |
35
|
4
|
|
|
|
|
828
|
SYS_DESCR => '1.3.6.1.2.1.1.1.0', |
36
|
|
|
|
|
|
|
SYS_OBJECT_ID => '1.3.6.1.2.1.1.2.0', |
37
|
|
|
|
|
|
|
SYS_UP_TIME => '1.3.6.1.2.1.1.3.0', |
38
|
|
|
|
|
|
|
SYS_CONTACT => '1.3.6.1.2.1.1.4.0', |
39
|
|
|
|
|
|
|
SYS_NAME => '1.3.6.1.2.1.1.5.0', |
40
|
|
|
|
|
|
|
SYS_LOCATION => '1.3.6.1.2.1.1.6.0', |
41
|
|
|
|
|
|
|
SYS_SERVICES => '1.3.6.1.2.1.1.7.0', |
42
|
4
|
|
|
4
|
|
1143
|
}; |
|
4
|
|
|
|
|
5
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Net::SNMP::Mixin::System - mixin class for the mib-2 system-group values |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 VERSION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Version 0.14 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
A Net::SNMP mixin class for mib-II system-group info. It's just in the distribution to act as a blueprint for mixin authors. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Net::SNMP; |
61
|
|
|
|
|
|
|
use Net::SNMP::Mixin; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $session = Net::SNMP->session( -hostname => 'foo.bar.com' ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$session->mixer('Net::SNMP::Mixin::System'); |
66
|
|
|
|
|
|
|
$session->init_mixins; |
67
|
|
|
|
|
|
|
snmp_dispatcher(); |
68
|
|
|
|
|
|
|
$session->init_ok(); |
69
|
|
|
|
|
|
|
die $session->errors if $session->errors; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $system_group = $session->get_system_group; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
printf "Name: %s, Contact: %s, Location: %s\n", |
74
|
|
|
|
|
|
|
$system_group->{sysName}, |
75
|
|
|
|
|
|
|
$system_group->{sysContact}, |
76
|
|
|
|
|
|
|
$system_group->{sysLocation}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 MIXIN METHODS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 B<< OBJ->get_system_group() >> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Returns the mib-II system-group as a hash reference: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
{ |
85
|
|
|
|
|
|
|
sysDescr => DisplayString, |
86
|
|
|
|
|
|
|
sysObjectID => OBJECT_IDENTIFIER, |
87
|
|
|
|
|
|
|
sysUpTime => TimeTicks, |
88
|
|
|
|
|
|
|
sysContact => DisplayString, |
89
|
|
|
|
|
|
|
sysName => DisplayString, |
90
|
|
|
|
|
|
|
sysLocation => DisplayString, |
91
|
|
|
|
|
|
|
sysServices => INTEGER, |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_system_group { |
97
|
1
|
|
|
1
|
1
|
735
|
my $session = shift; |
98
|
1
|
|
|
|
|
5
|
my $agent = $session->hostname; |
99
|
|
|
|
|
|
|
|
100
|
1
|
50
|
|
|
|
7
|
Carp::croak "$agent: '$prefix' not initialized," |
101
|
|
|
|
|
|
|
unless $session->init_ok($prefix); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# just a shallow copy for shallow values |
104
|
0
|
|
|
|
|
|
return { %{ $session->{$prefix}{sysGroup} } }; |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 INITIALIZATION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 B<< OBJ->_init($reload) >> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Fetch the SNMP mib-II system-group values from the host. Don't call this method direct! Returns nothing in case of failure so init_mixins can stop initialization. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# |
118
|
|
|
|
|
|
|
# due to the asynchron nature, we don't know what init job is really the last, we decrement |
119
|
|
|
|
|
|
|
# the value after each callback |
120
|
|
|
|
|
|
|
# |
121
|
4
|
|
|
4
|
|
17
|
use constant THIS_INIT_JOBS => 1; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
1579
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _init { |
124
|
0
|
|
|
0
|
|
|
my ( $session, $reload ) = @_; |
125
|
0
|
|
|
|
|
|
my $agent = $session->hostname; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
die "$agent: $prefix already initialized and reload not forced.\n" |
128
|
|
|
|
|
|
|
if exists get_init_slot($session)->{$prefix} |
129
|
0
|
0
|
0
|
|
|
|
&& get_init_slot($session)->{$prefix} == 0 |
|
|
|
0
|
|
|
|
|
130
|
|
|
|
|
|
|
&& not $reload; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# set number of async init jobs for proper initialization |
133
|
0
|
|
|
|
|
|
get_init_slot($session)->{$prefix} = THIS_INIT_JOBS; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# initialize the object system-group infos |
136
|
0
|
|
|
|
|
|
my $success = _fetch_system_group($session); |
137
|
0
|
0
|
|
|
|
|
$success ? return 1 : return; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 PRIVATE METHODS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Only for developers or maintainers. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 B<< _fetch_system_group($session) >> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Fetch values from the system-group once during object initialization. Push error message onto the error buffer in case of failure and returns nothing. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _fetch_system_group { |
151
|
0
|
|
|
0
|
|
|
my $session = shift; |
152
|
0
|
|
|
|
|
|
my $result; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# fetch the mib-II system-group |
155
|
0
|
0
|
|
|
|
|
$result = $session->get_request( |
156
|
|
|
|
|
|
|
-varbindlist => [ |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
SYS_DESCR, |
159
|
|
|
|
|
|
|
SYS_OBJECT_ID, |
160
|
|
|
|
|
|
|
SYS_UP_TIME, |
161
|
|
|
|
|
|
|
SYS_CONTACT, |
162
|
|
|
|
|
|
|
SYS_NAME, |
163
|
|
|
|
|
|
|
SYS_LOCATION, |
164
|
|
|
|
|
|
|
SYS_SERVICES, |
165
|
|
|
|
|
|
|
], |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# define callback if in nonblocking mode |
168
|
|
|
|
|
|
|
$session->nonblocking ? ( -callback => \&_system_group_cb ) : (), |
169
|
|
|
|
|
|
|
); |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
unless (defined $result) { |
172
|
0
|
0
|
|
|
|
|
if (my $err_msg = $session->error) { |
173
|
0
|
|
|
|
|
|
push_error($session, "$prefix: $err_msg"); |
174
|
|
|
|
|
|
|
}; |
175
|
0
|
|
|
|
|
|
return; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# in nonblocking mode the callback will be called asynchronously |
179
|
0
|
0
|
|
|
|
|
return 1 if $session->nonblocking; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# ok we are in synchronous mode, call the result mangling function |
182
|
|
|
|
|
|
|
# by hand |
183
|
0
|
|
|
|
|
|
_system_group_cb($session); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 B<< _system_group_cb($session) >> |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
The callback for _fetch_system_group. Push error message onto the error buffer in case of failure and returns nothing. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _system_group_cb { |
194
|
0
|
|
|
0
|
|
|
my $session = shift; |
195
|
0
|
|
|
|
|
|
my $vbl = $session->var_bind_list; |
196
|
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
unless (defined $vbl) { |
198
|
0
|
0
|
|
|
|
|
if (my $err_msg = $session->error) { |
199
|
0
|
|
|
|
|
|
push_error($session, "$prefix: $err_msg"); |
200
|
|
|
|
|
|
|
}; |
201
|
0
|
|
|
|
|
|
return; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysDescr} = $vbl->{ SYS_DESCR() }; |
205
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysObjectID} = $vbl->{ SYS_OBJECT_ID() }; |
206
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysUpTime} = $vbl->{ SYS_UP_TIME() }; |
207
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysContact} = $vbl->{ SYS_CONTACT() }; |
208
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysName} = $vbl->{ SYS_NAME() }; |
209
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysLocation} = $vbl->{ SYS_LOCATION() }; |
210
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysServices} = $vbl->{ SYS_SERVICES() }; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# this init job is finished |
213
|
0
|
|
|
|
|
|
get_init_slot($session)->{$prefix}--; |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
return 1; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
unless ( caller() ) { |
219
|
|
|
|
|
|
|
print "$prefix compiles and initializes successful.\n"; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 BUGS, PATCHES & FIXES |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
There are no known bugs at the time of this release. However, if you spot a bug or are experiencing difficulties that are not explained within the POD documentation, please submit a bug to the RT system (see link below). However, it would help greatly if you are able to pinpoint problems or even supply a patch. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Fixes are dependant upon their severity and my availablity. Should a fix not be forthcoming, please feel free to (politely) remind me by sending an email to gaissmai@cpan.org . |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
RT: http://rt.cpan.org/Public/Dist/Display.html?Name=Net-SNMP-Mixin |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 AUTHOR |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Karl Gaissmaier |
233
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Copyright 2008-2015 Karl Gaissmaier, all rights reserved. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
238
|
|
|
|
|
|
|
under the same terms as Perl itself. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
1; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
# vim: sw=2 |