mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-13 14:22:16 +00:00
Send alerts as one mail
This commit is contained in:
@@ -12,16 +12,24 @@ def blacklist_check():
|
||||
|
||||
users = User.objects.filter(is_active=True)
|
||||
|
||||
alerts = 0
|
||||
msg = ""
|
||||
|
||||
for u in users:
|
||||
if u.groups.count() > 0:
|
||||
# Has groups
|
||||
val = blacklist_values(u)
|
||||
if len(val) > 0:
|
||||
alerts += 1
|
||||
# Report possible issue
|
||||
log.warning("Suspect User: %s, %s entries found: %s" % (u.username, len(val), val))
|
||||
|
||||
blstr = ""
|
||||
for i in val:
|
||||
blstr = "%s%s - %s - %s\n" % (blstr, i.get_type_display(), i.value, i.reason)
|
||||
msg = "Suspect User found: %s\nGroups: %s\nBlacklist Items:\n\n%s" % (u.username, ", ".join(u.groups.all().values_list('name', flat=True)), blstr)
|
||||
send_mail('Automated blacklist checker alert - %s' % u.username, msg, 'blacklist@pleaseignore.com', ['abuse@pleaseignore.com'])
|
||||
|
||||
msg += "\n\n-----\n\n"
|
||||
msg += "Suspect User found: %s\nGroups: %s\nBlacklist Items:\n\n%s" % (u.username, ", ".join(u.groups.all().values_list('name', flat=True)), blstr)
|
||||
|
||||
if alerts:
|
||||
send_mail('Automated blacklist checker alerts', msg, 'blacklist@pleaseignore.com', ['abuse@pleaseignore.com'])
|
||||
|
||||
Reference in New Issue
Block a user