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

Added lvalerts on updates.

parent 40b359f7
No related branches found
No related tags found
No related merge requests found
...@@ -14,15 +14,6 @@ from gracedb.userprofile.models import Trigger, AnalysisType ...@@ -14,15 +14,6 @@ from gracedb.userprofile.models import Trigger, AnalysisType
import glue.ligolw.utils import glue.ligolw.utils
import glue.lvalert.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): def issueAlert(event, location, temp_data_loc):
issueXMPPAlert(event, location, temp_data_loc) issueXMPPAlert(event, location, temp_data_loc)
issueEmailAlert(event, location) issueEmailAlert(event, location)
...@@ -35,7 +26,15 @@ def prepareSummary(event): ...@@ -35,7 +26,15 @@ def prepareSummary(event):
return "GPS Time: %s" % event.gpstime 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 = [] profileRecips = []
atype = AnalysisType.objects.filter(code=event.analysisType)[0] atype = AnalysisType.objects.filter(code=event.analysisType)[0]
triggers = label.trigger_set.filter(atypes=atype) triggers = label.trigger_set.filter(atypes=atype)
...@@ -104,15 +103,15 @@ Event Summary: ...@@ -104,15 +103,15 @@ Event Summary:
#send_mail(subject, message, fromaddress, toaddresses) #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 = "%s_%s"% (event.group.name, event.get_analysisType_display())
nodename = nodename.lower() nodename = nodename.lower()
# XXX awful! if nodename not in settings.XMPP_ALERT_CHANNELS:
# Need a good way to know which things to send out to lvalert. f.write("nope. not in list\n")
# Currently, only MBTAOnline and Omega get alerts.
if nodename not in XMPP_ALERT_CHANNELS:
return return
f.write("Node: %s\n" % nodename)
env = {} env = {}
env["PYTHONPATH"] = ":".join(sys.path) env["PYTHONPATH"] = ":".join(sys.path)
...@@ -131,33 +130,34 @@ def issueXMPPAlert(event, location, temp_data_loc): ...@@ -131,33 +130,34 @@ def issueXMPPAlert(event, location, temp_data_loc):
stderr=STDOUT, stderr=STDOUT,
env=env) env=env)
#msg = createPayload(event.graceid(), location) f.write("A\n")
xmldoc = glue.lvalert.utils.make_LVAlertTable(location, event.graceid(), temp_data_loc) 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() buf = StringIO.StringIO()
f.write("d\n")
glue.ligolw.utils.write_fileobj(xmldoc, buf) glue.ligolw.utils.write_fileobj(xmldoc, buf)
f.write("e\n")
msg = buf.getvalue() msg = buf.getvalue()
f.write("f\n")
p.stdin.write(msg) p.stdin.write(msg)
f.write("g\n")
p.stdin.close() p.stdin.close()
f.write("h\n")
for i in range(1,10): for i in range(1,10):
res = p.poll() res = p.poll()
f.write("poll %d\n" % i)
if res == None: if res == None:
f.write("poll %d\n" % i)
time.sleep(1) time.sleep(1)
else: else:
f.write("poll end\n")
break 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 ...@@ -11,7 +11,7 @@ from django.views.generic.list_detail import object_detail, object_list
from models import Event, Group, EventLog, Labelling, Label from models import Event, Group, EventLog, Labelling, Label
from forms import CreateEventForm, EventSearchForm, SimpleSearchForm from forms import CreateEventForm, EventSearchForm, SimpleSearchForm
from alert import issueAlert, issueEmailAlertForLabel from alert import issueAlert, issueAlertForLabel, issueAlertForUpdate
from translator import handle_uploaded_data from translator import handle_uploaded_data
import os import os
...@@ -190,6 +190,12 @@ def _createLog(request, graceid, comment, uploadedFile=None): ...@@ -190,6 +190,12 @@ def _createLog(request, graceid, comment, uploadedFile=None):
rdict['error'] = "Problem saving file: %s" % str(e) rdict['error'] = "Problem saving file: %s" % str(e)
logEntry.save() 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 # XXX should be json
rval = str(rdict) rval = str(rdict)
response['Content-length'] = len(rval) response['Content-length'] = len(rval)
...@@ -272,7 +278,9 @@ def cli_label(request): ...@@ -272,7 +278,9 @@ def cli_label(request):
raise ValueError("No such Label '%s'" % labelName) raise ValueError("No such Label '%s'" % labelName)
# Don't add a label more than once. # 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( labelling = Labelling(
event = event, event = event,
label = label, label = label,
...@@ -283,10 +291,11 @@ def cli_label(request): ...@@ -283,10 +291,11 @@ def cli_label(request):
log = EventLog(event=event, issuer=request.ligouser, comment=message) log = EventLog(event=event, issuer=request.ligouser, comment=message)
log.save() log.save()
try: try:
issueEmailAlertForLabel(event, label) doxmpp = request.POST.get('alert') == "True"
except Exception, e: issueAlertForLabel(event, label, doxmpp)
d['warning'] = "Problem issuing email alert (%s)" % str(e) except Exception, e:
d['warning'] = "Problem issuing alert (%s)" % str(e)
msg = str(d) msg = str(d)
response = HttpResponse(mimetype='application/json') response = HttpResponse(mimetype='application/json')
...@@ -302,6 +311,7 @@ def log(request): ...@@ -302,6 +311,7 @@ def log(request):
if 'cli_version' in request.POST: if 'cli_version' in request.POST:
return _createLog(request, graceid, message) return _createLog(request, graceid, message)
# old, old client only
response = HttpResponse(mimetype='text/plain') response = HttpResponse(mimetype='text/plain')
try: try:
event = graceid and Event.getByGraceid(graceid) event = graceid and Event.getByGraceid(graceid)
...@@ -320,6 +330,7 @@ def log(request): ...@@ -320,6 +330,7 @@ def log(request):
msg = "OK" msg = "OK"
except: except:
msg = "ERROR: problem creating log entry" msg = "ERROR: problem creating log entry"
response = HttpResponse(mimetype='text/plain') response = HttpResponse(mimetype='text/plain')
response.write(msg) response.write(msg)
response['Content-length'] = len(msg) response['Content-length'] = len(msg)
......
...@@ -28,6 +28,15 @@ ALERT_TEST_EMAIL_TO = [ ...@@ -28,6 +28,15 @@ ALERT_TEST_EMAIL_TO = [
"bmoe@gravity.phys.uwm.edu", "bmoe@gravity.phys.uwm.edu",
] ]
XMPP_ALERT_CHANNELS = [
'burst_omega',
'test_omega',
'cbc_mbtaonline',
'test_mbtaonline',
'burst_cwb',
'test_cwb',
]
DATABASE_ENGINE = 'mysql' DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'gracedb' DATABASE_NAME = 'gracedb'
DATABASE_USER = 'gracedb' DATABASE_USER = 'gracedb'
......
...@@ -20,6 +20,13 @@ ALERT_TEST_EMAIL_TO = [ ...@@ -20,6 +20,13 @@ ALERT_TEST_EMAIL_TO = [
"Brian Moe <bmoe@gravity.phys.uwm.edu>", "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_ENGINE = 'mysql'
DATABASE_NAME = 'gracedb' DATABASE_NAME = 'gracedb'
DATABASE_USER = 'gracedb' DATABASE_USER = 'gracedb'
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<tr> <tr>
<th valign="top">UID</th> <th valign="top">UID</th>
<th>Labels</th> <th>Labels</th>
<th>Group</th>
<th>Type</th> <th>Type</th>
<th> <th>
{{ "gps"|timeselect:"gps" }} {{ "gps"|timeselect:"gps" }}
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
<span title="{{labelling.creator.name}} {{labelling.created|utc}}" style="color: {{labelling.label.defaultColor}}">{{ labelling.label.name }}</span> <span title="{{labelling.creator.name}} {{labelling.created|utc}}" style="color: {{labelling.label.defaultColor}}">{{ labelling.label.name }}</span>
{% endfor %} {% endfor %}
</td> </td>
<td>{{ object.group.name }} </td>
<td>{{ object.get_analysisType_display }} </td> <td>{{ object.get_analysisType_display }} </td>
<td>{% if object.gpstime%} <td>{% if object.gpstime%}
<!-- <span title="{{ object.gpstime|gpsdate }}">{{ object.gpstime }}</span> --> <!-- <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