예제 #1
0
def log_alert(e, *args, **kwargs):
    # no try catch here, if this fails we need to show an error
    users = Dojo_User.objects.filter(is_superuser=True)
    for user in users:
        alert = Alerts(user_id=user,
                       url=kwargs.get('url', reverse('alerts')),
                       title='Notification issue',
                       description="%s" % e,
                       icon="exclamation-triangle",
                       source="Notifications")
        # relative urls will fail validation
        alert.clean_fields(exclude=['url'])
        alert.save()
예제 #2
0
def log_alert(e, notification_type=None, *args, **kwargs):
    # no try catch here, if this fails we need to show an error

    users = Dojo_User.objects.filter((Q(is_superuser=True) | Q(is_staff=True)))
    for user in users:
        alert = Alerts(user_id=user,
                       url=kwargs.get('url', reverse('alerts'))[:100],
                       title=kwargs.get('title', 'Notification issue'),
                       description=kwargs.get('description', '%s' % e)[:2000],
                       icon="exclamation-triangle",
                       source=notification_type[:100] if notification_type else
                       kwargs.get('source', 'unknown')[:100])
        # relative urls will fail validation
        alert.clean_fields(exclude=['url'])
        alert.save()
예제 #3
0
def send_alert_notification(event, user=None, *args, **kwargs):
    print('sending alert notification')
    try:
        icon = kwargs.get('icon', 'info-circle')
        alert = Alerts(user_id=user,
                       title=kwargs.get('title')[:100],
                       description=create_notification_message(
                           event, user, 'alert', *args, **kwargs),
                       url=kwargs.get('url', reverse('alerts')),
                       icon=icon[:25],
                       source=Notifications._meta.get_field(
                           event).verbose_name.title()[:100])
        # relative urls will fail validation
        alert.clean_fields(exclude=['url'])
        alert.save()
    except Exception as e:
        logger.exception(e)
        log_alert(e, *args, **kwargs)
        pass
예제 #4
0
def send_alert_notification(event, user=None, *args, **kwargs):
    logger.debug('sending alert notification to %s', user)
    try:
        # no need to differentiate between user/no user
        icon = kwargs.get('icon', 'info-circle')
        alert = Alerts(
            user_id=user,
            title=kwargs.get('title')[:250],
            description=create_notification_message(event, user, 'alert', *args, **kwargs)[:2000],
            url=kwargs.get('url', reverse('alerts')),
            icon=icon[:25],
            source=Notifications._meta.get_field(event).verbose_name.title()[:100]
        )
        # relative urls will fail validation
        alert.clean_fields(exclude=['url'])
        alert.save()
    except Exception as e:
        logger.exception(e)
        log_alert(e, "Alert Notification", title=kwargs['title'], description=str(e), url=kwargs['url'])
        pass