While the server is running, query:
lv-client "select * from LVAlerts"
lv-client "select * from LVAlertRulesStatus"
and confirm each of these appears correct and is in agreement.
When the server is stopped you may extract the alert definition from the server configuration database. This database contains Alert definitions, LiveView Desktop workspaces, and other cached runtime configuration.
To extract the project database, use command:
lv-db -e -p <projectdir> >lv_db.txt
where the
<projectdir> value is a relative or absolute path to the top LiveView project folder.
Find the section in "lv_db.txt" which looks like this:
Exporting table Alerts
1,'campbell','<?xml version="1.0" encoding="UTF-8" standalone="yes"?><request><set-alert-rule><alert-rule
name="Trim Items table" severity="3" enabled="true" owner="campbell" created="2014-01-26T13:33:14.202-05:00"
last-updated="2014-01-31T12:00:35.735-05:00" id="1" status="valid"><status-message>OK</status-message>
<alert-query-config table="ItemsSales" query-type="SNAPSHOT_AND_CONTINUOUS" predicate-delay-in-millis="0">
<predicate>true when transactionTime between BEGIN and now()-minutes(2)</predicate></alert-query-config>
<message-template>Trimming Items table to 1 minute</message-template><version version-number="1"
version-string="LiveView 1.2"/><actions><action enabled="true"><publish-alert alert-recipient="*"/></action>
<action enabled="true"><delete-alert><table>ItemsSales</table><delete-predicate>transactionTime <
now()-minutes(1)</delete-predicate></delete-alert></action></actions></alert-rule></set-alert-rule>
</request>'
This is one of the rules from our "sample_lv-helloliveview" project.
The "Exporting table Alerts" section will be followed by these sections which may be ignored for the purpose of examining alerts: "Exporting table Workspace", "Exporting table NameValue", "Exporting table SystemInfo", and "Exporting table Queries".
The parts of the XML definition of the Alert Rule are:
A. Header1, - the ID number of the rule
'campbell', - the user who created the rule
B: Rule definition 1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2. <request>
3. <set-alert-rule>
4. <alert-rule name="Trim Items table" severity="3" enabled="true" owner="campbell" created="2014-01-26T13:33:14.202-05:00" last-updated="2014-01-31T12:00:35.735-05:00" id="1" status="valid">
5. <status-message>OK</status-message>
6. <alert-query-config table="ItemsSales" query-type="SNAPSHOT_AND_CONTINUOUS" predicate-delay-in-millis="0">
7. <predicate>true when transactionTime between BEGIN and now()-minutes(2)
8. </predicate>
9. </alert-query-config>
10. <message-template>Trimming Items table to 1 minute</message-template>
11. <version version-number="1" version-string="LiveView 1.2"/>
12. <actions>
13. <action enabled="true">
14. <publish-alert alert-recipient="*"/>
15. </action>
16. <action enabled="true">
17. <delete-alert>
18. <table>ItemsSales</table>
19. <delete-predicate>transactionTime < now()-minutes(1)
20. </delete-predicate>
21. </delete-alert>
22. </action>
23. </actions>
24. </alert-rule>
25. </set-alert-rule>
26. </request>
Explaination:Line 1-3: Wrapper
Line 4: Name and attributes. The "enabled" value determines if the rule query runs. The "id" should match the first value in the record Header. The "status" value indicates whether the definition of the alert rule has the minimum settings defined for the rule type.
Line 5: The value reported in the Status column of the LVAlertRulesStatus row for this rule.
Line 6: Query attributes.
Line 7. Criteria controlling when the alert rule triggers.
Line 8-9: Closing the Query definition.
Line 10: The message reported when this alert rule triggers.
Line 11: Version control information.
Line 12: Beginning of the actions definition describing what happens when the alert triggers.
Line 13,16: Whether the defined action will happen when the alert triggers, or not.
Line 14: A "publish" type of alert with attributes.
Line 15: Closing the Action definition.
Line 17: A "delete" type action.
Line 18-21: Query configuration for a delete-query.
Line 22-26: Closing the actions, rule definitions, and the Wrapper.
Debugging
To see why an alert rule is not firing:
1. Check the "enabled" values which should all be "true".
2. Check the <predicate> and <delete-predicate> expressions and test these using a simple "select" query to verify there is data in the table that allows each expression to return one or more rows.
For example, to delete old rows using the above rule, both these queries must return rows when the server is running:
a) lv-client "select * from ItemsSales where true when transactionTime between BEGIN and now()-minutes(2)"
b) lv-client "select * from ItemsSales where transactionTime < now()-minutes(1)"