Ejemplo n.º 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}))
Ejemplo n.º 2
0
Archivo: views.py Proyecto: gisce/AMON
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}))
Ejemplo n.º 3
0
def send_notifications():
    notifications_to_send = generate_notifications()
    for n in notifications_to_send:
        if n.mute != True and n.global_mute != True:
            message = generate_message(notification=n)

            notify = n.alert.get('notifications', [])

            # Collect all emails
            emails_list = []
            for x in notify:
                email = x.get('email')
                if email:
                    emails_list.append(email)

            if len(emails_list) > 0:
                send_notification_email(notification=n, emails=emails_list)

            for provider_auth in notify:
                provider = provider_auth.get('provider_id')

                if provider == 'pushover':
                    send_pushover_notification(message=message,
                                               auth=provider_auth)
                if provider == 'opsgenie':
                    send_opsgenie_notification(message=message,
                                               auth=provider_auth)
                if provider == 'pagerduty':
                    send_pagerduty_notification(message=message,
                                                auth=provider_auth)
                if provider == 'victorops':
                    send_victorops_notification(message=message,
                                                auth=provider_auth)
                if provider == 'slack':
                    send_slack_notification(message=message,
                                            auth=provider_auth)
                if provider == 'hipchat':
                    send_hipchat_notification(message=message,
                                              auth=provider_auth)
                if provider == 'webhook':
                    send_webhook_notification(notification=n,
                                              auth=provider_auth,
                                              message=message)

        alerts_history_model.mark_as_sent(n.trigger['_id'])

    return notifications_to_send  # For the remote command execute
Ejemplo n.º 4
0
def send_notifications():
    notifications_to_send = generate_notifications()
    for n in notifications_to_send:
        if n.mute != True and n.global_mute != True:
            message = generate_message(notification=n)

            notify = n.alert.get('notifications', [])
            
            # Collect all emails
            emails_list = []
            for x in notify:
                email = x.get('email')
                if email:
                    emails_list.append(email)
            
            if len(emails_list) > 0:
                send_notification_email(notification=n, emails=emails_list)

            for provider_auth in notify:
                provider = provider_auth.get('provider_id')
                
                if provider == 'pushover':
                    send_pushover_notification(message=message, auth=provider_auth)
                if provider == 'opsgenie':
                    send_opsgenie_notification(message=message, auth=provider_auth)
                if provider == 'pagerduty':
                    send_pagerduty_notification(message=message, auth=provider_auth)
                if provider == 'victorops':
                    send_victorops_notification(message=message, auth=provider_auth)
                if provider == 'slack':
                    send_slack_notification(message=message, auth=provider_auth)
                if provider == 'telegram':
                    send_telegram_notification(message=message, auth=provider_auth)
                if provider == 'hipchat':
                    send_hipchat_notification(message=message, auth=provider_auth)
                if provider == 'webhook':
                    send_webhook_notification(notification=n, auth=provider_auth, message=message)
        

        alerts_history_model.mark_as_sent(n.trigger['_id'])

    return notifications_to_send # For the remote command execute