Community
Question: How to retrieve the latest alarm text as a string when a new alarm occurs?
Hi everyone,
We are working on a customer requirement where we need to retrieve the latest alarm text as a string whenever a new alarm occurs.
Currently, we are stuck at querying the latest alarm. We have written a query to fetch the most recent alarm text, but it is failing in the CTRL script with an error.
main()
{
//SELECT '_alert_hdl.._text' FROM '*' LAST 1
//SELECT ALERT '_alert_hdl.._text' FROM '*' LAST 1
string query = "SELECT ALERT '_alert_hdl.._text' FROM '*' LAST 1";
dpQueryConnectAll("_AlarmCallback", TRUE, 0, query);
}
void _AlarmCallback(anytype userData, dyn_dyn_anytype res)
{
if (dynlen(res) < 2)
{
return;
}
for (int i = 2; i <= dynlen(res); i++)
{
string dpName = res[i][1];
string state = res[i][2];
// if (state != "CAME")
// continue;
string alarmText;
dpGet(dpName + "._alert_hdl._text", alarmText);
if (alarmText != "")
{
DebugN("Alarm Text"+ alarmText);
}
}
}
Error is following
WCCOActrl (2), 2026.01.09 16:14:45.255, PARAM,SEVERE, 81, Syntax error, Query not successful: dpQueryConnectAll(SELECT ALERT...) not allowed
Any help or guidance would be greatly appreciated.
Thanks in advance.
Dhaval Abotiyawala
Responses (2)
Try it with a dpQueryConnectSingle
Making an alarm query can be quite a big task. The help file does show various examples, but it might be a bit of a search. There's another method that I've used before.
* Use the normal AES screen to display alarms that you'd like to see
* Then activate a '-report query' on the Event manager to see what query it is doing
In general, your script would do a dpQueryCOnectSingle() using the quesy string that you've found via the A&E screen. You'll have to carefully look at the records that you receive. Note that an alarm goes through various state. Example: you'll see an record passing through your callback many times because the record will change in ack state, partner time, visibility etc..
My advises:
Start with a query. Use DebugN() and look at the exact fields that you receive. First learn the alarm mechanism.
The alarm text will be one of the fields in your query results
Note:
When you're alarm text never changes, then you could also do a dpGet() to the get the configured text