line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Sneck::Boop_Snoot; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
61731
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
10
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
420
|
use String::ShellQuote; |
|
1
|
|
|
|
|
780
|
|
|
1
|
|
|
|
|
73
|
|
7
|
1
|
|
|
1
|
|
419
|
use MIME::Base64; |
|
1
|
|
|
|
|
671
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
501
|
use Gzip::Faster; |
|
1
|
|
|
|
|
1177
|
|
|
1
|
|
|
|
|
634
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Monitoring::Sneck::Boop_Snoot - Boop the Monitoring::Sneck's snoot via SNMP |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.2.0 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.2.0'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Monitoring::Sneck::Boop_Snoot; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $sneck_snoot_booper = Monitoring::Sneck::Boop_Snoot->new({ |
27
|
|
|
|
|
|
|
version=>'2c', |
28
|
|
|
|
|
|
|
community=>'public', |
29
|
|
|
|
|
|
|
}); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 new |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Initiates the object. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
version Version to use. 1, 2c, or 3 |
38
|
|
|
|
|
|
|
Default: 2c |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
SNMP Version 1 or 2c specific |
41
|
|
|
|
|
|
|
community set the community string |
42
|
|
|
|
|
|
|
Default: public |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
SNMP Version 3 specific |
45
|
|
|
|
|
|
|
a set authentication protocol (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512) |
46
|
|
|
|
|
|
|
A set authentication protocol pass phrase |
47
|
|
|
|
|
|
|
e set security engine ID (e.g. 800000020109840301) |
48
|
|
|
|
|
|
|
E set context engine ID (e.g. 800000020109840301) |
49
|
|
|
|
|
|
|
l set security level (noAuthNoPriv|authNoPriv|authPriv) |
50
|
|
|
|
|
|
|
n set context name (e.g. bridge1) |
51
|
|
|
|
|
|
|
u set security name (e.g. bert) |
52
|
|
|
|
|
|
|
x set privacy protocol (DES|AES) |
53
|
|
|
|
|
|
|
X set privacy protocol pass phrase |
54
|
|
|
|
|
|
|
Z set destination engine boots/time |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $sneck_snoot_booper = Monitoring::Sneck::Boop_Snoot->new({ |
57
|
|
|
|
|
|
|
version=>'2c', |
58
|
|
|
|
|
|
|
community=>'public', |
59
|
|
|
|
|
|
|
}); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub new { |
64
|
0
|
|
|
0
|
1
|
|
my %args; |
65
|
0
|
0
|
|
|
|
|
if ( defined( $_[1] ) ) { |
66
|
0
|
|
|
|
|
|
%args = %{ $_[1] }; |
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $self = { |
70
|
|
|
|
|
|
|
version => '2c', |
71
|
|
|
|
|
|
|
community => 'public', |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
foreach my $arg_key ( keys(%args) ) { |
75
|
0
|
|
|
|
|
|
$self->{$arg_key} = shell_quote( $args{$arg_key} ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
0
|
|
|
|
if ( $self->{version} ne '1' && $self->{version} ne '2c' && $self->{version} ne '3' ) { |
|
|
|
0
|
|
|
|
|
79
|
0
|
|
|
|
|
|
die( '"' . $self->{version} . '" is not a recognized version' ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
bless $self; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $self; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 boop_the_snoot |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Fetches the data for the host and returns it. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
One option is taken and that is the hostname to poll. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This will die on snmpget failure. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $raw_json=$$sneck_snoot_booper->boop_the_snoot($host); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub boop_the_snoot { |
100
|
0
|
|
|
0
|
1
|
|
my $self = $_[0]; |
101
|
0
|
|
|
|
|
|
my $host = $_[1]; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# makes sure we have a good host |
104
|
0
|
0
|
|
|
|
|
if ( !defined($host) ) { |
105
|
0
|
|
|
|
|
|
die('No host specified'); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# quote the host so we can safely use it |
109
|
0
|
|
|
|
|
|
$host = shell_quote($host); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# put together the auth string to use |
112
|
0
|
|
|
|
|
|
my $auth_string = '-v ' . $self->{version}; |
113
|
0
|
0
|
0
|
|
|
|
if ( $self->{version} eq '1' || $self->{version} eq '2c' ) { |
114
|
0
|
|
|
|
|
|
$auth_string = $auth_string . ' -c ' . $self->{community}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else { |
117
|
0
|
|
|
|
|
|
my @auth_keys = ( 'a', 'A', 'e', 'E', 'l', 'n', 'u', 'x', 'X', 'Z' ); |
118
|
0
|
|
|
|
|
|
foreach my $auth_key (@auth_keys) { |
119
|
0
|
0
|
|
|
|
|
if ( defined( $self->{$auth_key} ) ) { |
120
|
0
|
|
|
|
|
|
$auth_string = $auth_string . ' -' . $auth_key . ' ' . shell_quote( $self->{$auth_key} ); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# the the snmpget command |
126
|
0
|
|
|
|
|
|
my $returned |
127
|
|
|
|
|
|
|
= `snmpget -Onq -v $self->{version} $auth_string $host 1.3.6.1.4.1.8072.1.3.2.3.1.2.5.115.110.101.99.107`; |
128
|
0
|
|
|
|
|
|
my $exit_code = $?; |
129
|
0
|
|
|
|
|
|
chomp($returned); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# handle the exit code |
132
|
0
|
|
|
|
|
|
my $exit_error = ''; |
133
|
0
|
0
|
|
|
|
|
if ( $exit_code == -1 ) { |
|
|
0
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
die('failed to execute snmpget'); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
elsif ( $exit_code & 127 ) { |
137
|
0
|
0
|
|
|
|
|
die( |
138
|
|
|
|
|
|
|
sprintf( |
139
|
|
|
|
|
|
|
"child died with signal %d, %s coredump\n", |
140
|
|
|
|
|
|
|
( $exit_code & 127 ), |
141
|
|
|
|
|
|
|
( $exit_code & 128 ) ? 'with' : 'without' |
142
|
|
|
|
|
|
|
) |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
else { |
146
|
0
|
|
|
|
|
|
$exit_code = $exit_code >> 8; |
147
|
0
|
0
|
|
|
|
|
if ( $exit_code != 0 ) { |
148
|
0
|
|
|
|
|
|
die( 'snmpget exited with ' . $exit_code ); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# clean it up incase it is on a system that quotes everything |
153
|
0
|
|
|
|
|
|
$returned =~ s/\\([^nbfrt\\])/$1/g; |
154
|
0
|
|
|
|
|
|
$returned =~ s/^\"//; |
155
|
0
|
|
|
|
|
|
$returned =~ s/\"$//; |
156
|
0
|
|
|
|
|
|
my ( $oid, $json ) = split( /\ +/, $returned, 2 ); |
157
|
0
|
|
|
|
|
|
$json =~ s/^\"//; |
158
|
0
|
|
|
|
|
|
$json =~ s/\"$//; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# check for base64 incasae the return has been gzipped |
161
|
0
|
0
|
|
|
|
|
if ($json =~ /^[A-Za-z0-9\/\+\n]+\=*\n*$/ ) { |
162
|
0
|
|
|
|
|
|
$json = gunzip(decode_base64($json)); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
return $json; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Zane C. Bowers-Hadley, C<< >> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 BUGS |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
175
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
176
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 SUPPORT |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
perldoc Monitoring::Sneck::Boop_Snoot |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
You can also look for information at: |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=over 4 |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item * CPAN Ratings |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
L |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * Search CPAN |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
L |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * Github |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * Repo |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Zane C. Bowers-Hadley. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This is free software, licensed under: |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
1; # End of Monitoring::Sneck::Boop_Snoot |