Skip to content
Snippets Groups Projects
Commit 75556638 authored by Brian Moe's avatar Brian Moe
Browse files

Merge branch 'alert'

parents f43b212f 48764789
No related branches found
No related tags found
No related merge requests found
......@@ -14,15 +14,6 @@ from gracedb.userprofile.models import Trigger, AnalysisType
import glue.ligolw.utils
import glue.lvalert.utils
XMPP_ALERT_CHANNELS = [
'burst_omega',
'test_omega',
'cbc_mbtaonline',
'test_mbtaonline',
'burst_cwb',
'test_cwb',
]
def issueAlert(event, location, temp_data_loc):
issueXMPPAlert(event, location, temp_data_loc)
issueEmailAlert(event, location)
......@@ -35,7 +26,15 @@ def prepareSummary(event):
return "GPS Time: %s" % event.gpstime
def issueEmailAlertForLabel(event, label):
def issueAlertForUpdate(event, description, doxmpp):
if doxmpp:
issueXMPPAlert(event, "", "", "update", description)
# XXX No emails for this. Argh.
def issueAlertForLabel(event, label, doxmpp):
if doxmpp:
issueXMPPAlert(event, "", "", "label", label)
# Email
profileRecips = []
atype = AnalysisType.objects.filter(code=event.analysisType)[0]
triggers = label.trigger_set.filter(atypes=atype)
......@@ -104,15 +103,15 @@ Event Summary:
#send_mail(subject, message, fromaddress, toaddresses)
def issueXMPPAlert(event, location, temp_data_loc):
def issueXMPPAlert(event, location, temp_data_loc, alert_type="new", description=""):
f = open('tmp/foo','a')
nodename = "%s_%s"% (event.group.name, event.get_analysisType_display())
nodename = nodename.lower()
# XXX awful!
# Need a good way to know which things to send out to lvalert.
# Currently, only MBTAOnline and Omega get alerts.
if nodename not in XMPP_ALERT_CHANNELS:
if nodename not in settings.XMPP_ALERT_CHANNELS:
f.write("nope. not in list\n")
return
f.write("Node: %s\n" % nodename)
env = {}
env["PYTHONPATH"] = ":".join(sys.path)
......@@ -131,33 +130,34 @@ def issueXMPPAlert(event, location, temp_data_loc):
stderr=STDOUT,
env=env)
#msg = createPayload(event.graceid(), location)
xmldoc = glue.lvalert.utils.make_LVAlertTable(location, event.graceid(), temp_data_loc)
f.write("A\n")
xmldoc = glue.lvalert.utils.make_LVAlertTable(
location,
event.graceid(),
temp_data_loc,
alert_type,
description)
f.write("B: %s\n" % str(xmldoc))
f.write("c\n")
buf = StringIO.StringIO()
f.write("d\n")
glue.ligolw.utils.write_fileobj(xmldoc, buf)
f.write("e\n")
msg = buf.getvalue()
f.write("f\n")
p.stdin.write(msg)
f.write("g\n")
p.stdin.close()
f.write("h\n")
for i in range(1,10):
res = p.poll()
f.write("poll %d\n" % i)
if res == None:
f.write("poll %d\n" % i)
time.sleep(1)
else:
f.write("poll end\n")
break
def createPayload (uid, filename):
template = """<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE LIGO_LW SYSTEM "http://ldas-sw.ligo.caltech.edu/doc/ligolwAPI/html/ligolw_dtd.txt">
<LIGO_LW>
<Table Name="LVAlert:table">
<Column Type="lstring" Name="LVAlert:uid"/>
<Column Type="lstring" Name="LVAlert:file"/>
<Stream Name="LVAlert:table" Type="Local" Delimiter=",">
"%(uid)s","%(filename)s"
</Stream>
</Table>
</LIGO_LW>
"""
return template % { 'uid': uid, 'filename': filename }
......@@ -11,7 +11,7 @@ from django.views.generic.list_detail import object_detail, object_list
from models import Event, Group, EventLog, Labelling, Label
from forms import CreateEventForm, EventSearchForm, SimpleSearchForm
from alert import issueAlert, issueEmailAlertForLabel
from alert import issueAlert, issueAlertForLabel, issueAlertForUpdate
from translator import handle_uploaded_data
import os
......@@ -190,6 +190,12 @@ def _createLog(request, graceid, comment, uploadedFile=None):
rdict['error'] = "Problem saving file: %s" % str(e)
logEntry.save()
if request.POST.get('alert') == "True":
description = "LOG: "
if uploadedFile:
description = "UPLOAD: '%s' " % uploadedFile.name
issueAlertForUpdate(event, description+comment, doxmpp=True)
# XXX should be json
rval = str(rdict)
response['Content-length'] = len(rval)
......@@ -272,7 +278,9 @@ def cli_label(request):
raise ValueError("No such Label '%s'" % labelName)
# Don't add a label more than once.
if label not in event.labels.all():
if label in event.labels.all():
d['warning'] = "Event %s already labeled with '%s'" % (event.graceid(), labelName)
else:
labelling = Labelling(
event = event,
label = label,
......@@ -283,10 +291,11 @@ def cli_label(request):
log = EventLog(event=event, issuer=request.ligouser, comment=message)
log.save()
try:
issueEmailAlertForLabel(event, label)
except Exception, e:
d['warning'] = "Problem issuing email alert (%s)" % str(e)
try:
doxmpp = request.POST.get('alert') == "True"
issueAlertForLabel(event, label, doxmpp)
except Exception, e:
d['warning'] = "Problem issuing alert (%s)" % str(e)
msg = str(d)
response = HttpResponse(mimetype='application/json')
......@@ -302,6 +311,7 @@ def log(request):
if 'cli_version' in request.POST:
return _createLog(request, graceid, message)
# old, old client only
response = HttpResponse(mimetype='text/plain')
try:
event = graceid and Event.getByGraceid(graceid)
......@@ -320,6 +330,7 @@ def log(request):
msg = "OK"
except:
msg = "ERROR: problem creating log entry"
response = HttpResponse(mimetype='text/plain')
response.write(msg)
response['Content-length'] = len(msg)
......
......@@ -28,6 +28,15 @@ ALERT_TEST_EMAIL_TO = [
"bmoe@gravity.phys.uwm.edu",
]
XMPP_ALERT_CHANNELS = [
'burst_omega',
'test_omega',
'cbc_mbtaonline',
'test_mbtaonline',
'burst_cwb',
'test_cwb',
]
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'gracedb'
DATABASE_USER = 'gracedb'
......
......@@ -20,6 +20,13 @@ ALERT_TEST_EMAIL_TO = [
"Brian Moe <bmoe@gravity.phys.uwm.edu>",
]
# Don't sent out non-test XMPP alerts on dev box!
XMPP_ALERT_CHANNELS = [
'test_omega',
'test_mbtaonline',
'test_cwb',
]
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'gracedb'
DATABASE_USER = 'gracedb'
......
......@@ -12,6 +12,7 @@
<tr>
<th valign="top">UID</th>
<th>Labels</th>
<th>Group</th>
<th>Type</th>
<th>
{{ "gps"|timeselect:"gps" }}
......@@ -32,6 +33,7 @@
<span title="{{labelling.creator.name}} {{labelling.created|utc}}" style="color: {{labelling.label.defaultColor}}">{{ labelling.label.name }}</span>
{% endfor %}
</td>
<td>{{ object.group.name }} </td>
<td>{{ object.get_analysisType_display }} </td>
<td>{% if object.gpstime%}
<!-- <span title="{{ object.gpstime|gpsdate }}">{{ object.gpstime }}</span> -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment