IMD SolutionComputing LibraryShop main store

Troubleshooting

Why system.alarm.queryStatus returns months-old alarms

Edge computing and IIoT Published 5 min read By IMD Solution engineering team

Short answer

system.alarm.queryStatus returns months-old cleared and acknowledged alarms because the live status system deliberately retains the most recent instance of every alarm that has ever gone active. Query only state=[0,2] for unacknowledged alarms, handle shelved events in a separate pass filtered by clear time, and rely on the live event limit instead of trying to purge the buffer.

On this page
  1. What the live status system actually retains
  2. What state=[0,1,2] asks for
  3. Isolating shelved events without dragging in history
  4. Sizing the retained set for one line at 250 alarms
  5. Structuring the reset script
  6. Where history belongs
  7. Questions asked

The result is not a fault: the live alarm status system in Ignition keeps the most recent instance of every alarm that has ever gone active, indefinitely. Asking queryStatus for cleared and acknowledged events (state 1) returns exactly that retained set, no matter how old. The fix is to stop querying state 1 for the unacknowledged passes, isolate shelved events in their own pass, and filter that pass by clear time against a memory tag. There is no documented way to purge the whole in-memory buffer, and you should not try.

What the live status system actually retains #

An alarm starts active and unacknowledged, and it stays in the live event system while it is active or unacknowledged. Once it is cleared and acknowledged, it leaves the buffer only when a newer active instance of the same alarm occurs, or when it is no longer the most recent instance of that alarm. The consequence: the most recent instance of every alarm that has gone active stays in memory.

Separately, each alarm holds at most its live event limit of recent events, which defaults to 5. When the limit is reached, the oldest event is pushed out regardless of its state.

So the status system is not a list of current problems, and it is not the journal. It is a snapshot of each alarm's latest event. Your result set grows with the tag count under the display path, not with plant activity — that is the growth you are seeing, and it is normal behavior, not a leak.

Quick check that the system is behaving normally: pick one alarm that cleared and was acknowledged weeks ago, and run queryStatus with state=[1] and a displaypath matching only that alarm. You should get its single most recent event back. If you do, the fix belongs in your filtering, not in the gateway.

What state=[0,1,2] asks for #

The state argument takes integer codes:

  • 0 — cleared, unacknowledged: retained until acknowledged; the alarms the PLC has cleared that still need acknowledging
  • 1 — cleared, acknowledged: retained indefinitely as the alarm's last instance
  • 2 — active, unacknowledged: retained until cleared and acknowledged

Your query covers all three, so it pulls every retained record under the path. Dropping 1 and querying state=[0,2] returns only unacknowledged alarms, which removes the months-old records at the source, because acknowledgement is what makes an event eligible to sit in memory.

For the reset script, that changes the decision:

  • No shelved cleared-and-acknowledged events need handling: use state=[0,2]. This is the simpler configuration and the one to prefer.
  • Shelved, cleared, acknowledged events must also be unshelved: keep state 1, but only in a dedicated shelved pass, post-filtered by time as described below.

Log the result count for both variants against the same display path. The [0,2] count should track what operators see on the status table; the [0,1,2] count will be larger by roughly the number of distinct alarms under that path that have ever fired.

Isolating shelved events without dragging in history #

Shelving hides an alarm from the display but does not change retention, so a shelved alarm stays held until something unshelves it. Use two calls to find them: run the same query once with includeShelved=True and once with includeShelved=False; events that appear only in the first result are the shelved ones. That reduces the state-1 pass from every retained alarm to only the shelved ones.

Then narrow by time. Store the timestamp of the last successful reset in a memory tag, and act only on events whose clear time is later than that timestamp. Anything cleared before the previous reset was already handled, or belongs to an alarm nobody has touched in months.

Finally, keep displaypath as tight as the plant model allows. Your existing tag-value-plus-wildcard pattern scopes to one area; if the PLC reset signal covers a single machine, build the pattern to match only that machine's display paths.

Test: shelve one alarm, cycle it active then cleared, and trigger the reset. The filtered list should contain exactly that event plus any genuinely unacknowledged alarms under the path, and nothing older.

Sizing the retained set for one line at 250 alarms #

Worked example, illustrative inputs except where the limits are documented: a line with 250 distinct alarm definitions under one display path, all of which have fired at least once since startup, and each alarm's live event limit at the documented default of 5.

The rule: with state=[0,1,2], the query returns at least one record per alarm definition that has ever gone active; with state=[0,2], it returns only currently unacknowledged events.

Arithmetic: the [0,1,2] query returns at least 250 records, and grows as new alarm definitions are added, since acknowledgement never removes a record from the retained set. The [0,2] query returns only the alarms unacknowledged at query time — for example 3 in a quiet hour — a reduction of 247 records, about 99 percent of the set.

Result: the state filter, not a purge, is what bounds the working set.

Decision: use state=[0,2] for the acknowledgement pass; run the state-1 pass only when shelved events need unshelving, scoped to includeShelved=True results and clear times after the last-reset memory tag. Above a few hundred alarm definitions on one path, keep the displaypath per machine rather than per line.

Structuring the reset script #

Trigger on the PLC reset tag, and act on the rising transition only, so a value that stays set does not re-run the query on every change event:

# Tag change script on the PLC reset tag, 0 -> 1 only
pattern = [tag[0].value + '*']

# Pass 1: everything still unacknowledged (history-free)
open_events = system.alarm.queryStatus(state = [0, 2],
    displaypath = pattern, includeShelved = True)
# acknowledge these

# Pass 2: shelved events only, recent clear times only
all_shelved = system.alarm.queryStatus(state = [0, 1, 2],
    displaypath = pattern, includeShelved = True)
non_shelved = system.alarm.queryStatus(state = [0, 1, 2],
    displaypath = pattern, includeShelved = False)
shelved_only = [e for e in all_shelved if e not in non_shelved]
recent = [e for e in shelved_only
    if e.getClearedTime() > lastResetTime]
# unshelve these, then acknowledge them

The getClearedTime and comparison are illustrative of the pattern; confirm the exact event property names for your Ignition version in the scripting reference for system.alarm, which documents acknowledge, unshelve and the related calls. Update the last-reset memory tag only after both passes succeed, so a failed run is retried on the next transition.

Where history belongs #

If old events are showing up in calculations, reports or KPIs, those consumers are reading live status where they should read history. The SQL-backed alarm journal you already have is the historical record; point report queries at it and filter on event time there. The live status system needs no purging once every consumer uses the right source — and the same discipline applies when you expose only approved Ignition tags to an external historian, or when you investigate why Ignition alarm journal logs every alarm twice. On the gateway side, raising the live event limit increases memory use on frequently active alarms, so leave it at the default 5 unless a specific alarm loses records you actually need.

Questions asked

Can a script clear the entire live alarm buffer at once?

No. Alarm events live in gateway memory, and there is no documented bulk-clear function for the live status system. The only ways an old record leaves are a newer active instance of the same alarm, losing its place as the most recent instance, or being pushed out when the alarm's live event limit, which defaults to 5, is reached. Reports and KPIs that need history should read the SQL-backed alarm journal instead.

Does the live event limit stop the buffer from growing?

It caps records per alarm, not total buffer size. The default live event limit is 5, so one alarm never holds more than 5 live events regardless of how often it fires. But every distinct alarm that has ever gone active retains at least one record, so total memory grows with the number of alarm definitions, not with plant activity. Raising the limit also increases memory use on frequently active alarms.

Does shelving an alarm change how long it is retained?

No. Shelving only hides an alarm from the status display; the retention rules are unchanged. A shelved alarm that has cleared and been acknowledged still holds its record until it is unshelved, which is why the reset script needs a separate shelved-only pass with includeShelved set to True.

Why do reports and KPIs show months-old alarms?

They are reading live status instead of history. The live status system is a snapshot of the most recent instance of each alarm, while the SQL-backed alarm journal is the historical record. Point report and calculation queries at the journal tables, and filter on event time there, rather than filtering live status results.

Keep reading

  • Troubleshooting

    Fix Ignition custom historian aggregates that return zeros

    A zero-filled result from an Ignition custom historian aggregate means the callback failed, not that every stored value was zero. The Gateway log names the cause: NameError: global name 'shared' is not defined, raised in pyaggimpl. Select the project that contains your aggregate's script library as the Gateway Scripting Project, publish it, and rerun the query.

    Edge computing and IIoT

  • Troubleshooting

    Stop duplicate InTouch alarms in Historian on TSE

    Every TSE session runs a full InTouch instance, and each one submits its own alarm and event records to Historian, so one transition lands once per session. $HistoricalLogging = false stops value historization only. Split the project: a server application that owns alarm generation and all Historian logging, and client applications with neither, with every alarm display reading the server's provider.

    Edge computing and IIoT

  • Troubleshooting

    Why MQTT Engine still feeds old tags after a broker stops

    Old values keep reaching the screens because MQTT Engine buffers and processes each Edge node's messages in order, so a birth-message flood drains through the tags even after the broker is stopped. Measure the queue with Enable Latency Check and Message Processing Latency, fix the flooding node first, and restart the module only to clear what the fixed cause already built.

    Edge computing and IIoT

Ignition database user source SQL Server permissions