diff --git a/gracedb/alerts/lvalert.py b/gracedb/alerts/lvalert.py index 7e3166301eccbe5a4d2e837d2e811740b634a5ed..fb9256fd77390d0f6481bb6cbe858ea459e8bc07 100644 --- a/gracedb/alerts/lvalert.py +++ b/gracedb/alerts/lvalert.py @@ -2,6 +2,8 @@ import logging from multiprocessing import Process import os from subprocess import Popen, PIPE + +from ligo.lvalert import LVAlertClient from ligo.overseer.overseer_client import send_to_overseer # Set up logger @@ -31,6 +33,21 @@ def send_with_lvalert_overseer(node_name, message, manager, port): return True if rdict.get('success', None) is not None else False +def send_with_lvalert_client(node, message, server): + + # Instantiate client + client = LVAlertClient(server=server) + + # Client setup + client.connect(reattempt=False) + client.auto_reconnect = False + client.process(block=False) + + # Send message + client.publish(node, message) + + +# OLD def send_with_lvalert_send(node, message, server): # Set up environment for running lvalert_send executable diff --git a/gracedb/alerts/xmpp.py b/gracedb/alerts/xmpp.py index cb136a708e6536607c6dda87412b2ad17bd7fcf2..9dac600c0565b16fb3590f3931b5d2e555525074 100644 --- a/gracedb/alerts/xmpp.py +++ b/gracedb/alerts/xmpp.py @@ -13,7 +13,7 @@ from events.permission_utils import is_external from events.query import filter_for_labels from events.shortcuts import is_event from superevents.shortcuts import is_superevent -from .lvalert import send_with_lvalert_overseer, send_with_lvalert_send +from .lvalert import send_with_lvalert_overseer, send_with_lvalert_client # Set up logger logger = logging.getLogger(__name__) @@ -129,11 +129,11 @@ def issue_xmpp_alerts(event_or_superevent, alert_type, serialized_object, "LVAlert Overseer failed, trying lvalert_send")) # If not using LVAlert Overseer or if sending with overseer failed, - # use basic lvalert_send executable (gross) + # use basic lvalert-client send if (not settings.USE_LVALERT_OVERSEER) or (not success): - success, err = send_with_lvalert_send(node_name, msg, server) - - if not success: + try: + send_with_lvalert_client(node_name, msg, server) + except Exception as e: logger.critical(("issue_xmpp_alerts: error sending " - "message with lvalert_send: {e}").format(e=err)) + "message with lvalert client: {e}").format(e=e))