line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SNMP::Mixin::System; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2342
|
use 5.006; |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
302
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
25
|
|
|
4
|
|
|
|
|
149
|
|
5
|
4
|
|
|
4
|
|
24
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
308
|
|
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
|
|
31
|
use Carp (); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
98
|
|
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
4
|
|
2432
|
use Net::SNMP::Mixin::Util qw/ push_error /; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
35
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# this module export config |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
my @mixin_methods; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN { |
24
|
4
|
|
|
4
|
|
2030
|
@mixin_methods = ( qw/get_system_group/); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
|
|
42
|
use Sub::Exporter -setup => { |
28
|
|
|
|
|
|
|
exports => [@mixin_methods], |
29
|
|
|
|
|
|
|
groups => { default => [@mixin_methods], }, |
30
|
4
|
|
|
4
|
|
37
|
}; |
|
4
|
|
|
|
|
11
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# SNMP oid constants used in this module |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
use constant { |
35
|
4
|
|
|
|
|
12299
|
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
|
|
2588
|
}; |
|
4
|
|
|
|
|
8
|
|
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.12 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
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 qw/mixer init_mixins/; |
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() if $session->nonblocking; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
die $session->error if $session->error; |
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
|
1217
|
my $session = shift; |
98
|
1
|
50
|
|
|
|
242
|
Carp::croak "'$prefix' not initialized," |
99
|
|
|
|
|
|
|
unless $session->{$prefix}{__initialized}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# just a shallow copy for shallow values |
102
|
0
|
|
|
|
|
|
return { %{ $session->{$prefix}{sysGroup} } }; |
|
0
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 INITIALIZATION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 B<< OBJ->_init($reload) >> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
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. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _init { |
116
|
0
|
|
|
0
|
|
|
my ($session, $reload) = @_; |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
0
|
|
|
|
die "$prefix already initalized and reload not forced.\n" |
119
|
|
|
|
|
|
|
if $session->{$prefix}{__initialized} && not $reload; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# initialize the object system-group infos |
122
|
0
|
|
|
|
|
|
my $success = _fetch_system_group($session); |
123
|
0
|
0
|
|
|
|
|
$success ? return 1 : return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 PRIVATE METHODS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Only for developers or maintainers. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 B<< _fetch_system_group($session) >> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Fetch values from the system-group once during object initialization. Push error message onto the error buffer in case of failure and returns nothing. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _fetch_system_group { |
137
|
0
|
|
|
0
|
|
|
my $session = shift; |
138
|
0
|
|
|
|
|
|
my $result; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# fetch the mib-II system-group |
141
|
0
|
0
|
|
|
|
|
$result = $session->get_request( |
142
|
|
|
|
|
|
|
-varbindlist => [ |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
SYS_DESCR, |
145
|
|
|
|
|
|
|
SYS_OBJECT_ID, |
146
|
|
|
|
|
|
|
SYS_UP_TIME, |
147
|
|
|
|
|
|
|
SYS_CONTACT, |
148
|
|
|
|
|
|
|
SYS_NAME, |
149
|
|
|
|
|
|
|
SYS_LOCATION, |
150
|
|
|
|
|
|
|
SYS_SERVICES, |
151
|
|
|
|
|
|
|
], |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# define callback if in nonblocking mode |
154
|
|
|
|
|
|
|
$session->nonblocking ? ( -callback => \&_system_group_cb ) : (), |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
|
unless (defined $result) { |
158
|
0
|
0
|
|
|
|
|
if (my $err_msg = $session->error) { |
159
|
0
|
|
|
|
|
|
push_error($session, "$prefix: $err_msg"); |
160
|
|
|
|
|
|
|
}; |
161
|
0
|
|
|
|
|
|
return; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# in nonblocking mode the callback will be called asynchronously |
165
|
0
|
0
|
|
|
|
|
return 1 if $session->nonblocking; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# ok we are in synchronous mode, call the result mangling function |
168
|
|
|
|
|
|
|
# by hand |
169
|
0
|
|
|
|
|
|
_system_group_cb($session); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 B<< _system_group_cb($session) >> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
The callback for _fetch_system_group. Push error message onto the error buffer in case of failure and returns nothing. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub _system_group_cb { |
180
|
0
|
|
|
0
|
|
|
my $session = shift; |
181
|
0
|
|
|
|
|
|
my $vbl = $session->var_bind_list; |
182
|
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
unless (defined $vbl) { |
184
|
0
|
0
|
|
|
|
|
if (my $err_msg = $session->error) { |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Net::SNMP looses sometimes error messages in nonblocking |
187
|
|
|
|
|
|
|
# mode, so we save them in an extra buffer |
188
|
0
|
|
|
|
|
|
push_error($session, "$prefix: $err_msg"); |
189
|
|
|
|
|
|
|
}; |
190
|
0
|
|
|
|
|
|
return; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysDescr} = $vbl->{ SYS_DESCR() }; |
195
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysObjectID} = $vbl->{ SYS_OBJECT_ID() }; |
196
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysUpTime} = $vbl->{ SYS_UP_TIME() }; |
197
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysContact} = $vbl->{ SYS_CONTACT() }; |
198
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysName} = $vbl->{ SYS_NAME() }; |
199
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysLocation} = $vbl->{ SYS_LOCATION() }; |
200
|
0
|
|
|
|
|
|
$session->{$prefix}{sysGroup}{sysServices} = $vbl->{ SYS_SERVICES() }; |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
$session->{$prefix}{__initialized}++; |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
return 1; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
unless ( caller() ) { |
208
|
|
|
|
|
|
|
print "$prefix compiles and initializes successful.\n"; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 BUGS, PATCHES & FIXES |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
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. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
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 . |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
RT: http://rt.cpan.org/Public/Dist/Display.html?Name=Net-SNMP-Mixin |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 AUTHOR |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Karl Gaissmaier |
222
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Copyright 2008 Karl Gaissmaier, all rights reserved. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
227
|
|
|
|
|
|
|
under the same terms as Perl itself. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=cut |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
1; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# vim: sw=2 |