Programmer's Guide
Lucky Vidmar
May 7, 2003
Introduction
The Earthworm Alarms System is intended to satisfy the need for an easy-to-use, web-centered method for dispatching notifications about automatic and reviewed earthquakes. The initial requirements are that the system must support several delivery mechanisms such as email, pager, and QDDS. Furthermore, the user must be able to specify and modify the text of the notification messages. The system must keep an audit of all notifications that were sent, and this audit should be used to ensure that subsequent alarms are sent to the same list of recipients who received the original notification.
This document deals only with the Earthworm Alarms Manager portion with
its source code residing under oracle/apps/src/alarms/web. Refer
to the Earthworm Quick Review documentation for more on how reviewed notifications
are handled and issued.
System Overview
At the center of the system is the Alarms Schema - a set of Oracle DB tables, views, and stored procedures, along with the requisite Earthworm API routines written in C. Please see the attached ERD and the explanation of it in this document.
The schema is accessed from two levels:
Alarms Manager
The Earthworm Alarms Manager is comprised of a series of CGI programs written in C. They support a web interface allowing the "manager" to create or modify recipients, rules, delivery mechanisms, and formats. See System Overview Diagram .
alarms_manager - This is the entry point into the Alarms Manager. It retrieves from the DB the available lists of recipients, criteria programs, and delivery formats, and then puts up three HTML sections allowing the manager to select an existing entry from a list, or chose to insert a new one. Clicking on Submit for each of the three sections (recipients, programs, formats) invokes the appropriate processing program (alarms_process_recipient, alarms_process_prog, alarms_process_format, explained below).
alarms_process_recipient - Invoked by alarms_manager, works in two modes depending on whether it is processing a new or an existing recipient. If it is a new recipient, it puts up an HTML form allowing the manager to define the initial rules for this recipient, specifying magnitude, reviewed status, delivery method and format, as well as the criteria program desired, if any. If an existing recipient is being processed, it retrieves from the DB and then displays the known information about that recipient, and then puts up the HTML form allowing the manager to either modify previously defined rules, or define new ones. The manager can also delete one or more existing rules, or delete the recipient altogether. Clicking Submit or Delete will invoke the alarms_process_new_recipient program.
alarms_process_new_recipient - Works in two modes, depending on whether it was invoked by clicking Delete or Submit from alarms_process_recipient. If in Delete mode, it deletes the recipient and all rules and deliveries associated with the recipient from the database. Otherwise, its task is to collect all available information about a recipient and prepare for insertion into the database. It is called from alarms_process_recipient which passes it all available information about the recipient. It then writes the information into a binary structure (see configuration file for location of that file) which contains all that information so that alarms_insert_recipient can use it. After that, it puts up an HTML form requesting the manager to fill in all the information which is needed to complete the request (new email address, name of the new criteria program, etc.). Clicking Submit invokes alarms_insert_recipient program.
alarms_insert_recipient - First it reads the binary file created by alarms_process_new_recipient which contains all of the information about this recipient known at that point. Then, it processes the web parameters passed in from alarms_process_new_recipient and reconciles them with the structure read from the file. If all goes well up to here, it proceeds to insert all of the information in the structure into the database.
alarms_process_prog - Invoked by alarms_manager, works in two modes depending on whether it is processing a new or an existing criteria program. See below for more information on criteria programs. If it is a new program, it puts up an HTML form allowing the manager to fill in the information about that program. Otherwise, it retrieves from the DB and displays previously defined information allowing the manager to review or modify it. Clicking Submit or Delete calls alarms_insert_prog program.
alarms_insert_prog - Called by alarms_process_prog, works in two ways depending on whether it was invoked by clicking Submit or Delete. If it is in Delete mode, and the criteria program is not used in any rule, it deletes the program from the database. Otherwise, it processes the web parameters passed to it, and calls Earthworm DB API routines to insert the information into the database.
alarms_process_format - Invoked by alarms_manager, works in three modes depending on whether it is processing a new or an existing delivery format, or if a preview of a format is desired. In Preview mode, it displays the existing format showing all valid format tokens in a different color. See below for more information on formats. If it is a new format, it puts up an HTML form allowing the manager to fill in the information about that format. Otherwise, it retrieves from the DB and displays previously defined information allowing the manager to review or modify it. Clicking Submit or Delete calls alarms_insert_format program.
alarms_insert_format - Called by alarms_process_format,
works in two ways depending on whether it was invoked by clicking Submit
or Delete. If it is in Delete mode, and the format is not used in any rule,
it deletes the format from the database. Otherwise, it processes the web
parameters passed to it, and calls Earthworm DB API routines to insert
the information into the database.
Alarms Processor
The basic flow of the Alarms Processor is to retrieve all the rules from the database, determine which ones meet the event?s criteria, and then build and execute the corresponding alarms. Optionally, we would like to allow the user to review and modify the alarm list before it is executed.
DetermineAlarms() - Retrieves the list of all rules from the database. For each rule which passes the magnitude and review flag criteria, the rule?s criteria program, if defined, is executed. See below for more information on criteria programs. If the criteria program returns successfully, a new alarm is inserted into the list of alarms to be executed. After all rules are processed, the list of alarms is sorted by priority and duplicates are eliminated.
ReviewAlarms() - Given a list of alarms, it puts up an HTML form allowing the manager to review the alarms. It returns another alarm list which can be passed to ExecuteAlarms().
ExecuteAlarms() - For each alarm from the alarm list,
produces an Earthworm message of the appropriate type (e.g., TYPE_EMAIL_MSG)
and writes it to the Alarms ring. For each alarm issued, it writes an entry
into the AlarmsAudit table in the database, noting the time of issue. Note
that the Phone delivery mechanism alarms are ignored by ExecuteAlarms.
Currently, the Phone list alarms are processed within the Earthworm Quick
Review system after ExecuteAlarms() is done, by a CGI program which
creates a web form listing all phone numbers which the reviewer should
dial.
Glossary Note - Alarms Formats
The alarms manager allows flexibility in defining and modifying the formats in which alarms messages are delivered. Using the format manager, each format is assigned two message templates: insertion and deletion. The format manager uses a token-based template to allow easy definition of new formats. Each token is bracketed by the ~ character, and each format definition must end with the ~End~ token. The system then replaces each token with the particular value associated with the event which caused the event to be issued:
The following tokens are currently recognized:
Glossary Note - Criteria Programs
It was realized early on that a relational database is not the best platform for storing every imaginable type of alarms rule. However, storing rules in the database is one of the specifications. So, to make life easier for the programmer, we use the notion of a criteria program (CP) which is one attribute of each rule. The basic idea is that a CP is a program written in any language, and invoked by the DetermineAlarms() function. It is passed information about the event and it signals back to the caller whether the event passes some set of criteria defined and checked by the program.
Each CP has three essential elements:
After a CP is executed, DetermineAlarms() needs to figure out whether the CP failed or succeeded. In our simple scheme this is accomplished by reading back the EWEvent structure from the file. If the idEvent value is set to the negative of the original idEvent then the event passed the criteria check. Otherwise, it did not. Therefore, each CP, irrespective of the language, must write the EWEvent structure back to the same file from which it was read, and set the idEvent to the negative of the original if the criteria checks are successful.
Finally, after the EWEvent structure is read back by DetermineAlarms(),
it is removed from the ProgramDir temporary directory.
Alarms Schema Overview
See the attached ERD for a graphical representation of the schema. Following are descriptions of each table and their entries.
AlarmsRecipient - keeps information about a recipient, such as the name, address, etc.
Alarms Delivery Overview
Once ExecuteAlarms() writes an alarm message into the ring, it
is up to another Earthworm module to pick that message up and delivery
the alarm accordingly. Therefore, we need to define a series of new message
types to carry information about alarms, and then to write delivery modules
to process those messages.
Message Types
Alarm message types will be defined as needed.
TYPE_EMAIL_MSG
<email address>
<mail server>
<subject line text>
<database ID of the audit associated with the alarm>
<text of the alarm message>
TYPE_QDDS_MSG
<target directory>
<database ID of the audit associated with the alarm>
<text of the alarm message>
TYPE_CUSTOM_ALARM_MSG
<database ID of the event for which the alarm is raised>
<database ID of the audit associated with the alarm>
<label(description) of the custom mechanism >
<text of the alarm message>
TYPE_PAGER_MSG
*** Format not yet defined ***
Delivery Modules
email_sender - picks up TYPE_EMAIL_MSG messages from the ring, parses them and calls the SendMail() earthworm library routine to delivery the message. Then, it updates the appropriate entry in the AlarmsAudit table to indicate that the message has been delivered.
qdds_sender - picks up TYPE_QDDS_MSG messages from the ring, parses them and writes the text of the message to the specified QDDS target directory. For now, this program only deals with placing the files in CUBE format into the correct directory, leaving the bulk of the delivery work to an outside QDDS-capable process.
Custom_delivery - template of a program that picks up TYPE_CUSTOM_ALARM_MSG message from the ring and processes them according to customized local requirement. This delivery mechanism is intended to provide the unlimited flexibility for sites whose alarm requirements do not corresponds to the features of the Earthworm system.