Exemple #1
0
def test(request, provider_id=None, notification_id=None):

    auth = notifications_model.get_by_id(notification_id)

    message = 'Test Notification'

    if provider_id == 'pushover':
        send_pushover_notification(message=message, auth=auth)
    elif provider_id == 'pagerduty':
        send_pagerduty_notification(message=message, auth=auth)
    elif provider_id == 'victorops':
        send_victorops_notification(message=message, auth=auth)
    elif provider_id == 'opsgenie':
        send_opsgenie_notification(message=message, auth=auth)
    elif provider_id == 'slack':
        send_slack_notification(message=message, auth=auth)
    elif provider_id == 'hipchat':
        send_hipchat_notification(message=message, auth=auth)
    elif provider_id == 'webhook':
        _send_webhook(auth=auth, data={"message": message})
    elif provider_id == 'email':
        emails = [auth.get('email')]
        send_test_email(emails=emails)
    else:
        return redirect(reverse('notifications_all'))

    messages.add_message(request, messages.INFO, 'Sending test notification to {0}'.format(provider_id.title()))

    return redirect(reverse('notifications_edit', kwargs={'provider_id': provider_id, 'notification_id': notification_id}))
Exemple #2
0
def test(request, provider_id=None, notification_id=None):

    auth = notifications_model.get_by_id(notification_id)

    message = 'Test Notification'

    if provider_id == 'pushover':
        send_pushover_notification(message=message, auth=auth)
    elif provider_id == 'pagerduty':
        send_pagerduty_notification(message=message, auth=auth)
    elif provider_id == 'victorops':
        send_victorops_notification(message=message, auth=auth)
    elif provider_id == 'opsgenie':
        send_opsgenie_notification(message=message, auth=auth)
    elif provider_id == 'slack':
        send_slack_notification(message=message, auth=auth)
    elif provider_id == 'hipchat':
        send_hipchat_notification(message=message, auth=auth)
    elif provider_id == 'webhook':
        _send_webhook(auth=auth, data={"message": message})
    elif provider_id == 'email':
        emails = [auth.get('email')]
        send_test_email(emails=emails)
    else:
        return redirect(reverse('notifications_all'))

    messages.add_message(request, messages.INFO, 'Sending test notification to {0}'.format(provider_id.title()))

    return redirect(reverse('notifications_edit', kwargs={'provider_id': provider_id, 'notification_id': notification_id}))
Exemple #3
0
    def _get_notifications(self, alert):
        notifications_list = []
        notifications = alert.get('notifications', None)
        if notifications:

            for x in notifications:
                split_provider_id = x.split(':')  # email:id
                if len(
                        split_provider_id
                ) == 2:  # New format, ignore old ['hipchat', 'something']
                    _id = split_provider_id[1]
                    result = notifications_model.get_by_id(_id)
                    notifications_list.append(result)

        return notifications_list
Exemple #4
0
def edit(request, provider_id=None, notification_id=None):
    provider_data = notifications_model.get_by_id(notification_id)

    all_for_provider = notifications_model.get_all_for_provider(
        provider_id=provider_id)

    provider_form = PROVIDERS.get(provider_id, False)

    if not provider_form:
        return redirect(reverse('notifications_all'))

    if request.method == "POST":
        form = provider_form(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            notifications_model.update(data=data, id=notification_id)

            if 'test' in request.POST:
                redirect_url = reverse('notifications_test',
                                       kwargs={
                                           'provider_id': provider_id,
                                           'notification_id': notification_id
                                       })

            else:
                redirect_url = reverse('notifications_edit',
                                       kwargs={
                                           'provider_id': provider_id,
                                           'notification_id': notification_id
                                       })

            messages.add_message(
                request, messages.INFO,
                '{0} settings updated'.format(provider_id.title()))

            return redirect(redirect_url)
    else:
        form = provider_form(provider_data=provider_data)

    return render(
        request, 'notifications/view.html', {
            "form": form,
            "provider_id": provider_id,
            "provider_data": provider_data,
            "all_for_provider": all_for_provider,
            "notification_id": notification_id
        })
Exemple #5
0
def edit(request, provider_id=None, notification_id=None):
    provider_data = notifications_model.get_by_id(notification_id)

    all_for_provider = notifications_model.get_all_for_provider(provider_id=provider_id)

    provider_form = PROVIDERS.get(provider_id, False)

    if not provider_form:
        return redirect(reverse('notifications_all'))

    if request.method == "POST":
        form = provider_form(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            notifications_model.update(data=data, id=notification_id)

            if 'test' in request.POST:
                redirect_url = reverse('notifications_test', kwargs={'provider_id': provider_id, 'notification_id': notification_id})

            else:
                redirect_url = reverse('notifications_edit', kwargs={'provider_id': provider_id, 'notification_id': notification_id})

            messages.add_message(request, messages.INFO, '{0} settings updated'.format(provider_id.title()))

            return redirect(redirect_url)
    else:
        form = provider_form(provider_data=provider_data)

    return render(request, 'notifications/view.html', {
        "form": form,
        "provider_id": provider_id,
        "provider_data": provider_data,
        "all_for_provider": all_for_provider,
        "notification_id": notification_id
    })