2014-05-08 16:59:35 +00:00
|
|
|
from django.template import Template, Context
|
2014-07-11 14:48:46 +00:00
|
|
|
from django.utils import timezone
|
2014-07-09 16:17:43 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2014-05-08 16:59:35 +00:00
|
|
|
|
2014-07-09 16:17:43 +00:00
|
|
|
from orchestra.apps.orchestration import ServiceController
|
|
|
|
from orchestra.apps.resources import ServiceMonitor
|
2014-05-08 16:59:35 +00:00
|
|
|
|
2014-07-11 14:48:46 +00:00
|
|
|
from . import settings
|
|
|
|
|
2014-05-08 16:59:35 +00:00
|
|
|
|
2014-07-09 16:17:43 +00:00
|
|
|
class MailmanBackend(ServiceController):
|
2014-05-08 16:59:35 +00:00
|
|
|
verbose_name = "Mailman"
|
|
|
|
model = 'lists.List'
|
2014-07-09 16:17:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MailmanTraffic(ServiceMonitor):
|
|
|
|
model = 'lists.List'
|
|
|
|
resource = ServiceMonitor.TRAFFIC
|
|
|
|
|
2014-07-11 14:48:46 +00:00
|
|
|
def monitor(self, mail_list):
|
|
|
|
context = self.get_context(mail_list)
|
2014-07-09 16:17:43 +00:00
|
|
|
self.append(
|
2014-07-11 14:48:46 +00:00
|
|
|
"SUBSCRIBERS=$(list_members %(list_name)s | wc -l)\n"
|
|
|
|
"SIZE=$(grep ' post to %(list_name)s ' %(mailman_log)s \\\n"
|
|
|
|
" | awk '\"%(last_date)s\"<=$0 && $0<=\"%(current_date)s\"' \\\n"
|
|
|
|
" | sed 's/.*size=\([0-9]*\).*/\\1/' \\\n"
|
|
|
|
" | tr '\\n' '+' \\\n"
|
|
|
|
" | xargs -i echo {}0 )\n"
|
|
|
|
"echo %(object_id)s $(( ${SIZE}*${SUBSCRIBERS} ))" % context)
|
|
|
|
|
|
|
|
def get_context(self, mail_list):
|
2014-07-14 14:56:48 +00:00
|
|
|
last_date = timezone.localtime(self.get_last_date(mail_list.pk))
|
|
|
|
current_date = timezone.localtime(self.current_date)
|
2014-07-11 14:48:46 +00:00
|
|
|
return {
|
|
|
|
'mailman_log': settings.LISTS_MAILMAN_POST_LOG_PATH,
|
|
|
|
'list_name': mail_list.name,
|
|
|
|
'object_id': mail_list.pk,
|
2014-07-14 14:56:48 +00:00
|
|
|
'last_date': last_date.strftime("%b %d %H:%M:%S"),
|
|
|
|
'current_date': current_date.strftime("%b %d %H:%M:%S"),
|
2014-07-11 14:48:46 +00:00
|
|
|
}
|