X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=modules%2Fporterbox%2Ffiles%2Fmail-big-homedirs;h=5dbe9859f64d1fa1f70fa86a86fc2d098de3014c;hb=245ba7ea907401e38bda78fcd7a6cc0ef07101ef;hp=da12c28f786f1f4bbc3b067f86f64bb8140399a3;hpb=f4c8ce78caba64b9a6aa76a89c7debcf98ccbb90;p=dsa-puppet.git diff --git a/modules/porterbox/files/mail-big-homedirs b/modules/porterbox/files/mail-big-homedirs index da12c28f..5dbe9859 100755 --- a/modules/porterbox/files/mail-big-homedirs +++ b/modules/porterbox/files/mail-big-homedirs @@ -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 # Copyright (c) 2013 Peter Palfrader +# Copyright (c) 2013 Luca Filipozzi # # 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,25 +34,39 @@ 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 = 'debian-admin (via Cron) ' @@ -60,19 +75,19 @@ MAIL_CC = 'debian-admin (bulk sink) ' MAIL_REPLYTO = 'debian-admin ' 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. """ @@ -176,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)