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 ContentThe steps are (example):
1. Create the rulelv-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.hello2. Get the alert idlv-client -u lv://localhost:11080 listrules3. Add an actionlv-client -u lv://localhost:11080 addalertaction bdfa0db3-2bfd-4ee5-88a0-e4e89e8cd069 --publish4. Inspect the rulepython 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'.