aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-04-25 04:49:43 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-04-25 04:50:40 +1200
commit58cbad7083440ab90c1ff867fdd0f0d7638b3104 (patch)
treebb32d80402956aa59a156c6985aff62105554a6c
downloadnagios-check-xmpp-58cbad7083440ab90c1ff867fdd0f0d7638b3104.tar.gz
nagios-check-xmpp-58cbad7083440ab90c1ff867fdd0f0d7638b3104.zip
Version 1.00v1.00
-rw-r--r--.gitignore18
-rw-r--r--LICENSE7
-rw-r--r--MANIFEST4
-rw-r--r--Makefile.PL35
-rw-r--r--libexec/check_xmpp117
5 files changed, 181 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e9ca607
--- /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_xmpp-*
+check_xmpp-*.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..fd60acb
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,4 @@
+libexec/check_xmpp
+LICENSE
+MANIFEST
+Makefile.PL
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..8828919
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,35 @@
+use 5.006;
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'check_xmpp',
+ AUTHOR => 'Tom Ryder <tom@sanctum.geek.nz>',
+ VERSION_FROM => 'libexec/check_xmpp',
+ LICENSE => 'MIT',
+ INSTALLSCRIPT => '/usr/local/nagios/libexec',
+ INSTALLSITESCRIPT => '/usr/local/nagios/libexec',
+ EXE_FILES => ['libexec/check_xmpp'],
+ MIN_PERL_VERSION => '5.006',
+ CONFIGURE_REQUIRES => {
+ 'ExtUtils::MakeMaker' => '0',
+ },
+ PREREQ_PM => {
+ 'English' => 0,
+ 'Monitoring::Plugin' => 0,
+ 'Net::XMPP' => 0,
+ },
+ META_MERGE => {
+ 'meta-spec' => { version => 2 },
+ resources => {
+ homepage => 'https://sanctum.geek.nz/cgit/check_xmpp.git/',
+ repository => {
+ type => 'git',
+ url => 'https://sanctum.geek.nz/code/check_xmpp.git/',
+ web => 'https://sanctum.geek.nz/cgit/check_xmpp.git/',
+ },
+ },
+ },
+ clean => { FILES => 'check_xmpp-*' },
+);
diff --git a/libexec/check_xmpp b/libexec/check_xmpp
new file mode 100644
index 0000000..c628c13
--- /dev/null
+++ b/libexec/check_xmpp
@@ -0,0 +1,117 @@
+#!perl
+#
+# Connect to an XMPP service to check it's working.
+#
+# Author: Tom Ryder <tom@sanctum.geek.nz>
+# License: MIT
+#
+package main;
+
+# Force me to write this properly
+use strict;
+use warnings;
+use utf8;
+
+# Old Perl should be OK
+use 5.006;
+
+# Import required modules
+use English '-no_match_vars';
+use Monitoring::Plugin '%ERRORS';
+use Net::XMPP;
+
+# Decree package version
+our $VERSION = '1.00';
+
+our $DESCRIPTION = <<'EOF';
+This plugin uses Perl Net::XMPP to connect to an XMPP server, to test whether
+it is accepting connections. It does not perform any authentication.
+EOF
+our $LICENSE = <<'EOF';
+MIT License <https://opensource.org/licenses/MIT>
+EOF
+
+# Add custom options
+our @OPTS = (
+ {
+ spec => 'hostname|H=s',
+ label => 'HOSTNAME',
+ help => 'Hostname or IP address of device to check',
+ },
+ {
+ spec => 'port|p=i',
+ label => 'PORT',
+ help => 'TCP port to check',
+ },
+ {
+ spec => 'tls|s',
+ help => 'Use a secure connection',
+ },
+);
+
+# Build Monitoring::Plugin object
+my $mp = Monitoring::Plugin->new(
+ usage => 'Usage: %s'
+ . ' [--hostname|-H HOSTNAME]'
+ . ' [--port|-p PORT]'
+ . ' [--tls|-s]',
+ version => $VERSION,
+ blurb => $DESCRIPTION,
+ license => $LICENSE,
+) or die "Failed plugin build\n";
+
+# Anything fatal in here exits UNKNOWN
+eval {
+
+ # Add and read custom options
+ for my $opt (@OPTS) {
+ $mp->add_arg( %{$opt} );
+ }
+ $mp->getopts();
+
+ # Start counting down to timeout
+ alarm $mp->opts->timeout();
+
+ # Create XMPP object
+ my $xmpp = Net::XMPP::Client->new()
+ or die "Failed object construct\n";
+
+ # Build connection parameters based on options
+ my %conn;
+ for my $opt (qw(hostname port tls)) {
+ defined( my $val = $mp->opts->get($opt) )
+ or next;
+ $conn{$opt} = $val;
+ }
+
+ # If TLS is being used, get certificate authority details
+ if ( $conn{tls} ) {
+ require IO::Socket::SSL;
+ my %default_ca = IO::Socket::SSL::default_ca();
+ for my $key ( keys %default_ca ) {
+ $conn{ lc $key } = $default_ca{$key};
+ }
+ }
+
+ # Attempt connection and add an appropriate message
+ my ( $code, $message );
+ if ( $xmpp->Connect(%conn) ) {
+ ( $code, $message ) = ( $ERRORS{OK}, 'Successful XMPP connection' );
+ $xmpp->Disconnect();
+ }
+ else {
+ ( $code, $message ) = ( $ERRORS{CRITICAL}, 'Failed XMPP connection' );
+ }
+ $mp->add_message( $code, $message );
+
+ # Exit with the status of our most severe error
+ $mp->plugin_exit(
+ $mp->check_messages(
+ join => ', ',
+ join_all => ', ',
+ ),
+ );
+
+} or $mp->plugin_die($EVAL_ERROR);
+
+1;