aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-04-25 04:43:17 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-04-25 04:43:17 +1200
commitc5c13fa16d7ab2a7577c676ec537e50ced813b7b (patch)
tree52de420f8edeaa9b86bacc1fe7811dc153333d8f
downloadnagios-check-ftp-c5c13fa16d7ab2a7577c676ec537e50ced813b7b.tar.gz
nagios-check-ftp-c5c13fa16d7ab2a7577c676ec537e50ced813b7b.zip
Version 1.00v1.00
-rw-r--r--.gitignore18
-rw-r--r--LICENSE7
-rw-r--r--MANIFEST4
-rw-r--r--Makefile.PL38
-rw-r--r--libexec/check_ftp96
5 files changed, 163 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..01da630
--- /dev/null
+++ b/.gitignore
@@ -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
+check_ftp-*
+check_ftp-*.tar.gz
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..cb45c5d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,7 @@
+Copyright 2020 Tom Ryder
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..b8e5c0e
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,4 @@
+libexec/check_ftp
+LICENSE
+MANIFEST
+Makefile.PL
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..ba195be
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,38 @@
+use 5.006;
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'check_ftp',
+ AUTHOR => 'Tom Ryder <tom@sanctum.geek.nz>',
+ VERSION_FROM => 'libexec/check_ftp',
+ LICENSE => 'MIT',
+ INSTALLSCRIPT => '/usr/local/nagios/libexec',
+ INSTALLSITESCRIPT => '/usr/local/nagios/libexec',
+ EXE_FILES => ['libexec/check_ftp'],
+ MIN_PERL_VERSION => '5.010_001',
+ CONFIGURE_REQUIRES => {
+ 'ExtUtils::MakeMaker' => '0',
+ },
+ PREREQ_PM => {
+ 'English' => 0,
+ 'Exception::Class' => 0,
+ 'Monitoring::Plugin' => 0,
+ 'Path::Tiny' => 0,
+ 'Quota' => 0,
+ 'Try::Tiny' => 0,
+ },
+ META_MERGE => {
+ 'meta-spec' => { version => 2 },
+ resources => {
+ homepage => 'https://sanctum.geek.nz/cgit/check_ftp.git/',
+ repository => {
+ type => 'git',
+ url => 'https://sanctum.geek.nz/code/check_ftp.git/',
+ web => 'https://sanctum.geek.nz/cgit/check_ftp.git/',
+ },
+ },
+ },
+ clean => { FILES => 'check_ftp-*' },
+);
diff --git a/libexec/check_ftp b/libexec/check_ftp
new file mode 100644
index 0000000..a36dfd3
--- /dev/null
+++ b/libexec/check_ftp
@@ -0,0 +1,96 @@
+#!perl
+#
+# Check that we can connect to an FTP server, with opportunistic TLS; the
+# check_ftp plugin that comes with Monitoring::Plugin doesn't do this.
+#
+# Author: Tom Ryder <tom@sanctum.geek.nz>
+# License: MIT
+#
+package main;
+
+# Force me to write this properly
+use strict;
+use warnings;
+use utf8;
+
+# Require at least this Perl version
+use 5.010_001;
+
+# Import required modules
+use English qw(-no_match_vars);
+use Exception::Class ( PluginException => { alias => 'throw' } );
+use Monitoring::Plugin;
+use Net::FTP;
+use Try::Tiny;
+
+# Decree package version
+our $VERSION = '1.00';
+
+# Add description and license package variables
+our $DESCRIPTION = <<'EOF';
+This plugin makes an FTP connection to a nominated server, optionally including
+a STARTTLS upgrade for FTPS. It does not support implicit FTPS.
+EOF
+our $LICENSE = <<'EOF';
+MIT License <https://opensource.org/licenses/MIT>
+EOF
+
+# Custom plugin options
+our @OPTS = (
+ {
+ spec => 'hostname|H=s',
+ help => 'FTP server hostname or address',
+ label => 'HOSTNAME',
+ default => 'localhost',
+ },
+ {
+ spec => 'starttls|S:s',
+ help => 'Try STARTTLS with optional specified hostname',
+ label => 'HOSTNAME',
+ },
+);
+
+# Build Monitoring::Plugin object
+my $mp = Monitoring::Plugin->new(
+ usage => 'Usage: %s [--hostname|h HOSTNAME] [--starttls|S [SERVERNAME]]',
+ version => $VERSION,
+ blurb => $DESCRIPTION,
+ license => $LICENSE,
+);
+
+# Anything that dies in here raises ->plugin_die
+try {
+
+ # Add and read custom options
+ for my $opt (@OPTS) {
+ $mp->add_arg( %{$opt} );
+ }
+ $mp->getopts;
+
+ # Start counting down to timeout
+ alarm $mp->opts->timeout;
+
+ # Attempt FTP connection
+ my %opts;
+ if ( length $mp->opts->starttls ) {
+ $opts{SSL_verifycn_name} = $mp->opts->starttls;
+ }
+ defined( my $ftp = Net::FTP->new( $mp->opts->hostname, %opts ) )
+ or $mp->plugin_exit( CRITICAL => 'Failed connect' );
+
+ # If we connected and the server reports that it supports TLS, try it
+ if ( defined $mp->opts->starttls ) {
+ my $ssl = $ftp->can_ssl
+ or throw 'Client can\'t TLS';
+ $ftp->feature('AUTH TLS')
+ or $mp->add_message( WARNING => 'AUTH TLS not listed in features' );
+ $ftp->starttls
+ or $mp->add_message( WARNING => $ssl->errstr || 'STARTTLS error' );
+ }
+ $mp->plugin_exit( $mp->check_messages );
+}
+catch {
+ $mp->plugin_die($_);
+};
+
+1;