How to create a LiveView Table Alert Rule and action from the command-line

How to create a LiveView Table Alert Rule and action from the command-line

book

Article ID: KB0071973

calendar_today

Updated On:

Products Versions
TIBCO Streaming 10.x and later

Description

I would like to create a script for creating a LiveView Alert Rule. This is something I cannot do from the LiveView Web Alert UI.
How can I create an alert rule on a LiveView table from the command-line?

Resolution

To assist with creating alerts and actions, copy the ''lvlistalerts.py" script from the sample project "LiveView REST API sample using Python". The following example steps assume the "Hello LiveView" sample project is running. Load these samples using StreamBase Studio menu:
File > Import Samples and Community Content

The steps are (example):

1. Create the rule
lv-client -u lv://localhost:11080 addalertrule ItemsSales --where "quantityRemaining < 5 limit 10000" --message "Low inventory on item $Item, category $category" --name "Very very low inventory" --owner subuser --alertgroup A.hello

2. Get the alert id
lv-client -u lv://localhost:11080 listrules

3. Add an action
lv-client -u lv://localhost:11080 addalertaction bdfa0db3-2bfd-4ee5-88a0-e4e89e8cd069 --publish

4. Inspect the rule
python lvlistalerts.py -i bdfa0db3-2bfd-4ee5-88a0-e4e89e8cd069
{"status":"OK","description":null,"message":"Low inventory on item $Item, category $category","name":"Very very low inventory",
"severity":null,"quiescence":null,"enabled":true,"owner":"subuser","created":1662582965012,"lastUpdate":1662583122379,
"id":"bdfa0db3-2bfd-4ee5-88a0-e4e89e8cd069","valid":true,"alertGroup":"A.hello","actions":[{"type":"publish_alert",
"type":"publish_alert","description":null,"enabled":true,"fieldSubs":{},"message":null,"key":null,"recipient":" "}],
"trigger":{"query":"select from ItemsSales where quantityRemaining < 5 limit 10000 limit 10000","table":"ItemsSales"}}

The python scripts from the sample access the LiveView Server REST API to inspect and change settings:
  • lvlisttables.py - Lists all tables, or optionally all information about a given table, in the LDM
  • lvsnapquery.py - Performs snapshot queries
  • lvlivequery.py - Performs live queries
  • lvpublish.py - Takes input from the console and publishes it to a table
  • lvlistalerts.py - Lists all alerts, or optionally all information about a given alert
  • lvmanagealerts.py - Create, modify, or delete alerts
The JSON definition for creating a valid alert using 'lvmanagealerts.py' is very particular and it is easier to create the alert some other way and then get the correct JSON definition using 'lvlistalerts.py'.

 

Issue/Introduction

Command line example using lv-client and python