From de48c80f3bcd35662316b90ba8327d635c50e70e Mon Sep 17 00:00:00 2001 From: Chris Sharp Date: Mon, 12 Jan 2015 08:42:32 -0500 Subject: [PATCH] adding nagios script to check for pg backups --- nagios/check_pgbackup.pl | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 nagios/check_pgbackup.pl diff --git a/nagios/check_pgbackup.pl b/nagios/check_pgbackup.pl new file mode 100644 index 0000000..2a79b69 --- /dev/null +++ b/nagios/check_pgbackup.pl @@ -0,0 +1,75 @@ +#!/usr/bin/perl -w + +############################## check_pgbackup.pl ################################## +# Version : 0.1 +# Date : September 12th, 2013 +# Author : Michael Peters +# 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 . +################################################################################## + +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 - 24*60*60))[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 == 22 && $MIN > 40 ) || ($HOUR == 0 && $MIN < 0 ) ) + { + 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/backup/db01/snapshot/gapines.org-prod-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"} +} + -- 2.11.0