Skip to content

Instantly share code, notes, and snippets.

@sujithrs
Forked from mikeyk/watch_wal-e.py
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujithrs/876ca7175c87df43e081 to your computer and use it in GitHub Desktop.
Save sujithrs/876ca7175c87df43e081 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
from boto.ses.connection import SESConnection
import os
import sys
import subprocess
import socket
TMPFILE = '/var/run/postgresql/last-wal-archive-error-file.tmp'
if __name__ == '__main__':
return_code = 'unknown'
host = socket.getfqdn()
wal_file = 'unknown'
try:
ses_conn = SESConnection()
wal_file = sys.argv[1]
wal_push = '/usr/local/bin/wal-e'
return_code = subprocess.call([wal_push, 'wal-push', wal_file])
except Exception, e:
return_code = str(e)
finally:
if return_code != 0:
if os.path.exists(TMPFILE):
contents = open(TMPFILE).read()
last_wal_error = contents
if wal_file == last_wal_error:
ses_conn.send_email(
source = 'youremail@',
subject = 'PG WAL Archive Failed!',
body = 'Host: %s\nError: %s\nWAL: %s' % (host, return_code, wal_file),
to_addresses = ['toemail@'])
sys.exit(1)
outfl = open(TMPFILE, 'w')
outfl.write(wal_file)
outfl.close()
sys.exit(1)
else:
if os.path.exists(TMPFILE):
os.remove(TMPFILE)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment