def send_notifications(notification_id): try: notification = ScheduledNotification.objects.get(id=notification_id) if notification.notifier == UserNotificationMethod.METHOD_XMPP: notifier = XmppNotifier(settings.XMPP_SETTINGS) if notification.notifier == UserNotificationMethod.METHOD_EMAIL: notifier = EmailNotifier(settings.EMAIL_SETTINGS) if notification.notifier == UserNotificationMethod.METHOD_TWILIO_SMS: notifier = TwilioSmsNotifier(settings.TWILIO_SETTINGS) if notification.notifier == UserNotificationMethod.METHOD_TWILIO_CALL: notifier = TwilioCallNotifier(settings.TWILIO_SETTINGS) if notification.notifier == UserNotificationMethod.METHOD_SLACK: notifier = SlackNotifier(settings.SLACK_SETTINGS) elif notification.notifier == UserNotificationMethod.METHOD_PUSHOVER: notifier = PushoverNotifier() elif notification.notifier == UserNotificationMethod.METHOD_PROWL: notifier = ProwlNotifier(settings.PROWL_SETTINGS) elif notification.notifier == UserNotificationMethod.METHOD_ROCKET: notifier = RocketNotifier() elif notification.notifier == UserNotificationMethod.METHOD_HIPCHAT: notifier = HipchatNotifier(settings.HIPCHAT_SETTINGS) notifier.notify(notification) # Log successful notification logmessage = EventLog() if notification.incident: logmessage.service_key = notification.incident.service_key logmessage.incident_key = notification.incident logmessage.user = notification.user_to_notify logmessage.action = 'notified' logmessage.data = "Notification sent to %s about %s service via %s" % ( notification.user_to_notify, logmessage.service_key, notification.notifier, ) logmessage.occurred_at = timezone.now() logmessage.save() return (logmessage.data) if notification.notifier != UserNotificationMethod.METHOD_TWILIO_CALL: # In case of a twilio call, we need the object for TWiml generation notification.delete() except ScheduledNotification.DoesNotExist: pass #Incident was resolved. NOP. except Exception, e: # Log successful notification logmessage = EventLog() if notification.incident: logmessage.service_key = notification.incident.service_key logmessage.incident_key = notification.incident logmessage.user = notification.user_to_notify logmessage.action = 'notification_failed' logmessage.data = "Sending notification failed to %s about %s service because %s" % ( notification.user_to_notify, logmessage.service_key, e, ) logmessage.occurred_at = timezone.now() logmessage.save() return (logmessage.data) raise
def send_notifications(notification_id): try: notification = ScheduledNotification.objects.get(id=notification_id) if notification.notifier == UserNotificationMethod.METHOD_XMPP: notifier = XmppNotifier(settings.XMPP_SETTINGS) if notification.notifier == UserNotificationMethod.METHOD_EMAIL: notifier = EmailNotifier(settings.XMPP_SETTINGS) if notification.notifier == UserNotificationMethod.METHOD_TWILIO_SMS: notifier = TwilioSmsNotifier(settings.TWILIO_SETTINGS) if notification.notifier == UserNotificationMethod.METHOD_TWILIO_CALL: notifier = TwilioCallNotifier(settings.TWILIO_SETTINGS) elif notification.notifier == UserNotificationMethod.METHOD_PUSHOVER: notifier = PushoverNotifier() notifier.notify(notification) notification.delete() except ScheduledNotification.DoesNotExist: pass #Incident was resolved. NOP.