From 169763724978ed4b35e1b8e50523392d3cafa1ae Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Wed, 22 Oct 2014 17:01:22 +0200 Subject: [PATCH] Adding check_sieve --- check_sieve/.control.swp | Bin 0 -> 12288 bytes check_sieve/Makefile | 3 + check_sieve/check_sieve | 236 +++++++++++++++++++++++++++ check_sieve/check_sieve.cfg | 5 + check_sieve/control | 7 + check_sieve/copyright | 7 + debian/README.Debian.plugins | 5 +- debian/control | 6 +- debian/copyright | 28 ++++ debian/patches/check_sieve/10_pathes | 14 ++ debian/patches/series | 1 + 11 files changed, 309 insertions(+), 3 deletions(-) create mode 100644 check_sieve/.control.swp create mode 100644 check_sieve/Makefile create mode 100644 check_sieve/check_sieve create mode 100644 check_sieve/check_sieve.cfg create mode 100644 check_sieve/control create mode 100644 check_sieve/copyright create mode 100644 debian/patches/check_sieve/10_pathes diff --git a/check_sieve/.control.swp b/check_sieve/.control.swp new file mode 100644 index 0000000000000000000000000000000000000000..c1504079801074adf419d4caaecbf3a9bc0f4c74 GIT binary patch literal 12288 zcmeI&&2G~`5C`xn7fyu=PTYo4sUWbOwm?fn5mJdDNEE4|sRTu6v)%Bti$eYDBjFoX*X>3C literal 0 HcmV?d00001 diff --git a/check_sieve/Makefile b/check_sieve/Makefile new file mode 100644 index 0000000..cf9673d --- /dev/null +++ b/check_sieve/Makefile @@ -0,0 +1,3 @@ +#/usr/bin/make -f + +include ../common.mk diff --git a/check_sieve/check_sieve b/check_sieve/check_sieve new file mode 100644 index 0000000..2bb21f0 --- /dev/null +++ b/check_sieve/check_sieve @@ -0,0 +1,236 @@ +#!/usr/local/bin/perl + +########################################################################### +# $Id: check_sieve.pl 214 2014-01-08 09:37:22Z alan $ +# +# check SIEVE connections as per rfc 5804 +# +# Copyright (c) 2013 Persistent Objects Ltd - http://p-o.co.uk +# +# Dual licence AL/GPL +# +# Artistic License 2.0 (http://www.perlfoundation.org/artistic_license_2_0) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +########################################################################### +# Inspired by check_stuff.pl, originally by Nathan Vonnahme, n8v at users +# dot sourceforge dot net, July 19 2006 +########################################################################### + +########################################################################### +# prologue +use strict; +use warnings; +use IO::Socket::INET6; +use Time::HiRes; +use Nagios::Plugin; + +use vars qw($VERSION $PROGNAME); +use vars qw($start $duration $sock $family $code $line $implementation); +use vars qw($capability $message $peer_address); +$VERSION = '1.02'; + +# get the base name of this script for use in the examples +use File::Basename; +$PROGNAME = basename($0); + + +# Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory) +my $p = Nagios::Plugin->new( + usage => "Usage: %s + [ -v|--verbose ] + [ -H|--host ] + [ -P|--port ] + [ -4|--ipv4] + [ -6|--ipv6] + [ -t|--timeout ] + [ -c|--critical= ] + [ -w|--warning= ] + [ -r|--result = ]", + version => $VERSION, + blurb => 'This plugin checks for a running Sieve daemon.', + + extra => " + + Examples: + + $PROGNAME -H localhost -P 4190 -w 5 -c 10 + Returns a warning if the response is greater than 5 seconds, + or a critical error if it is greater than 10. + + " +); + +########################################################################### +# define, document and get the command line options. +# see the command line option guidelines at +# http://nagiosplug.sourceforge.net/developer-guidelines.html#PLUGOPTIONS +# usage, help, version, timeout and verbose are defined by default. + +$p->add_arg( + spec => 'host|H=s', + help => +qq{-H, --host=STRING + Host where the running daemon can be found, defaults to localhost.}, + required => 0, + default => 'localhost', +); + +$p->add_arg( + spec => 'port|P=i', + help => +qq{-P, --port=INTEGER + Port number for the running daemon, default 4190.}, + required => 0, + default => 4190, +); + +$p->add_arg( + spec => 'warning|w=i', + help => +qq{-w, --warning=INTEGER:INTEGER + Minimum and maximum number of allowable result, outside of which a + warning will be generated. If omitted, no warning is generated.}, + + required => 0, + default => 5, +); + +$p->add_arg( + spec => 'critical|c=i', + help => +qq{-c, --critical=INTEGER:INTEGER + Minimum and maximum number of the generated result, outside of + which a critical will be generated. }, + required => 0, + default => 10, +); + +$p->add_arg( + spec => 'ipv6|6', + help => +qq{-6, --ipv6 + Use ipv6. }, +); +$p->add_arg( + spec => 'ipv4|4', + help => +qq{-4, --ipv4 + Use ipv4. }, +); + +$p->add_arg( + spec => 'result|r=i', + help => +qq{-r, --result=INTEGER + Supplied result for testing.}, + required => 0, +); + +########################################################################### +# Parse arguments and process standard ones (e.g. usage, help, version) +$p->getopts; + +########################################################################### +# perform sanity checking on command line options +if ( (defined $p->opts->result) && ($p->opts->result < 0 || $p->opts->result > 20) ) { + $p->nagios_die( ' invalid number supplied for the -r option ' ); +} +unless ( defined $p->opts->warning || defined $p->opts->critical ) { + $p->nagios_die('Please supply a warning or critical threshold argument', UNKNOWN); +} +if ( $p->opts->warning == $p->opts->critical ) { + $p->nagios_die('Critical is equal to Warning', UNKNOWN); +} +if ( $p->opts->warning > $p->opts->critical ) { + $p->nagios_die('Critical is longer than Warning', UNKNOWN); +} + + +########################################################################### +# Set the protocol family +if ( $p->opts->ipv6) { + $family = AF_INET6; +}elsif ( $p->opts->ipv4) { + $family = AF_INET; +} + + +########################################################################### +# Set the timeout +#$SIG{'ALRM'} = sub { $p->nagios_die("Timeout", CRITICAL); }; +alarm $p->opts->timeout; + + +########################################################################### +# Check Sieve daemon is running + +$start = Time::HiRes::time; + +$sock = IO::Socket::INET6->new( + PeerAddr => $p->opts->host, + PeerPort => $p->opts->port, + Domain => $family, + Proto => 'tcp', + Timeout => $p->opts->timeout +) or $p->nagios_exit(UNKNOWN, 'Unable to connect to: '. $p->opts->host .':'.$p->opts->port); +$peer_address = $sock->peerhost() . ':' . $sock->peerport(); + +SOCKETLOOP: +while (defined($line = <$sock>)) { + #print $line; + if ($line =~ /SIEVE/) { + $capability = $line; + } + if ($line =~ /implementation/i) { + $implementation = $line; + } + + last SOCKETLOOP if $line =~ /^OK/; +} +close($sock); + +# Get rid of quotes if they have been used +$implementation =~ tr/0-9a-zA-Z. //csd; +$implementation = substr $implementation, 15; +$capability =~ tr/0-9a-zA-Z. //cd; +$capability = substr $capability, 6; + +$duration = sprintf("%.4f",Time::HiRes::time - $start); + +########################################################################### +# check the result against the defined warning and critical thresholds, +# output the result and exit +if ($p->opts->result) { + # We are testing + $duration = $p->opts->result; +} +$code = $p->check_threshold( + check => $duration, + warning => $p->opts->warning, + critical => $p->opts->critical, +); +$message .= $duration . ' second response time;'; + +if ($p->opts->verbose) { + $message .= ' connected to ' . $peer_address . ';'; + if ($implementation) { + $message .= ' ' . $implementation . ';'; + } + $message .= ' [' . $capability . '];'; +} + +# Output the result +$p->nagios_exit($code, $message); diff --git a/check_sieve/check_sieve.cfg b/check_sieve/check_sieve.cfg new file mode 100644 index 0000000..45aaa25 --- /dev/null +++ b/check_sieve/check_sieve.cfg @@ -0,0 +1,5 @@ +# 'check_sieve' command definition +define command{ + command_name check_sieve + command_line /usr/lib/monitoring-plugins/check_sieve -H $HOSTADDRESS$ $ARG1$ + } diff --git a/check_sieve/control b/check_sieve/control new file mode 100644 index 0000000..b93b96c --- /dev/null +++ b/check_sieve/control @@ -0,0 +1,7 @@ +Homepage: https://raw.githubusercontent.com/alan-hicks/check_sieve/master/check_sieve.pl +Watch: https://raw.githubusercontent.com/alan-hicks/check_sieve/master/check_sieve.pl \$VERSION\ =\ '([0-9.]+)' +Recommends: libio-socket-inet6-perl, monitoring-plugins-common | nagios-plugins-common +Version: 1.02 +Uploaders: Jan Wagner +Description: plugin checking for a running Sieve daemon + Check SIEVE connections as per rfc 5804 for Nagios diff --git a/check_sieve/copyright b/check_sieve/copyright new file mode 100644 index 0000000..3d89cc9 --- /dev/null +++ b/check_sieve/copyright @@ -0,0 +1,7 @@ +Copyright (c) 2012 William Leibzon + +License: GPL v2 + + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + diff --git a/debian/README.Debian.plugins b/debian/README.Debian.plugins index 31715f2..891ce28 100644 --- a/debian/README.Debian.plugins +++ b/debian/README.Debian.plugins @@ -37,8 +37,11 @@ check_redis: check_sentinel: Required Packages: ruby-redis +check_sieve: + Required Packages: libio-socket-inet6-perl, monitoring-plugins-common | nagios-plugins-common + check_smart: - Required Packages: perl-base, perl-modules, monitoring-plugins-common | nagios-plugins-common + Required Packages: perl-modules, monitoring-plugins-common | nagios-plugins-common check_tftp: Required Packages: libnet-tftp-perl, monitoring-plugins-common | nagios-plugins-common diff --git a/debian/control b/debian/control index 002a09f..09298ee 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,7 @@ Vcs-Browser: http://github.com/waja/monitoring-plugins-cyconet Package: monitoring-plugins-cyconet Architecture: any Depends: ${misc:Depends} -Recommends: ${shlibs:Depends}, ${python:Depends}, libnet-snmp-perl, monitoring-plugins-common | nagios-plugins-common, libtime-modules-perl, libwww-perl, python-argparse, libredis-perl, ruby-redis, perl-modules, libnet-tftp-perl, libxml-xpath-perl, ${perl:Depends} +Recommends: ${shlibs:Depends}, ${python:Depends}, libnet-snmp-perl, monitoring-plugins-common | nagios-plugins-common, libtime-modules-perl, libwww-perl, python-argparse, libredis-perl, ruby-redis, libio-socket-inet6-perl, perl-modules, libnet-tftp-perl, libxml-xpath-perl, ${perl:Depends} Suggests: Enhances: nagios-plugins, nagios-plugins-basic, nagios-plugins-standard Description: Plugins for nagios compatible monitoring systems @@ -21,7 +21,7 @@ Description: Plugins for nagios compatible monitoring systems . * check_bgp (0.4): plugin to check BGP peer status via SNMP. * check_file: plugin to check file count, size and ages - * check_nginx_status (0.9): plugin checking the nginx_status page report from nginx + * check_nginx_status (0.10): plugin checking the nginx_status page report from nginx Tracking Active connections processes, request per second, connections per seconds, Connections status. * check_nwc_health (3.0.3.7): This plugin checks the hardware health and interface metrics @@ -30,6 +30,8 @@ Description: Plugins for nagios compatible monitoring systems * check_phpfpm_status (0.9): plugin to check the fpm-status page report from php-fpm * check_redis (0.72): plugin that verifies redis server is working. * check_sentinel (0b8e0e388a): plugin to monitor Redis sentinel + * check_sieve (1.02): plugin checking for a running Sieve daemon + Check SIEVE connections as per rfc 5804 for Nagios * check_smart: plugin to check SMART status of ATA/SCSI disks * check_tftp (0.11): plugin that verifies TFTP server is working. * check_tomcat (1.4): plugin to check the tomcat status page. diff --git a/debian/copyright b/debian/copyright index eadac19..9c185a6 100644 --- a/debian/copyright +++ b/debian/copyright @@ -199,6 +199,34 @@ https://raw.github.com/reedox/check_sentinel/master/check_sentinel THE SOFTWARE. +------------------------------------------------------------------------------ + +check_sieve: + +The plugin was downloaded from: +https://raw.githubusercontent.com/alan-hicks/check_sieve/master/check_sieve.pl + + Copyright (c) 2012 William Leibzon + + License: GPL v2 + + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + + + +------------------------------------------------------------------------------ + +check_smart: + +The plugin was downloaded from: +https://exchange.icinga.org/exchange/check_smart+hwraid + + Copyright (c) Kurt Yoder, Giles Westwood + + License: public-domain + + ------------------------------------------------------------------------------ check_tftp: diff --git a/debian/patches/check_sieve/10_pathes b/debian/patches/check_sieve/10_pathes new file mode 100644 index 0000000..786ee3f --- /dev/null +++ b/debian/patches/check_sieve/10_pathes @@ -0,0 +1,14 @@ +Author: Jan Wagner +Description: + Patches check_sieve to use debian specific paths. + +diff --git a/check_sieve/check_sieve b/check_sieve/check_sieve +index 2bb21f0..7405671 100644 +--- a/check_sieve/check_sieve ++++ b/check_sieve/check_sieve +@@ -1,4 +1,4 @@ +-#!/usr/local/bin/perl ++#!/usr/bin/perl + + ########################################################################### + # $Id: check_sieve.pl 214 2014-01-08 09:37:22Z alan $ diff --git a/debian/patches/series b/debian/patches/series index 6c249ef..c3e9e36 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,3 +1,4 @@ check_tomcat/epn check_tftp/epn check_phpfpm_status/10_pathes +check_sieve/10_pathes