from django.core import mail
from django.template.loader import get_template
from django.template import Context
from noc_site.notify.models import Notification, Partner
def notify_Notification():
#I only want to touch a specific notification
notification = Notification.objects.filter(id='2')
notification_type = notification.all()[0].notify_type
partners = Partner.objects.all()
for partner in partners:
to_list = [ptr.email for ptr in partner.to_contact.all()]
cc_list = [ptr.email for ptr in partner.cc_contact.all()]
bcc_list = [ptr.email for ptr in partner.cc_contact.all()]
#Scheduled Maintenance Notification
if notification_type == 'Scheduled':
#Times
start = notification.all()[0].start
end = notification.all()[0].end
env = notification.all()[0].env
plaintext = get_template('maintenance-notification.txt')
variables = Context(
{
'start': start,
'end': end,
'env': env,
}
)
connection = mail.get_connection()
text_content = plaintext.render(variables)
EMail = mail.EmailMessage('Subject', text_content,
'email@tld.com',
to=to_list, cc=cc_list, bcc=bcc_list,)
EMail.send()
#Outage Notification
if notification_type == 'Outage':
start = notification.all()[0].start
env = notification.all()[0].env
if(notification.all()[0].restored):
end = notification.all()[0].end
else:
end = 'TBD'
plaintext = get_template('outage-notification.txt')
variables = Context(
{
'start': start,
'end': end,
'env': env,
}
)
connection = mail.get_connection()
text_content = plaintext.render(variables)
EMail = mail.EmailMessage('Subject', text_content,
'email@tld.com',
to=to_list, cc=cc_list, bcc=bcc_list,)
EMail.send()