summaryrefslogtreecommitdiff
path: root/rystamps.py
diff options
context:
space:
mode:
Diffstat (limited to 'rystamps.py')
-rwxr-xr-xrystamps.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/rystamps.py b/rystamps.py
new file mode 100755
index 0000000..9cc8429
--- /dev/null
+++ b/rystamps.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+
+# rystamps -- monitor script for rybackup, that notifies the systems
+# administrator in case of anomalies, that is if (UTC)
+# timestamps of backups are outdated by NN(h)
+# Copyright (C) 2011 Adrian C. <anrxc sysphere.org>
+
+# 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 of the License, or
+# (at your option) any later version.
+
+
+from string import join
+from smtplib import SMTP
+from socket import getfqdn
+from os.path import getmtime
+from datetime import timedelta, datetime
+
+
+# Configuration
+#
+# Backups directory
+backups = "/mnt/backup"
+
+# Alarm thresholds per client (in hours)
+servers = {
+ "apollo" : {
+ "hourly" : 36, "daily" : 168, "weekly" : 720
+ },
+ "columbia" : {
+ "hourly" : 24, "daily" : 48, "weekly" : 168, "monthly" : 720
+ },
+}
+
+# Alerts mailing settings
+host = getfqdn()
+user = "root@%s" % host
+dest = "sysadmin@example.org"
+relay = "mail.example.com"
+
+
+# Functions
+#
+# Sending out alerts
+def mail(FROM, TO, SUBJECT, BODY):
+ MSG = join((
+ "From: %s" % FROM,
+ "To: %s" % TO,
+ "Subject: %s" % SUBJECT,
+ "",
+ BODY), "\r\n")
+ try:
+ server = SMTP(relay)
+ server.sendmail(FROM, TO, MSG)
+ server.quit()
+ except:
+ pass
+
+
+# Timestamps comparison
+def timecomp(stamp, warn):
+ timen = datetime.utcnow()
+ timeb = datetime.fromtimestamp(stamp)
+ if (timen - timeb) > timedelta(hours = warn):
+ return True
+
+
+# Performing checks and parsing the output
+def main():
+ alarms = []
+
+ for s in servers.keys():
+ for ival in servers[s].keys():
+ mtime = getmtime("%s/%s/%s.1" % (backups, s, ival))
+
+ if timecomp(int(mtime), servers[s][ival]) == True:
+ alarms.append("%s %s.1\t last modified on: %s (UTC)" % (
+ s, ival, datetime.fromtimestamp(int(mtime))))
+
+ if alarms:
+ body = "Outdated backups detected:\n\n%s" % "\n".join(alarms)
+ mail(user, dest, host+": backups timestamp status report", body)
+
+if __name__ == "__main__":
+ main()