From 8850a78149bcc3ac1d8eac44b821ce86036bf486 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Wed, 5 Aug 2015 14:15:08 -0400 Subject: [PATCH 1/1] Nagios/Icinga: Check existance of daily PostgreSQL backup file A Nagios plugin (also works with NRPE and Icinga) written in Perl which checks for the existance of a daily PostgreSQL backup file. To use, install to your nagios-plugins folder (usually /usr/lib/nagios/plugins) and make sure the script has executable permissions by the nagios user. This script will return one of three statuses to Nagios/Icinga; OK - File does not exist, because it has not yet been created by cron. OK - File exists. CRITICAL File does not exist. Follow the comments in the script to configure the first hour, on a new day, that you want to begin checking for existance of the file. A function is included so that you won't recieve a critical alert when the clock hits 00:00 and no backup file exists because your backup cron job has not yet run. Signed-off-by: Michael Peters --- nagios-plugins/check_postgres_backup.pl | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 nagios-plugins/check_postgres_backup.pl diff --git a/nagios-plugins/check_postgres_backup.pl b/nagios-plugins/check_postgres_backup.pl new file mode 100755 index 000000000..58cb6ac82 --- /dev/null +++ b/nagios-plugins/check_postgres_backup.pl @@ -0,0 +1,75 @@ +#!/usr/bin/perl -w + +############################## check_pgbackup.pl ################################## +# Version : 0.2 +# Date : September 12th, 2013 (Last Modified : August 5th, 2015) +# Author : Michael Peters +# 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 . +################################################################################## + +package main; +use strict; +use Getopt::Long; +use POSIX; + +#get date info +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); + +# adjust to be the output location of your eg-db-backup.sh backup gzips +my $file = "/backups/dbBackups/postgres-backup-$YEAR-$MONTH-$DAY.cpio.gz"; + + +#### +# 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 hour value below accordingly, based on when you expect +# your backup to be complete each day. +### + +if ( $HOUR < 8 ) + { + print "File " . $file . " does not exist, because it has not yet been created by cron."; + exit $ERRORS{"OK"}; + } + + +###### Check that backup snapshot gzip file for today exists ###### + +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"} +} + -- 2.11.0