mostly done
This commit is contained in:
parent
9f117ca740
commit
11783bc513
|
@ -0,0 +1,5 @@
|
|||
Revision history for Monitoring-Sneck-Boop_Snoot
|
||||
|
||||
0.01 Date/time
|
||||
First version, released on an unsuspecting world.
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Changes
|
||||
lib/Monitoring/Sneck/Boop_Snoot.pm
|
||||
Makefile.PL
|
||||
MANIFEST This list of files
|
||||
README
|
||||
t/00-load.t
|
||||
t/manifest.t
|
||||
t/pod-coverage.t
|
||||
t/pod.t
|
|
@ -0,0 +1,56 @@
|
|||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
my %WriteMakefileArgs = (
|
||||
NAME => 'Monitoring::Sneck::Boop_Snoot',
|
||||
AUTHOR => q{Zane C. Bowers-Hadley <vvelox@vvelox.net>},
|
||||
VERSION_FROM => 'lib/Monitoring/Sneck/Boop_Snoot.pm',
|
||||
ABSTRACT_FROM => 'lib/Monitoring/Sneck/Boop_Snoot.pm',
|
||||
LICENSE => 'artistic_2',
|
||||
MIN_PERL_VERSION => '5.006',
|
||||
INST_SCRIPT => 'bin',
|
||||
CONFIGURE_REQUIRES => {
|
||||
'ExtUtils::MakeMaker' => '0',
|
||||
},
|
||||
TEST_REQUIRES => {
|
||||
'Test::More' => '0',
|
||||
},
|
||||
PREREQ_PM => {
|
||||
'JSON' => '0',
|
||||
'String::ShellQuote' => '0',
|
||||
},
|
||||
META_MERGE => {
|
||||
"meta-spec" => { version => 2 },
|
||||
resources => {
|
||||
repository => {
|
||||
type => 'git',
|
||||
url => 'https://github.com/VVelox/Monitoring-Sneck-Boop_Snoot.git',
|
||||
web => 'https://github.com/VVelox/Monitoring-Sneck-Boop_Snoot',
|
||||
},
|
||||
},
|
||||
},
|
||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||
clean => { FILES => 'Monitoring-Sneck-Boop_Snoot-*' },
|
||||
);
|
||||
|
||||
# Compatibility with old versions of ExtUtils::MakeMaker
|
||||
unless ( eval { ExtUtils::MakeMaker->VERSION('6.64'); 1 } ) {
|
||||
my $test_requires = delete $WriteMakefileArgs{TEST_REQUIRES} || {};
|
||||
@{ $WriteMakefileArgs{PREREQ_PM} }{ keys %$test_requires } = values %$test_requires;
|
||||
}
|
||||
|
||||
unless ( eval { ExtUtils::MakeMaker->VERSION('6.55_03'); 1 } ) {
|
||||
my $build_requires = delete $WriteMakefileArgs{BUILD_REQUIRES} || {};
|
||||
@{ $WriteMakefileArgs{PREREQ_PM} }{ keys %$build_requires } = values %$build_requires;
|
||||
}
|
||||
|
||||
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
|
||||
unless eval { ExtUtils::MakeMaker->VERSION('6.52'); 1 };
|
||||
delete $WriteMakefileArgs{MIN_PERL_VERSION}
|
||||
unless eval { ExtUtils::MakeMaker->VERSION('6.48'); 1 };
|
||||
delete $WriteMakefileArgs{LICENSE}
|
||||
unless eval { ExtUtils::MakeMaker->VERSION('6.31'); 1 };
|
||||
|
||||
WriteMakefile(%WriteMakefileArgs);
|
|
@ -0,0 +1,46 @@
|
|||
Monitoring-Sneck-Boop_Snoot
|
||||
|
||||
|
||||
|
||||
INSTALLATION
|
||||
|
||||
To install this module, run the following commands:
|
||||
|
||||
perl Makefile.PL
|
||||
make
|
||||
make test
|
||||
make install
|
||||
|
||||
SUPPORT AND DOCUMENTATION
|
||||
|
||||
After installing, you can find documentation for this module with the
|
||||
perldoc command.
|
||||
|
||||
perldoc Monitoring::Sneck::Boop_Snoot
|
||||
|
||||
You can also look for information at:
|
||||
|
||||
RT, CPAN's request tracker (report bugs here)
|
||||
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Monitoring-Sneck-Boop_Snoot
|
||||
|
||||
CPAN Ratings
|
||||
https://cpanratings.perl.org/d/Monitoring-Sneck-Boop_Snoot
|
||||
|
||||
Search CPAN
|
||||
https://metacpan.org/release/Monitoring-Sneck-Boop_Snoot
|
||||
|
||||
Github
|
||||
https://github.com/VVelox/Monitoring-Sneck-Boop_Snoot
|
||||
|
||||
Repo
|
||||
https://github.com/VVelox/Monitoring-Sneck-Boop_Snoot.git
|
||||
|
||||
|
||||
LICENSE AND COPYRIGHT
|
||||
|
||||
This software is Copyright (c) 2022 by Zane C. Bowers-Hadley.
|
||||
|
||||
This is free software, licensed under:
|
||||
|
||||
The Artistic License 2.0 (GPL Compatible)
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
use JSON;
|
||||
use Monitoring::Sneck::Boop_Snoot;
|
||||
|
||||
sub prog_version {
|
||||
print "sneck v. 0.0.1\n";
|
||||
}
|
||||
|
||||
sub help {
|
||||
&proc_version;
|
||||
|
||||
print '
|
||||
|
||||
boop_snoot <args> <host>
|
||||
|
||||
-p Do not pretty print.
|
||||
|
||||
-s Do not Sort the keys.
|
||||
|
||||
-v <version > Version to use. 1, 2c, or 3
|
||||
Default: 2c
|
||||
|
||||
SNMP Version 1 or 2c specific
|
||||
-c <community> SNMP community stream.
|
||||
Default: public
|
||||
|
||||
SNMP Version 3
|
||||
-a <value> Set authentication protocol (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512)
|
||||
-A <value> Set authentication protocol pass phrase
|
||||
-e <value> Set security engine ID (e.g. 800000020109840301)
|
||||
-E <value> Set context engine ID (e.g. 800000020109840301)
|
||||
-l <value> Set security level (noAuthNoPriv|authNoPriv|authPriv)
|
||||
-n <value> Set context name (e.g. bridge1)
|
||||
-u <value> Set security name (e.g. bert)
|
||||
-x <value> Set privacy protocol (DES|AES)
|
||||
-X <value> Set privacy protocol pass phrase
|
||||
-Z <value> Set destination engine boots/time
|
||||
|
||||
-h Print help info.
|
||||
--help Print help info.
|
||||
--version Print version info.
|
||||
|
||||
';
|
||||
}
|
||||
|
||||
my $community = 'public';
|
||||
my $version = '2c';
|
||||
my $a;
|
||||
my $A;
|
||||
my $e;
|
||||
my $E;
|
||||
my $l;
|
||||
my $n;
|
||||
my $u;
|
||||
my $x;
|
||||
my $X;
|
||||
my $Z;
|
||||
my $prog_version;
|
||||
my $help;
|
||||
my $pretty;
|
||||
my $sort;
|
||||
Getopt::Long::Configure('no_ignore_case');
|
||||
Getopt::Long::Configure('bundling');
|
||||
GetOptions(
|
||||
'version' => \$prog_version,
|
||||
'v' => \$version,
|
||||
'help' => \$help,
|
||||
'h' => \$help,
|
||||
'c=s' => \$community,
|
||||
'a=s' => \$a,
|
||||
'A=s' => \$A,
|
||||
'e=s' => \$e,
|
||||
'E=s' => \$E,
|
||||
'l=s' => \$l,
|
||||
'n=s' => \$n,
|
||||
'u=s' => \$u,
|
||||
'x=s' => \$x,
|
||||
'X=s' => \$X,
|
||||
'Z=s' => \$Z,
|
||||
's' => \$sort,
|
||||
'p' => \$pretty,
|
||||
);
|
||||
|
||||
# print version or help if requested
|
||||
if ($help) {
|
||||
&help;
|
||||
exit 42;
|
||||
}
|
||||
if ($prog_version) {
|
||||
&prog_version;
|
||||
exit 42;
|
||||
}
|
||||
|
||||
# make sure we have a host
|
||||
if ( !defined( $ARGV[0] ) ) {
|
||||
die('No host specified');
|
||||
}
|
||||
|
||||
use Monitoring::Sneck::Boop_Snoot;
|
||||
|
||||
my $sneck_snoot_booper = Monitoring::Sneck::Boop_Snoot->new(
|
||||
{
|
||||
version => $version,
|
||||
community => $community,
|
||||
a => $a,
|
||||
A => $A,
|
||||
e => $e,
|
||||
E => $E,
|
||||
l => $l,
|
||||
n => $n,
|
||||
u => $u,
|
||||
x => $x,
|
||||
X => $X,
|
||||
Z => $Z,
|
||||
}
|
||||
);
|
||||
|
||||
my $raw_json = $sneck_snoot_booper->boop_the_snoot( $ARGV[0] );
|
||||
|
||||
# was told to raw print it, so just print and exit
|
||||
if ($sort && $pretty) {
|
||||
print $raw_json."\n";
|
||||
}
|
||||
|
||||
my $json;
|
||||
eval { $json = decode_json($raw_json); };
|
||||
if ($@) {
|
||||
die( 'Failed to decode the returned JSON.... ' . $raw_json . ' ... ' . $@ );
|
||||
}
|
||||
|
||||
my $new_json=JSON->new->utf8;
|
||||
|
||||
if (!$pretty) {
|
||||
$new_json->pretty(1);
|
||||
}
|
||||
|
||||
if (!$sort) {
|
||||
$new_json->canonical(1);
|
||||
}
|
||||
|
||||
print $new_json->encode($json);
|
||||
|
||||
if ($pretty) {
|
||||
print "\n";
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
Makefile
|
||||
Makefile.old
|
||||
Build
|
||||
Build.bat
|
||||
META.*
|
||||
MYMETA.*
|
||||
.build/
|
||||
_build/
|
||||
cover_db/
|
||||
blib/
|
||||
inc/
|
||||
.lwpcookies
|
||||
.last_cover_stats
|
||||
nytprof.out
|
||||
pod2htm*.tmp
|
||||
pm_to_blib
|
||||
Monitoring-Sneck-Boop_Snoot-*
|
||||
Monitoring-Sneck-Boop_Snoot-*.tar.gz
|
|
@ -0,0 +1,216 @@
|
|||
package Monitoring::Sneck::Boop_Snoot;
|
||||
|
||||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use String::ShellQuote;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Monitoring::Sneck::Boop_Snoot - Boop the Monitoring::Sneck's snoot via SNMP
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
Version 0.0.1
|
||||
|
||||
=cut
|
||||
|
||||
our $VERSION = '0.0.1';
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Monitoring::Sneck::Boop_Snoot;
|
||||
|
||||
my $sneck_snoot_booper = Monitoring::Sneck::Boop_Snoot->new({
|
||||
version=>'2c',
|
||||
community=>'public',
|
||||
});
|
||||
|
||||
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
Initiates the object.
|
||||
|
||||
version Version to use. 1, 2c, or 3
|
||||
Default: 2c
|
||||
|
||||
SNMP Version 1 or 2c specific
|
||||
community set the community string
|
||||
Default: public
|
||||
|
||||
SNMP Version 3 specific
|
||||
a set authentication protocol (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512)
|
||||
A set authentication protocol pass phrase
|
||||
e set security engine ID (e.g. 800000020109840301)
|
||||
E set context engine ID (e.g. 800000020109840301)
|
||||
l set security level (noAuthNoPriv|authNoPriv|authPriv)
|
||||
n set context name (e.g. bridge1)
|
||||
u set security name (e.g. bert)
|
||||
x set privacy protocol (DES|AES)
|
||||
X set privacy protocol pass phrase
|
||||
Z set destination engine boots/time
|
||||
|
||||
my $sneck_snoot_booper = Monitoring::Sneck::Boop_Snoot->new({
|
||||
version=>'2c',
|
||||
community=>'public',
|
||||
});
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my %args;
|
||||
if ( defined( $_[1] ) ) {
|
||||
%args = %{ $_[1] };
|
||||
}
|
||||
|
||||
my $self = {
|
||||
version => '2c',
|
||||
community => 'public',
|
||||
};
|
||||
|
||||
foreach my $arg_key ( keys(%args) ) {
|
||||
$self->{$arg_key} = shell_quote( $args{$arg_key} );
|
||||
}
|
||||
|
||||
if ( $self->{version} ne '1' && $self->{version} ne '2c' && $self->{version} ne '3' ) {
|
||||
die( '"' . $self->{version} . '" is not a recognized version' );
|
||||
}
|
||||
|
||||
bless $self;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
=head2 boop_the_snoot
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
sub boop_the_snoot {
|
||||
my $self = $_[0];
|
||||
my $host = $_[1];
|
||||
|
||||
# makes sure we have a good host
|
||||
if ( !defined($host) ) {
|
||||
die('No host specified');
|
||||
}
|
||||
|
||||
# quote the host so we can safely use it
|
||||
$host = shell_quote($host);
|
||||
|
||||
# put together the auth string to use
|
||||
my $auth_string = '-v ' . $self->{version};
|
||||
if ( $self->{version} eq '1' || $self->{version} eq '2c' ) {
|
||||
$auth_string = $auth_string . ' -c ' . $self->{community};
|
||||
}
|
||||
else {
|
||||
my @auth_keys = ( 'a', 'A', 'e', 'E', 'l', 'n', 'u', 'x', 'X', 'Z' );
|
||||
foreach my $auth_key (@auth_keys) {
|
||||
if ( defined( $self->{$auth_key} ) ) {
|
||||
$auth_string = $auth_string . ' -' . $auth_key . ' ' . shell_quote( $self->{$auth_key} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# the the snmpget command
|
||||
my $returned
|
||||
= `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`;
|
||||
my $exit_code = $?;
|
||||
chomp($returned);
|
||||
|
||||
# handle the exit code
|
||||
my $exit_error = '';
|
||||
if ( $exit_code == -1 ) {
|
||||
die('failed to execute snmpget');
|
||||
}
|
||||
elsif ( $exit_code & 127 ) {
|
||||
die(
|
||||
sprintf(
|
||||
"child died with signal %d, %s coredump\n",
|
||||
( $exit_code & 127 ),
|
||||
( $exit_code & 128 ) ? 'with' : 'without'
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$exit_code = $exit_code >> 8;
|
||||
if ( $exit_code != 0 ) {
|
||||
die( 'snmpget exited with ' . $exit_code );
|
||||
}
|
||||
}
|
||||
|
||||
# clean it up incase it is on a system that quotes everything
|
||||
$returned =~ s/\\([^n\\])/($1)/g;
|
||||
$returned =~ s/^\"//;
|
||||
$returned =~ s/\"$//;
|
||||
my ( $oid, $json ) = split( '\ ', $returned, 2 );
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
Please report any bugs or feature requests to C<bug-monitoring-sneck-boop_snoot at rt.cpan.org>, or through
|
||||
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
|
||||
automatically be notified of progress on your bug as I make changes.
|
||||
|
||||
|
||||
|
||||
|
||||
=head1 SUPPORT
|
||||
|
||||
You can find documentation for this module with the perldoc command.
|
||||
|
||||
perldoc Monitoring::Sneck::Boop_Snoot
|
||||
|
||||
|
||||
You can also look for information at:
|
||||
|
||||
=over 4
|
||||
|
||||
=item * RT: CPAN's request tracker (report bugs here)
|
||||
|
||||
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Monitoring-Sneck-Boop_Snoot>
|
||||
|
||||
=item * CPAN Ratings
|
||||
|
||||
L<https://cpanratings.perl.org/d/Monitoring-Sneck-Boop_Snoot>
|
||||
|
||||
=item * Search CPAN
|
||||
|
||||
L<https://metacpan.org/release/Monitoring-Sneck-Boop_Snoot>
|
||||
|
||||
=item * Github
|
||||
|
||||
L<https://github.com/VVelox/Monitoring-Sneck-Boop_Snoot>
|
||||
|
||||
=item * Repo
|
||||
|
||||
L<https://github.com/VVelox/Monitoring-Sneck-Boop_Snoot.git>
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head1 ACKNOWLEDGEMENTS
|
||||
|
||||
|
||||
=head1 LICENSE AND COPYRIGHT
|
||||
|
||||
This software is Copyright (c) 2022 by Zane C. Bowers-Hadley.
|
||||
|
||||
This is free software, licensed under:
|
||||
|
||||
The Artistic License 2.0 (GPL Compatible)
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
1; # End of Monitoring::Sneck::Boop_Snoot
|
|
@ -0,0 +1,13 @@
|
|||
#!perl
|
||||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
plan tests => 1;
|
||||
|
||||
BEGIN {
|
||||
use_ok( 'Monitoring::Sneck::Boop_Snoot' ) || print "Bail out!\n";
|
||||
}
|
||||
|
||||
diag( "Testing Monitoring::Sneck::Boop_Snoot $Monitoring::Sneck::Boop_Snoot::VERSION, Perl $], $^X" );
|
|
@ -0,0 +1,15 @@
|
|||
#!perl
|
||||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
unless ( $ENV{RELEASE_TESTING} ) {
|
||||
plan( skip_all => "Author tests not required for installation" );
|
||||
}
|
||||
|
||||
my $min_tcm = 0.9;
|
||||
eval "use Test::CheckManifest $min_tcm";
|
||||
plan skip_all => "Test::CheckManifest $min_tcm required" if $@;
|
||||
|
||||
ok_manifest();
|
|
@ -0,0 +1,24 @@
|
|||
#!perl
|
||||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
unless ( $ENV{RELEASE_TESTING} ) {
|
||||
plan( skip_all => "Author tests not required for installation" );
|
||||
}
|
||||
|
||||
# Ensure a recent version of Test::Pod::Coverage
|
||||
my $min_tpc = 1.08;
|
||||
eval "use Test::Pod::Coverage $min_tpc";
|
||||
plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
|
||||
if $@;
|
||||
|
||||
# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
|
||||
# but older versions don't recognize some common documentation styles
|
||||
my $min_pc = 0.18;
|
||||
eval "use Pod::Coverage $min_pc";
|
||||
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
|
||||
if $@;
|
||||
|
||||
all_pod_coverage_ok();
|
|
@ -0,0 +1,16 @@
|
|||
#!perl
|
||||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
unless ( $ENV{RELEASE_TESTING} ) {
|
||||
plan( skip_all => "Author tests not required for installation" );
|
||||
}
|
||||
|
||||
# Ensure a recent version of Test::Pod
|
||||
my $min_tp = 1.22;
|
||||
eval "use Test::Pod $min_tp";
|
||||
plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
|
||||
|
||||
all_pod_files_ok();
|
Loading…
Reference in New Issue