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