# Monitoring Alarm Changes

Alarm states can be monitored using the Alarm State Changed script.

An alarm can be in four different states:

- Inactive (0): The condition is false, and has been acknowledged.
- Unacknowledged (1): The condition is true, and not acknowledged.
- Acknowledged (2): The condition is true and acknowledged
- Restored (3): The condition is false, and not acknowledged.

Control | Description
--- | ---
Alarms.AlarmsActive | At least one alarm is currently active (its condition is set to true).
Alarms.AlarmsUnacknowledged | At least one alarm has not been acknowledged.
Alarms.Acknowledge(alarmName) | Acknowledges the alarm matching the given name.
Alarms.AcknowledgeAll() | Acknowledges all alarms.

The following script logs the state change:

    public static void AlarmStateChanged(System.DateTime time, string name, string description, string group, int priority, int state, string message)
    {
        //If a new alarm occurs display the new alarm warning (only when the alarm turns on)

        if (state==1)
        {
            $Alarms_NewAlarm = true;
        }

        //Write the new alarm or an alarm reset to the event log (i.e. when an alarm turns on or off, but not an acknowledge event)

        if (state==0 || state==1)
        {
            $Databases.MyData.MyTable.AddRow(DateTime.Now, description + "-->" + message, priority, group);
        }
    }