django-orchestra-test/orchestra/apps/lists/backends.py

42 lines
1.5 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django.template import Template, Context
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-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
def process(self, output):
for line in output.readlines():
listname, value = line.strip().slpit()
2014-05-08 16:59:35 +00:00
2014-07-09 16:17:43 +00:00
def monitor(self, mailinglist):
self.append(
"LISTS=$(grep -v 'post to mailman' /var/log/mailman/post"
" | grep size | cut -d'<' -f2 | cut -d'>' -f1 | sort | uniq"
" | while read line; do \n"
" grep \"$line\" post | head -n1 | awk {'print $8\" \"$11'}"
" | sed 's/size=//' | sed 's/,//'\n"
"done)"
)
self.append(
'SUBS=""\n'
'while read LIST; do\n'
' NAME=$(echo "$LIST" | awk {\'print $1\'})\n'
' SIZE=$(echo "$LIST" | awk {\'print $2\'})\n'
' if [[ ! $(echo -e "$SUBS" | grep "$NAME") ]]; then\n'
' SUBS="${SUBS}${NAME} $(list_members "$NAME" | wc -l)\n"\n'
' fi\n'
' SUBSCRIBERS=$(echo -e "$SUBS" | grep "$NAME" | awk {\'print $2\'})\n'
' echo "$NAME $(($SUBSCRIBERS*$SIZE))"\n'
'done <<< "$LISTS"'
)