sleek-lvalert Documentation

sleek-lvalert is a client for the LIGO/Virgo LVAlert pubsub infrastructure that is powered by SleekXMPP. It is compatible with Python 3.

Quick Start

Install with pip:

pip install sleek-lvalert

Put your username and password in your netrc file in ~/.netrc:

echo 'machine lvalert-test.cgca.uwm.edu login albert.einstein password gravity' >> ~/.netrc
chmod 0600 ~/.netrc

Subscribe to some nodes:

lvalert subscribe cbc_gstlal cbc_pycbc cbc_mbtaonline

Listen for LVAlert messages:

lvalert listen

API

class sleek_lvalert.LVAlertClient(username=None, password=None, resource=None, netrc=None, interactive=False, server='lvalert.cgca.uwm.edu')[source]

Bases: sleekxmpp.clientxmpp.ClientXMPP

An XMPP client configured for LVAlert.

Parameters:
  • username (str (optional)) – The XMPP username, or None to look up from the netrc file.
  • password (str (optional)) – The XMPP password, or None to look up from the netrc file.
  • resource (str (optional)) – The XMPP resource ID, or None to generate a random one.
  • netrc (str (optional)) – The netrc file. The default is to consult the NETRC environment variable or use the default path of ~/.netrc.
  • interactive (bool (optional)) – If True, then fall back to asking for the password on the command line if necessary.
  • server (str (optional)) – The LVAlert server hostname.

Example

Here is an example for performing administrative actions.

client = LVAlertClient()
client.connect()
client.process(block=False)
client.subscribe('cbc_gstlal', 'cbc_pycbc')
client.abort()

Here is an example for running a listener.

def process_alert(node, payload):
    if node == 'cbc_gstlal':
        alert = json.loads(payload)
        ...

client = LVAlertClient()
client.listen(process_alert)
client.connect()
client.process(block=True)
get_nodes()[source]

Get a list of all available pubsub nodes.

get_subscriptions()[source]

Get a list of your subscriptions.

listen(callback)[source]

Set a callback to be executed for each pubsub item received.

Parameters:callback (callable) – A function of two arguments: the node and the alert payload.
subscribe(*nodes)[source]

Subscribe to one or more pubsub nodes.

unsubscribe(*nodes)[source]

Unsubscribe from one or more pubsub nodes.

Command Line Interface

usage: lvalert [-h] [-l {critical,error,warning,info,debug}] [-n NETRC]
               [-r RESOURCE] [-s SERVER] [-u USERNAME]
               {listen,subscriptions,nodes,subscribe,unsubscribe} ...

Positional Arguments

action

Possible choices: listen, subscriptions, nodes, subscribe, unsubscribe

sub-command help

Named Arguments

-l, --log

Possible choices: critical, error, warning, info, debug

Log level

Default: “error”

-n, --netrc netrc file (default: read from NETRC environment variable or ~/.netrc)
-r, --resource XMPP resource (default: random)
-s, --server

LVAlert server hostname

Default: “lvalert.cgca.uwm.edu”

-u, --username User name (default: look up in netrc file)

Sub-commands:

listen

Listen for LVAlert messages and print them to stdout.

lvalert listen [-h]

subscriptions

List your subscriptions

lvalert subscriptions [-h]

nodes

List available pubsub nodes

lvalert nodes [-h]

subscribe

Subscribe to one or more nodes

lvalert subscribe [-h] node [node ...]
Positional Arguments
node a pubsub node (e.g. cbc_gstlal)

unsubscribe

Unsubscribe from one or more nodes

lvalert unsubscribe [-h] node [node ...]
Positional Arguments
node a pubsub node (e.g. cbc_gstlal)