======================================== LiveView Advanced Alerting Sample ======================================== This is a project for TIBCO LiveView that configures a server instance with sample alert rules that demonstrate advanced configuration of alerting in LiveView. The ItemsSales data table and its data source application can be reviewed by referring to the Hello LiveView sample. This sample includes: - Preconfigured alert rules, stored in the project's src/main/resources/LiveView.h2.db store. - LVAlerts table -- this table is defined in LVAlerts.lvconf, and configures extensions (additional fields) for the default alert table. All LiveView servers automatically instantiate a default alert table of this name. Users may create like-named table in order to control configuration of the project's alert table. The customization in this sample uses these features: - Table-level to modify field values - Adding extra fields (category, maxSeveritySeen, alertCount, setClear) - Customizing the primary key definition (removing AlertRuleGUID which is the default primary key) Refer to comments in src/main/liveview/LVAlerts.lvconf file for a full explanation of the customizations. You can open it by right-clicking and selecting the XML editor, in order to see the comments. The alert rules in this sample use advanced settings in Publish Alert action configurations, which work in concert with a customized LVAlerts table to achieve having only one unique alert row for each unique item transactionID. This sample thus demonstrates a particular style of alerting, where only the latest alert is retained in view for some unique key configured in each alert rule. (Contrast this with default alerting configurations that record alert rows as a log would, with new rows published for each action.) Additionally, there is a configured CustomAlertTupleReceiver application that demonstrates how the Send Tuple alert action can be easily used to exploit the benefits of StreamBase EventFlow logic. The application alertreceiver.sbapp demonstrates how alerts can be sent to the server log and three different publish adapters. There are three configured alert rules that send tuples to these three publish adapters. The adapters themselves are disabled in the alertreceiver.sbapp EventFlow module, since each needs some local configuration to be able to publish. To enable an adapter, right-click the adapter and select "Enable Component." There are some configuration notes in the application, but for more details read the StreamBase documentation on each adapter and reference the StreamBase samples for each adapter. To run this sample in Studio, you can: - In the LiveView Project Viewer, click the green Run button in the upper right. - Right-click any of the lvconf table configuration files in the Project Explorer view and select Run As > Run Configurations > Run (in the invoked Run Configurations dialog). - Right-click the project folder itself, and select Run As > LiveView Fragment Remember that starting a LiveView project can take one to three minutes, depending on the speed of your computer, the amount of memory available for Java processes, and other factors. Once the sample is running, you can view and configure alert rules from a browser connecting to localhost:10080. Click on the "bell" on the top right hand side of the browser. The alert rules pre-configured in this sample are: - "Ran out of item" This alert rule is configured against the base data table ItemSales, such that whenever an item's quantity is zero, the server publishes an alert row, or updates a pre-existing alert row, for this item. This alert rule also has an "Execute OS Command" and "Execute Java Command" actions. The OS action calls RanOutOfItem.bat (and is thus suitable only for execution on Windows), passing it arguments from the alert. This action writes out to a file (\tmp\outofitems.log). You can change the file location by changing the third parameter to the command. The Java action executes the class com.tibco.ldm.sample.DemoForExecJava which can be found in src/main/java. This class will create a file \tmp\TextFileGenerationForTestingAlerts_For_%s_%d, where the first param has the Item name substituted in and the second param has an incrementing number substituted in. You can change the location of the file by changing the pathName parameter in the ExecJava configuration dialog. Note that both OS and Java commands are run in the context of the LiveView server process. They are both potentially high security risks and care should be exercised in who is permitted to configure these actions. To that end, note that by default both OS and Java Exec are disabled by default and must be individually enabled by setting the system properties found in the engine.conf file. If auth is enabled, there are individual permissions available for individual actions. - "Item selling price too low" Alert rule configured against ItemSales, watching for a lastSoldPrice under fifteen, that remained this way for six seconds. Publishes an alert row, or updates a pre-existing alert row, for this item. - "Item selling price too low Clear" Alert rule configured against ItemSales, watching for a lastSoldPrice under fifteen. Immediately publishes an alert row, or updates a pre-existing alert row, for this item. - Note that the alerts above are also using a "Send Tuple" action, which forwards data from the alert to the CustomAlertTupleReceiver application (which is defined in the StreamBase module file CustomAlertTupleReceiver/alertreceiver.sbapp). - "Twitter - back in stock" When an item was out of stock and then becomes available again, a tweet is sent to indicate new availability. - "EMS - out of item" When an item quantity hits zero, an EMS message is published with all of the item's details. - "Tibrv - price too low" When the selling price of an items drops below a threshold, a Rendezvous message is published with all of the item's details. - "Trimming ItemsSales table to 4 minutes" This alert keeps the table from getting too large. There are few tips to take in from this alert. First, in the Publish Alert action, it has a static value for the Alert Key. This means that there will only ever be one row in the LVAlerts table from this alert. Each time it publishes, it will replace the existing row. Next, to keep from running constantly, it uses a time-windowed condition, looking for any item that is older than 5 minutes. When it sees any, it performs a delete operation, deleting all items older than 4 minutes. This allows the alert to run only once a minute rather than trying to run as each item ages off. Finally, it has set "After executing actions, suppress subsequent execution for ..." In a system where items were flooding in, you typically would see many items hitting the more-than- 5-minute window in the time it takes the delete operation to run, so the alert would needlessly run many times. This setting prevents that. - "Hot Item" An aggregate-based alert to find items that have had more than 7 transactions in the last minute. The Java action executes the class com.tibco.ldm.sample.Spotfire which can be found in src/main/java. This class will post a job XML to the specified Spotfire server where the first require parameter is your Spotfire automation-service-rest-api "clientID"; the second require parameter is your "clientSecret"; the third require parameter is the "jobXML" you want to post and the fourth require parameter is your Spotfire server "URL". Information for registering clientID and clientSecret on your Spotfire server can be found on https://community.tibco.com/wiki/rest-api-execute-tibco-spotfirer-automation-services-jobs and job XML can be created using Spotfire Analyst application. - "Hot Item has low inventory" An advanced aggregate-based alert. This sample demonstrates how you can have a complete aggregate projection, defining several fields that can be used in the message and/or the index. The technique is to include a Boolean field named (exactly) LVAlertTestExpression. This is the field that the alert processor will test, looking for a transition from false to true. However, by defining the entire projection, there are now other fields that can be used in the message. - "Regular Inventory Check" A time-based alert that fires up periodically based on the cron string, in this instance, every 1 minute reminding to perform a visual check of available inventory and ensure information displayed is accurate. - "Disable Regular Inventory Check" A query-based alert that contains two actions: Publish Alert and Invoke HTTP. Once this alert is triggered after 10 or more alerts have been published to the LiveView Alerts table, it publishes the given message to LiveView Alerts table and sends an HTTP PATCH request that disables the "Regular Inventory Check" alert. To run this sample from the command line outside of Studio, you must: - Package this sample's LiveView fragment project into a fragment archive. - Create a separate StreamBase Application project, and set the pom.xml for that project to depend on the fragment archive created in the previous step. - Create a separate StreamBase Application archive file. - Install that archive into a StreamBase Runtime node. - Start the node. These steps are described in more detail in the "Deploy with epadmin" page of the Concepts Overview in the StreamBase documentation. This sample includes: engine.conf - a LiveView configuration file to set up JVM arguments for this sample.