The alarms module manages alarms on the gateway: alarm definitions (templates), alarm instances (raised alarms) and their lifecycle (raise, acknowledge, resolve, reopen, delete). Use it to raise alarms from a script or an integration, to acknowledge them remotely, or to feed a third-party supervision. For the concepts and the delivery channels (e-mail, SMS, push, WhatsApp), see Alarms and notifications.
It is loaded with:
peer('supervision').require('alarms', function(err, alarms){
// ... alarms.<method>(...)
})
Every method follows the standard Node.js convention: the last argument is a callback(err, result). Errors are short strings such as 'not found' or 'missing alarmId'.
There is no alarm screen in the gateway interface yet: alarms are managed through this API (peers, or REST with
/peers/supervision/alarms/<method>, see REST: calling peer methods).
One definition can have several alarms at the same time, one per target and consumer. consumer is a free label (default 'default') that lets two applications raise the same alarm independently.
| Status | Meaning |
|---|---|
active |
Raised, not acknowledged, not resolved |
acknowledged |
Someone has seen it; the cause may still be present |
resolved |
The cause is gone. A resolved alarm can also be acknowledged afterwards: it stays resolved and gets acknowledgedTs. |
An alarm is removed from the list when the retention time of its current status has elapsed (expired), or when it is deleted. The gateway checks expirations every minute.
The mode of a definition sets default values. A value written in the definition always wins.
| Mode | Acknowledge | Resolve | Retention |
|---|---|---|---|
alarm |
Yes | Yes | Resolved alarms are kept 7 days (onResolvedTTL) |
alarmSimple |
Yes | No | Acknowledged alarms are kept 24 h (onAcknowledgeTTL) |
journal |
No | No | Kept 24 h after creation (onCreateTTL) — a log entry, not an alarm to handle |
Without
modeand without retention times, alarms are never removed automatically: they stay in the list until you delete them. Always set amode, or the TTL fields.
| Field | Default | Description |
|---|---|---|
id |
— (required) | Unique identifier, a string. __system__ is reserved (see 6.2). |
type |
— | Free category, copied to each alarm ('custom' when missing) |
severity |
— | critical, warning, info or debug. Alarms without severity get warning. |
description |
— | Text. Used as alarm message when raiseAlarm gives none. |
mode |
— | alarm, alarmSimple or journal (see 1.3) |
hasAcknowledge |
true |
The alarms can be acknowledged |
hasResolve |
true |
The alarms can be resolved |
persist |
true |
The alarms survive a restart of the gateway (see 7) |
onCreateTTL |
from mode |
Retention of an active alarm, in ms |
onAcknowledgeTTL |
from mode |
Retention of an acknowledged alarm, in ms |
onResolvedTTL |
from mode |
Retention of a resolved alarm, in ms |
cooldownMs |
— | After an alarm is resolved, raising it again for the same target and consumer is refused during this time, in ms |
maxInstances |
— | Maximum number of unresolved alarms of this definition at the same time |
params |
{} |
Automatic triggering and notifications (see 2.2 and 2.3) |
A definition with empty params is passive: its alarms are raised and resolved by your code with raiseAlarm and resolveAlarm.
params.thresholdA threshold definition watches one address and handles its alarm by itself:
params: {
threshold: { address: 'room1Temp', op: '>', value: 28, message: 'Room 1 too hot' }
}
| Field | Default | Description |
|---|---|---|
address |
— (required) | Address key, as in the newValue <key> event of gateways: address id, name, or <gateway name or id>¬<name>. An alias works only when the Alias view is started on the gateway. |
op |
> |
>, >=, <, <=, == or != |
value |
— (required) | Threshold, a number |
message |
<address> <op> <value> |
Alarm message. The current value is appended: Room 1 too hot (= 28.6). |
When a new value matches the condition, an alarm is raised with the address as target. When a later value no longer matches, the alarm is resolved automatically (resolvedBy is '__auto__'). Values that are not numbers are ignored. Use a mode where resolving is allowed (alarm, or no mode): with alarmSimple or journal, the alarm is never resolved automatically.
params.onEventonEvent writes a value to an address when something happens to an alarm of the definition: send an SMS through an SMS gateway, switch on a lamp, set a KNX object…
params: {
onEvent: {
raised: { address: 'alarmLamp', value: 1 },
resolved: [
{ address: 'alarmLamp', value: 0 },
{ address: 'maintenanceLog' } // no value: a JSON summary of the event is written
]
}
}
raised, acknowledged, unacknowledged, resolved, reopened, updated, expired, deleted.{ address, value }, or an array of such objects. address is an address key (as in gateways.writeValue), or an array of address keys.value, the gateway writes a JSON text: {"event":"raised","alarm":{"id":…,"definitionId":…,"targetId":…,"status":…,"severity":…,"message":…}}.| Method | Description |
|---|---|
getDefinitions(callback) |
All definitions, as an object keyed by id. Contains the reserved __system__ definition. |
getDefinition(definitionId, callback) |
One definition. Error 'not found'. |
insertDefinition(definition, callback) |
Create a definition. Fails if the id exists (definition already exists: <id>). |
updateDefinition(definition, callback) |
Replace an existing definition. Fails if the id does not exist (definition not found: <id>). |
replaceDefinition(definition, callback) |
Replace the definition, or create it if it does not exist |
deleteDefinition(definitionId, callback) |
Delete the definition and all its alarms (each one emits alarmDeleted). Error 'not found'. |
updateDefinitionandreplaceDefinitiondo not merge: fields you leave out are lost (unlikegateways.updateAddress). Read the definition withgetDefinition, change it, and send it back complete.
The callback receives the stored definition, with the defaults of its mode applied.
getAlarms([filter], callback)Returns an array of alarms. Without filter, all alarms in memory. Every key of the filter must match:
| Filter key | Description |
|---|---|
status |
'active', 'acknowledged' or 'resolved' |
excludeResolved |
true: every alarm that is not resolved (active and acknowledged) |
definitionId |
Alarms of one definition |
targetId |
Alarms of one target |
consumer |
Alarms of one consumer |
type |
Alarms of one type |
severity |
Exact severity |
minSeverity |
This severity or higher (critical > warning > info > debug) |
To list the alarms still to handle, use { excludeResolved: true }: { status: 'active' } leaves out the acknowledged alarms whose cause is still present.
getAlarmsreturns the alarms still kept by the gateway, not a full history: an alarm disappears when its retention time elapses or when it is deleted. To keep a permanent record, listen to the events (section 5) and store them on your side.
getAlarm(alarmId, callback)One alarm, by its alarm id (the id returned by raiseAlarm or getAlarms), not by its definition id. Accepts '<alarmId>' or { alarmId }. Error 'not found'.
| Field | Description |
|---|---|
id |
Alarm id, generated by the gateway (a short string) |
definitionId |
Definition of the alarm |
targetId |
Target. Defaults to the definition id. |
consumer |
Consumer, 'default' when not given |
status |
active, acknowledged or resolved |
type, severity, message |
From raiseAlarm, else from the definition |
createdTs |
Raise time, in ms |
acknowledgedTs, acknowledgedBy |
Acknowledge time (ms) and user, or null |
resolvedTs, resolvedBy |
Resolve time (ms) and user ('__auto__' for an automatic resolve), or null |
reopenedTs |
Time of the last reopenAlarm, when reopened |
persist, hasAcknowledge, hasResolve, onCreateTTL, onAcknowledgeTTL, onResolvedTTL |
Copied from the definition when the alarm was raised |
| other fields | Any extra field passed to raiseAlarm (for example data) |
raiseAlarm(options, callback)| Option | Default | Description |
|---|---|---|
definitionId |
— (required) | An existing definition |
targetId |
definition id | Target of the alarm |
consumer |
'default' |
Consumer |
message |
definition description |
Alarm text |
severity |
definition severity, else warning |
Severity of this alarm |
| other fields | — | Copied to the alarm (for example data: { value: 28.6 }). They cannot overwrite the fields of section 3.3. |
Deduplication: there is at most one unresolved alarm per definition, target and consumer. If one exists, raiseAlarm returns it unchanged and raises nothing new.
The call fails with 'definition not found or guard triggered' when:
cooldownMs and the same alarm was resolved less than cooldownMs ago;suppressForMs and the delay is not over (see 4.4);maxInstances unresolved alarms.A raise refused by a guard leaves a trace under the reserved __system__ definition (see 6.2).
These methods accept '<alarmId>' or { alarmId, user }. user is stored in acknowledgedBy / resolvedBy. The callback receives the updated alarm.
| Method | Description | Error when refused |
|---|---|---|
acknowledgeAlarm(options, callback) |
Acknowledge. Allowed once per alarm, and only if the definition allows acknowledging. { alarmId, user, resolve: true } acknowledges and resolves in one call. |
'not found or not acknowledgeable' |
unacknowledgeAlarm(options, callback) |
Remove the acknowledgment; an acknowledged alarm goes back to active |
'not found or not in acknowledged state' |
resolveAlarm(options, callback) |
Resolve. Only if the definition allows resolving and the alarm is not already resolved. Starts the cooldownMs delay. |
'not found or not resolvable' |
reopenAlarm(options, callback) |
Set a resolved alarm back to active; acknowledgment and resolution are cleared |
'not found or not reopenable' |
A reopened threshold alarm is resolved again automatically when a new value no longer matches the condition.
updateAlarm(options, callback){ alarmId, ...fields } changes free fields of an alarm, typically message, severity or data. The protected fields are ignored without error: id, definitionId, targetId, status, createdTs, the acknowledge and resolve fields, persist, hasAcknowledge, hasResolve and the TTL fields. Change the status with the methods of 4.2.
deleteAlarm(options, callback)Removes an alarm, whatever its status. Accepts '<alarmId>' or { alarmId, suppressForMs }. With suppressForMs, raising the same alarm (same definition, target and consumer) again is refused during that time, in ms — useful when you clear alarms that would otherwise come back at once. Error 'not found'.
Listen on the module object (see Peers protocol, section 5):
peer('supervision').require('alarms', function(err, alarms){
function onRaised(alarm){ console.log('ALARM', alarm.severity, alarm.targetId, alarm.message) }
alarms.on('alarmRaised', onRaised)
// when you no longer need it:
// alarms.removeListener('alarmRaised', onRaised)
})
| Event | Arguments | Emitted when |
|---|---|---|
alarmRaised |
(alarm) |
An alarm is raised |
alarmAcknowledged |
(alarm) |
An alarm is acknowledged |
alarmUnacknowledged |
(alarm) |
An acknowledgment is removed |
alarmResolved |
(alarm) |
An alarm is resolved (manually or automatically) |
alarmReopened |
(alarm) |
A resolved alarm is reopened |
alarmUpdated |
(alarm, oldFields) |
updateAlarm changed fields; oldFields holds their previous values |
alarmExpired |
(alarm) |
An alarm is removed because its retention time elapsed |
alarmDeleted |
(alarm) |
An alarm is deleted (deleteAlarm, or its definition is deleted) |
alarmDefinitionInserted |
(definition) |
A definition is created |
alarmDefinitionUpdated |
(definition, oldDefinition) |
A definition is replaced |
alarmDefinitionDeleted |
(definition) |
A definition is deleted |
Each method is a separate right in the role of the account: supervision › alarms › <method> (see Users & access). Give an operator account only the methods it needs, for example getAlarms, acknowledgeAlarm and resolveAlarm, and keep insertDefinition, deleteDefinition and deleteAlarm for integrators.
__system__ definition__system__ is built in. It cannot be created, replaced or deleted. The gateway uses it as a journal (mode journal, not persistent, kept 24 h) for its own messages about the alarm engine: refused raises (cooldown, maxInstances, deletion delay), save errors, failed definition start. Leave it out of the lists you show to users, for example by filtering out definitionId === '__system__', and read it with getAlarms({ definitionId: '__system__' }) when a raise does not work as expected.
persist: true (the default) are written to alarms_instances.log in the data folder at each change, and reloaded when the supervision restarts. Alarms with persist: false are lost at restart.cooldownMs and suppressForMs delays are kept in memory: they start again from zero after a restart.
peer('supervision').require('alarms', function(err, alarms){
alarms.insertDefinition({
id: 'room1Hot',
mode: 'alarm',
severity: 'warning',
description: 'Room 1 temperature',
cooldownMs: 600000, // no new alarm within 10 min after a resolve
params: {
threshold: { address: 'room1Temp', op: '>', value: 28, message: 'Room 1 too hot' },
onEvent: {
raised: { address: 'alarmLamp', value: 1 },
resolved: { address: 'alarmLamp', value: 0 }
}
}
}, function(err, def){
if(err) return console.error(err)
console.log('definition created', def.id)
})
})
peer('supervision').require('alarms', function(err, alarms){
alarms.insertDefinition({ id: 'pumpFault', mode: 'alarm', severity: 'critical' }, function(err){
// err 'definition already exists: pumpFault' is fine on the second run
alarms.raiseAlarm({
definitionId: 'pumpFault',
targetId: 'pump2',
message: 'Pump 2: no flow',
data: { flow: 0 }
}, function(err, alarm){
if(err) return console.error(err)
// later, from the operator side:
alarms.acknowledgeAlarm({ alarmId: alarm.id, user: 'operator' }, function(err){
// when the pump runs again:
alarms.resolveAlarm({ alarmId: alarm.id, user: 'operator' }, function(err, a){
console.log(a.status) // 'resolved'
})
})
})
})
})
alarms.getAlarms({ excludeResolved: true, minSeverity: 'warning' }, function(err, list){
list.filter(function(a){ return a.definitionId !== '__system__' })
.sort(function(a, b){ return b.createdTs - a.createdTs })
.forEach(function(a){ console.log(a.status, a.severity, a.targetId, a.message) })
})
Over REST:
curl -b cookies.txt -X POST \
-H 'Content-Type: application/json' \
-d '{"args":[{"excludeResolved":true}]}' \
'https://gateway.example.com/peers/supervision/alarms/getAlarms'
| Symptom | Cause | What to do |
|---|---|---|
raiseAlarm answers definition not found or guard triggered |
Unknown definition, or cooldownMs, deletion delay or maxInstances |
Check the id with getDefinition; read getAlarms({ definitionId: '__system__' }) for the reason |
raiseAlarm returns an old alarm |
Deduplication: an unresolved alarm already exists for this definition, target and consumer | Resolve it first, or use another targetId |
getAlarm answers not found |
A definition id was given instead of the alarm id | Use the id of the alarm, or getAlarms({ definitionId }) |
resolveAlarm answers not found or not resolvable |
Already resolved, or the definition does not allow resolving (alarmSimple, journal, hasResolve: false) |
Check status and hasResolve of the alarm |
A field is lost after updateDefinition |
The definition is replaced, not merged | Send the complete definition |
updateAlarm does not change status |
status is protected |
Use acknowledgeAlarm, resolveAlarm or reopenAlarm |
| Alarms pile up and never disappear | No mode and no TTL on the definition |
Set a mode or the TTL fields |
| A threshold alarm never fires | Address key not matched, or non-numeric values | Use the address id or <gateway>¬<name>; check the value in the address table |
require, events, serialization.writeValue, newValue events.