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