check_pgbackup.pl Nagios / Icinga plugin user/mrpeters/check_pgbackup_nagios
authorMichael Peters <mpeters@emeralddata.net>
Thu, 12 Sep 2013 19:07:13 +0000 (15:07 -0400)
committerMichael Peters <mpeters@emeralddata.net>
Thu, 12 Sep 2013 19:07:13 +0000 (15:07 -0400)
A simple Nagios / Icinga plugin to check the existance of a
backup gzip generated by eg-db-backup.sh on the particular
day.

Includes variables to report an OK status between midnight and the
time the backup can be expected to be completed running.

Signed-off-by: Michael Peters <mpeters@emeralddata.net>
Open-ILS/src/extras/nagios/plugins/check_pgbackup.pl [new file with mode: 0755]

diff --git a/Open-ILS/src/extras/nagios/plugins/check_pgbackup.pl b/Open-ILS/src/extras/nagios/plugins/check_pgbackup.pl
new file mode 100755 (executable)
index 0000000..ad7b228
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/perl -w
+
+############################## check_pgbackup.pl ##################################
+# Version : 0.1
+# Date : September 12th, 2013
+# Author  : Michael Peters <mpeters@emeralddata.net>
+# Use :  A Nagios/Icinga plugin for monitoring the existence of Evergreen PostgreSQL 
+#        backups generated by eg-db-backup.sh (http://git.evergreen-ils.org/?p=contrib/equinox.git;a=blob;f=ESI-Examples/sys/scripts/eg-db-backup.sh)
+# Licence :  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 2, 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 <http://www.gnu.org/licenses/>.
+##################################################################################
+
+package main;
+use strict;
+use Getopt::Long;
+use POSIX;
+
+#get date info
+#from http://git.evergreen-ils.org/?p=contrib/equinox.git;a=blob;f=eg-stats/parse-eg-stats.pl(GPL Licensed)
+my ($SEC, $MIN, $HOUR, $DAY,$MONTH,$YEAR) = (localtime(time))[0,1,2,3,4,5,6];
+$YEAR+=1900;
+$MONTH++;
+if ($DAY < 10) {
+   $DAY = "0".$DAY;
+}
+if ($MONTH < 10) {
+   $MONTH = "0".$MONTH;
+}
+
+my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
+
+####
+#  Prevent Nagios messages when backups haven't yet been run for the day. 
+#  If the time(s) of the backup cronjob(s) are modified, or different from those 
+#  below, adjust the values below accordingly.
+###
+if ( ( $HOUR == 0 && $MIN > 0 ) || ($HOUR == 8 && $MIN < 30 ) )
+   {
+      exit $ERRORS{"OK"};
+   }
+
+###### Check that backup snapshot gzip file for today exists ######
+
+# adjust to be the output location of your eg-db-backup.sh backup gzips
+my $file = "/var/dbBackups/killeen-postgres-backup-$YEAR-$MONTH-$DAY.cpio.gz";
+
+if (-e $file) {
+  print "File " . $file . " exists.";
+  exit $ERRORS{"OK"}
+}
+else {
+  print "File " . $file . " does not exist.";
+  exit $ERRORS{"CRITICAL"}
+}
+if (! -e $file) {
+  print "File " . $file . " does not exist.";
+  exit $ERRORS{"OK"}
+}
+else {
+  print "File " . $file . " exists.";
+  exit $ERRORS{"CRITICAL"}
+}
+