Example #1
0
def mark_blk(mx_obj, rbl_obj):
    b_hist, created = BlacklistHistory.objects.get_or_create(mailserver=mx_obj, close_time=None)
    mx_status = MailserverStatus.objects.get(mailserver=mx_obj)

    # The following tests if this is a new detected blacklist or not
    # If it is, we just add it to the list.  If not, we return out of the
    # function so we don't keep writing to the database.
    b_rbl, created_rbl = mx_obj.mailserverrblstatus_set.get_or_create(rbl=rbl_obj)
    if b_rbl.status == 'clear':
        b_rbl.status = 'blacklisted'
        b_rbl.save()
        b_hist.rbl.add(rbl_obj) # Adds rbl to history

    if created or mx_status.blacklist == 'clear':
        mx_status.blacklist = 'blacklisted'
        mx_status.save()
        # If the mailserver goes from clear->blacklist, it is the first
        # time the blacklist happened, so alert the client.
        email_wait_time = mx_obj.mailserverprefs_set.get().send_email_min
        if email_wait_time == 0:
            compose_email(mx_obj, rbl_obj.name, 'blacklist')
        else:
            queue_alert('sms', mx_obj, rbl_obj.name, email_wait_time, "blacklist")
Example #2
0

# This check runs through and looks at the PortHistoryQueue list.  If
# more than two instances exist, it marks it down.
#mx_list = get_all_mailservers()
#for mx in mx_list:
#    check_port_queue(mx)


# This checks the probe statuses
generate_probe_status()

# This part goes through the QueueAlert (alerts with a delay until emailed)
# and sends any that need to be sent.  These somewhat repetitive tests are to
# determine if the reason why the alert is being sent is still true.  The alert
# gets deleted in the end.
alert_list = QueueAlert.objects.filter(delivery_time__lte=datetime.now())
for alert_item in alert_list:
    if alert_item.delivery_type == 'email':
        if (alert_item.type == 'portdown' and alert_item.mailserver.mailserverstatus_set.get().port == 'down') or (alert_item.type == 'portup' and alert_item.mailserver.mailserverstatus_set.get().port == 'up'):
            compose_email(alert_item.mailserver, alert_item.alert, alert_item.type)
        elif (alert_item.mailserver.mailserverstatus_set.get().blacklist == 'blacklisted' and alert_item.type == 'blacklist') or (alert_item.mailserver.mailserverstatus_set.get().blacklist == 'clear' and alert_item.type == 'clear'):
            compose_email(alert_item.mailserver, alert_item.alert, alert_item.type)
    elif alert_item.delivery_type == 'sms':
        if (alert_item.type == 'portdown' and alert_item.mailserver.mailserverstatus_set.get().port == 'down') or (alert_item.type == 'portup' and alert_item.mailserver.mailserverstatus_set.get().port == 'up'):
            compose_sms(alert_item.mailserver, alert_item.alert, alert_item.type)
        elif (alert_item.mailserver.mailserverstatus_set.get().blacklist == 'blacklisted' and alert_item.type == 'blacklist') or (alert_item.mailserver.mailserverstatus_set.get().blacklist == 'clear' and alert_item.type == 'clear'):
            compose_sms(alert_item.mailserver, alert_item.alert, alert_item.type)
    alert_item.delete()