]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - modules/porterbox/files/mail-big-homedirs
apply Bill Allombert's patch with fixes
[dsa-puppet.git] / modules / porterbox / files / mail-big-homedirs
index 41f6a25b314c8281b3db42c35c756265d917d06d..5dbe9859f64d1fa1f70fa86a86fc2d098de3014c 100755 (executable)
@@ -1,9 +1,10 @@
 #!/usr/bin/python
 ## vim:set et ts=2 sw=2 ai:
-# homedir_reminder.py - Reminds users about sizable homedirs.
+# Send email reminders to users having sizable homedirs.
 ##
 # Copyright (c) 2013 Philipp Kern <phil@philkern.de>
 # Copyright (c) 2013 Peter Palfrader <peter@palfrader.org>
+# Copyright (c) 2013 Luca Filipozzi <lfilipoz@debian.org>
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -33,45 +34,62 @@ import logging
 import os.path
 import platform
 import pwd
+import random
 import subprocess
 import struct
 import time
 import StringIO
-import pwd
 
 # avoid base64 encoding for utf-8
 email.charset.add_charset('utf-8', email.charset.SHORTEST, email.charset.QP)
 
-
 SENDMAIL = ['/usr/sbin/sendmail', '-t', '-oi']
 #SENDMAIL = ['/bin/cat']
 
+EXPLANATIONS = [
+u"""\
+{hostname} /home is growing close to full.  If you have anything in there that
+you no longer need, please clean it up.""" # By Martin Zobel-Helas
+,u"""\
+Can you please look at your $HOME on {hostname} and remove files which you
+no longer need (such as old sources).""" # By Martin Michlmayr
+,u"""\
+Thanks for your porting effort on {hostname}!
+
+Please note that /home is running short of diskspace, so please remove files
+you do not need anymore.""" # By Bill Allombert
+  # Please add more from your archive!
+  ]
+
 REPORT_SIZES = [
-    { 'days': 5, 'size': 10240 },
-    { 'days': 10, 'size': 1024 },
-    { 'days': 30, 'size': 100 },
-    { 'days': 60, 'size': 20 },
-    { 'days': 150, 'size': 10 }
+    { 'days':  5, 'size': 10240 },
+    { 'days': 10, 'size':  1024 },
+    { 'days': 30, 'size':   100 },
+    { 'days': 60, 'size':    60 },
+    { 'days': 90, 'size':    30 }
   ]
 USER_EXCLUSION_LIST = ['lost+found']
-MAIL_FROM = 'dsa@debian.org'
+MAIL_FROM = 'debian-admin (via Cron) <bulk@admin.debian.org>'
 MAIL_TO = '{username}@{hostname}.debian.org'
-MAIL_CC = ''
+MAIL_CC = 'debian-admin (bulk sink) <bulk@admin.debian.org>'
+MAIL_REPLYTO = 'debian-admin <dsa@debian.org>'
 MAIL_SUBJECT = 'Please clean up ~{username} on {hostname}.debian.org'
 MAIL_TEXT = u"""\
-Hi {name},
+Hi {name}!
 
-you last logged into {hostname} {days_ago} days ago, and your home
-directory there is {homedir_size}MB in size.
+{explanation}
 
-Disk space on porter boxes is often limited.  Please respect your fellow
-porters by cleaning up after yourself and deleting schroots and source/build
-trees in your home directory as soon as feasible.
+For your information, you last logged into {hostname} {days_ago} days ago, and
+your home directory there is {homedir_size} MB in size.
 
-If you currently do not use {hostname}, please keep ~{username} under 10MB.
+If you currently do not use {hostname}, please keep ~{username} under 30 MB,
+if possible.  Please assist us in freeing up space by deleting schroots, also.
 
 Thanks,
-Cron, on behalf of your catherders/admins
+
+Debian System Administration Team via Cron
+
+PS: replies not required.
 """
 
 class Error(Exception):
@@ -153,7 +171,8 @@ class HomedirReminder(object):
     msg = email.mime.text.MIMEText(MAIL_TEXT.format(**kwargs), _charset='UTF-8')
     msg['From'] = MAIL_FROM.format(**kwargs)
     msg['To'] = MAIL_TO.format(**kwargs)
-    msg['Cc'] = MAIL_CC.format(**kwargs)
+    if MAIL_CC != "": msg['Cc'] = MAIL_CC.format(**kwargs)
+    if MAIL_REPLYTO != "": msg['Reply-To'] = MAIL_REPLYTO.format(**kwargs)
     msg['Subject'] = MAIL_SUBJECT.format(**kwargs)
     msg['Precedence'] = "bulk"
     msg['Auto-Submitted'] = "auto-generated by mail-big-homedirs"
@@ -172,18 +191,22 @@ class HomedirReminder(object):
 
       reportsize = None
       for e in REPORT_SIZES:
-        if days_ago > e['days']: reportsize = e['size']
+        if days_ago >= e['days']: reportsize = e['size']
 
       if reportsize is not None and homedir_size > reportsize:
         logging.warning('Homedir of user %s is %d and did not login for a while', username, homedir_size)
         try:
           name = pwd.getpwnam(username).pw_gecos.decode('utf-8')
           name = name.split(',', 1)[0]
+          name = name.split(' ', 1)[0]
         except:
           name = username
+        explanation = EXPLANATIONS[random.randint(0,len(EXPLANATIONS)-1)]
+        explanation = explanation.format(hostname=platform.node())
         self.send_mail(hostname=platform.node(),
                        username=username,
                        name=name,
+                       explanation=explanation,
                        homedir_size=homedir_size,
                        days_ago=days_ago)