| 1 | package Monitoring::Sneck::Boop_Snoot; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use String::ShellQuote; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Gzip::Faster; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | 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 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my %args; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( defined( $_[1] ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | %args = %{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ( $self->{version} ne '1' && $self->{version} ne '2c' && $self->{version} ne '3' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"version"} ne 1 and $self->{"version"} ne "2c" and $self->{"version"} ne 3
$self->{"version"} ne 1 and $self->{"version"} ne "2c"
MC/DC0%0/3
$self->{"version"} ne 1 and $self->{"version"} ne "2c" and $self->{"version"} ne 3
$self->{"version"} ne 1
$self->{"version"} ne "2c"
$self->{"version"} ne 3
Truth table0%0/4
A and B and C
A= $self->{"version"} ne 1B= $self->{"version"} ne "2c"C= $self->{"version"} ne 3
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub boop_the_snoot { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
boop_the_snoot: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $host = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # makes sure we have a good host | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ( !defined($host) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ( $self->{version} eq '1' || $self->{version} eq '2c' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"version"} eq 1 or $self->{"version"} eq "2c"
MC/DC0%0/2
$self->{"version"} eq 1 or $self->{"version"} eq "2c"
$self->{"version"} eq 1
$self->{"version"} eq "2c"
Truth table0%0/3
A or B
A= $self->{"version"} eq 1B= $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 | ▶ | if ( defined( $self->{$auth_key} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ( $exit_code == -1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | die('failed to execute snmpget'); | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | elsif ( $exit_code & 127 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | die( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ( $exit_code != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ($json =~ /^[A-Za-z0-9\/\+\n]+\=*\n*$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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<< <vvelox at vvelox.net> >> | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | Please report any bugs or feature requests to C<bug-monitoring-sneck-boop_snoot at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||||||||
| 175 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Monitoring-Sneck-Boop_Snoot>. 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<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Monitoring-Sneck-Boop_Snoot> | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | L<https://cpanratings.perl.org/d/Monitoring-Sneck-Boop_Snoot> | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | L<https://metacpan.org/release/Monitoring-Sneck-Boop_Snoot> | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | =item * Github | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | L<https://github.com/VVelox/Monitoring-Sneck-Boop_Snoot> | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | =item * Repo | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | L<https://github.com/VVelox/Monitoring-Sneck-Boop_Snoot.git> | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 1; # End of Monitoring::Sneck::Boop_Snoot | |||||||||||||||||||||||||||||||||||||||||