Query the Alarm History
The History tab of the Alarm Page (or any Alarm List) offers the easiest way to query alarm history with its various filters. Note that you can use the keyboard combination CTRL+C to copy the information from a report (or any alarm list), then paste it into a spreadsheet for further processing.
In custom code, you can build your own alarm lists by using the function GetAlarmList. This is the function used by the Alarm Page and every Alarm List widget.
You can also query historical alarm data using code via the SQL Interface command, "SQLQuery". You may use this function to build SQL statements that can select data directly from the list of active alarms or the alarm history.
Two tables are available for you to query. :Alarms for current alarms and :AlarmHistory for past events. Note the leading colon in both table names.
For example, to query the names and priorities of all active alarms:
SQL_Query = "SELECT Name, Priority FROM :Alarms WHERE Active = 1";
\VTSSQLInterface\SQLQuery(SQL_Query, &Result, &FieldNames, &FieldTypes,
&RetCode, &ErrorMessage);
Upon success, the resulting two-dimensional array will be stored in the variable Result. The size of the first dimension is controlled by the number of fields you query for. The size of the second dimension matches the number of rows returned.
In the event of an unsuccessful query, Invalids will be returned in the SQLQuery parameters.
To retrieve all events associated with the operator Bob on April 10, 2008 :
SQL_Query = Concat("SELECT Timestamp, Name, SubName, Event ",
"FROM :AlarmHistory ",
"WHERE Timestamp >= '2008-04-10 0:00:00' ",
"AND Timestamp < '2008-04-11 0:00:00' ",
"AND Operator = 'Bob'");
\VTSSQLInterface\SQLQuery(SQL_Query, &Result, &FieldNames, &FieldTypes,
&RetCode, &ErrorMessage);
To know when the query has finished, watch for RetCode becoming valid.
Available column names to use in your query include:
Timestamp |
Name |
SubName |
Event |
Message |
Priority |
Type |
HookPointValue |
Area |
HookPointUnits |
Operator |
Alarm Reports - Using the built-in alarm reports
GetAlarmList - VTScada function reference
SQLQuery - VTScada function reference
SQL Queries - Configuration and examples.