]> git.michaelhowe.org Git - packages/n/nagios-plugins-local.git/commitdiff
New check_configtool plugin
authorMichael Howe <michael@michaelhowe.org>
Sat, 17 Oct 2015 10:09:25 +0000 (10:09 +0000)
committerMichael Howe <michael@michaelhowe.org>
Sat, 17 Oct 2015 10:09:25 +0000 (10:09 +0000)
debian/changelog
plugins/check_configtool [new file with mode: 0755]

index 45763aa73a328c0544771bd1784b963ea3184029..585795b8d30666b6249a2d30b26e42fd4992b0d0 100644 (file)
@@ -1,3 +1,9 @@
+nagios-plugins-local (0.9) unstable; urgency=medium
+
+  * Add check_configtool plugin 
+
+ -- Michael Howe <michael@michaelhowe.org>  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 (executable)
index 0000000..76a9ffe
--- /dev/null
@@ -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'};