| 1 | #!perl | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use Getopt::Long qw(:config require_order no_ignore_case bundling); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Monitoring::Sneck::Checks; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | sneck_check - runs a Monitoring::Sneck::Checks check from the shell | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | sneck_check [B<-t> <seconds>] [B<-a>] <check> [<args>...] | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | sneck_check B<-h>|B<--help> [<check>] | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | sneck_check <check> B<-h>|B<--help> | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sneck_check B<-l>|B<--list-checks> | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | Runs a check the same as sneck does for perl:<check>, prints its | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | output, and exits with its code, so it can also be used as a nagios | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | plugin. A check that can not be loaded, -1 for sneck, exits 3. | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 FLAGS | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =head2 -t <seconds> | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | Seconds to give it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | Default :: 30 | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =head2 -a | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | Print stdout and then stderr, labeled, instead of the two combined. | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | =head2 -h, --help | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | Print this, or the docs for the check if one is given, what it is for | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | and the options it takes. Before or after the check is the same. | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | =head2 -l, --list-checks | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | List the checks that can be found, one a line, with what each is for. | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | =head1 EXAMPLES | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sneck_check http -H www.example.org -S -w 1 -c 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sneck_check -t 10 https_cert -H www.example.org -w 30 -c 14 | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sneck_check --help https_cert | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sneck_check --list-checks | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 17 | my $timeout = 30; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 17 | my $apart; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | my $help; | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 17 | my $list; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 17 | ▶ | GetOptions( 't=s' => \$timeout, 'a' => \$apart, 'help|h' => \$help, 'list-checks|l' => \$list ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | or pod2usage( -exitval => 3, -verbose => 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 17 | ▶ | if ($list) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | my $checks = Monitoring::Sneck::Checks->list; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | foreach my $name ( sort( keys( %{$checks} ) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 140 | ▶ | print $name . ( $checks->{$name} eq '' ? '' : ' :: ' . $checks->{$name} ) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | exit(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 15 | my $check = shift(@ARGV); | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # require_order leaves everything after the check alone, so a -h after it is looked for here | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 15 | ▶ | if ( defined($check) && grep { $_ eq '-h' || $_ eq '--help' } @ARGV ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $check and grep {$_ eq "-h" or $_ eq "--help";} @ARGV
$_ eq '-h' || $_ eq '--help'
MC/DC100%2/2
defined $check and grep {$_ eq "-h" or $_ eq "--help";} @ARGV
defined $check
grep {$_ eq "-h" or $_ eq "--help";} @ARGV
MC/DC100%2/2
$_ eq '-h' || $_ eq '--help'
$_ eq '-h'
$_ eq '--help'
Truth table100%3/3
A and B
A= defined $checkB= grep {$_ eq "-h" or $_ eq "--help";} @ARGV
Truth table100%3/3
A || B
A= $_ eq '-h'B= $_ eq '--help'
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | $help = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 15 | ▶ | if ($help) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | ▶ | pod2usage( -exitval => 0, -verbose => 2 ) if !defined($check); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 9 | my $module = eval { Monitoring::Sneck::Checks->load($check) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 9 | ▶ | if ( !defined($module) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | print STDERR $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | exit(3); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | my $file = $INC{ 'Monitoring/Sneck/Checks/' . $check . '.pm' }; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | pod2usage( | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | -input => $file, | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | -exitval => 'NOEXIT', | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | -verbose => 99, | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | -sections => 'NAME|SYNOPSIS|DESCRIPTION|OPTIONS' | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | pod2usage( | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | -input => $INC{'Monitoring/Sneck/Checks/base.pm'}, | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | -exitval => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | -verbose => 99, | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | -sections => 'COMMON OPTIONS' | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } ## end if ($help) | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | ▶ | pod2usage( -exitval => 3, -verbose => 1 ) if !defined($check); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | my $return = Monitoring::Sneck::Checks->run( check => $check, args => [@ARGV], timeout => $timeout ); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | ▶ | if ($apart) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | print 'stdout:' . "\n" . $return->{stdout} . 'stderr:' . "\n" . $return->{stderr}; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | print $return->{combined}; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | ▶ | exit( $return->{code} == -1 ? 3 : $return->{code} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||