From: Michael Howe Date: Sat, 17 Oct 2015 10:09:25 +0000 (+0000) Subject: New check_configtool plugin X-Git-Tag: 0.11~2 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=8d031ae096f2ad658480027f4c88d85e3a17f4e8;p=packages%2Fn%2Fnagios-plugins-local.git New check_configtool plugin --- diff --git a/debian/changelog b/debian/changelog index 45763aa..585795b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +nagios-plugins-local (0.9) unstable; urgency=medium + + * Add check_configtool plugin + + -- Michael Howe Sat, 17 Oct 2015 11:08:47 +0100 + nagios-plugins-local (0.8) unstable; urgency=low * Add more dependencies, used by check_cert diff --git a/plugins/check_configtool b/plugins/check_configtool new file mode 100755 index 0000000..76a9ffe --- /dev/null +++ b/plugins/check_configtool @@ -0,0 +1,66 @@ +#!/usr/bin/perl +# +# $HeadURL$ +# $LastChangedRevision$ +# $LastChangedDate$ +# $LastChangedBy$ +# +# +# check_configtool - check that configtool is enabled and has a cronjob that runs. +# +# Conditions: +# * configtool disabled: warning +# * configtool cronjob not present: critical +# * configtool.disable file location not defined: unknown + +use strict; +use warnings; + +use lib '/usr/lib/nagios/plugins'; +use utils qw(%ERRORS); + +use Configtool::Config; + +my $config = Configtool::Config->new(); + +unless( $config->disablepath ){ + print "UNKNOWN: cannot find location of configtool.disable file in configuration (is configtool installed?)\n"; + exit $ERRORS{'UNKNOWN'}; +} +# Check that the repository exists: +unless( -d $config->repository ){ + printf "UNKNOWN: repository directory %s does not exist (running as correct user?)\n", $config->repository; + exit $ERRORS{'UNKNOWN'}; +} + +# Check configtool cronjob exists +my $cronjob_exists = 0; +CRONTABS: foreach my $file ( glob '/etc/cron.d/*' ){ + # letters, digits, underscores and hyphens, per cron(8) + next unless $file =~ m{[a-z0-9_-]+}i; + open( my $fh, "<", $file ) + or die "Could not open $file for reading: $!"; + while( my $line = <$fh> ){ + chomp( $line ); + next if $line =~ m{^#}; + if( $line =~ m{configtool$} ){ + $cronjob_exists = 1; + last CRONTABS; + } + } + close( $fh ); +} + +unless( $cronjob_exists ){ + print "CRITICAL: cannot find a cronjob running configtool\n"; + exit $ERRORS{'CRITICAL'}; +} + +# Check if configtool is disabled +if ( -f $config->disablepath ){ + printf "WARNING: configtool disabled (%s exists)\n", $config->disablepath; + exit $ERRORS{'WARNING'}; +} + +print "OK: cronjob exists, configtool enabled\n"; +exit $ERRORS{'OK'};