# Alarming from within a module

**URL:** <https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748>\
**Category:** Module Development\
**Created:** [October 8, 2021, 12:57pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748 "2021-10-08T12:57:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtdfan](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@jtdfan](https://forum.inductiveautomation.com/u/jtdfan)\
**Post date:** [October 8, 2021, 12:57pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/1 "2021-10-08T12:57:44Z")

</div>

I am needing to create alarms via multiple modules that we are developing for our Ignition projects. Thus far, I have been able to add a journal entry to the Alarm Journal from the module’s Gateway Context and the alarm reports back in the module that it is Active, Unacknowledged. However, that alarm doesn’t show up as a System alarm in the Alarm Journal or the System’s Gateway alarm tags.

What am I missing?

1. Get GatewayContext.getAlarmJournal
2. Create AlarmEvent and EventData
3. Call AlarmEvent.active(EventData)
4. Call AlarmJournal.storeEvent(AlarmEvent)

I may have messed up some of the PseudoCode, but any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [October 8, 2021, 1:06pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/2 "2021-10-08T13:06:05Z")

</div>

welh the pseudocode is kinda lacking to help xd  
store event also requires transition state, maybe thats why idk. you’ll have to show some more code

---

<div class="post-metadata">

**Author:** ![jtdfan](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@jtdfan](https://forum.inductiveautomation.com/u/jtdfan)\
**Post date:** [October 8, 2021, 1:10pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/3 "2021-10-08T13:10:44Z")

</div>

I found the code once I got in the office

```auto
public void raiseAlarm(String displayPath, AlarmPriority alarmPriority, AlarmStateTransition alarmStateTransition, String eventMessage, Integer eventValue) {
        try {
            var addr = InetAddress.getLocalHost();
            String hostname = addr.getHostName();

            QualifiedPath.Builder qualifiedPathBuilder = new QualifiedPath.Builder();
            qualifiedPathBuilder.setAlarm("ATOM Alarm");
            qualifiedPathBuilder.setEvent(eventMessage);
            qualifiedPathBuilder.setMachine(hostname);
            qualifiedPathBuilder.setProvider("LIFT");
            qualifiedPathBuilder.setSource("Dematic ATOM Module");
            qualifiedPathBuilder.setUser("ATOM");
            QualifiedPath qualifiedPath = qualifiedPathBuilder.build();

            AlarmJournalManager journalManager = gatewayContext.getAlarmManager().getJournalManager();
            BasicAlarmEvent alarmEvent = new BasicAlarmEvent(qualifiedPath, displayPath, alarmPriority);
            DateTime alarmDate = DateTime.now();
            BasicPropertySet basicPropertySet = new BasicPropertySet();
            basicPropertySet.set(CommonAlarmProperties.EventState, alarmStateTransition);
            basicPropertySet.set(CommonAlarmProperties.EventValue, eventValue);
            basicPropertySet.set(CommonAlarmProperties.Priority, alarmPriority);
            basicPropertySet.set(CommonAlarmProperties.Label, eventMessage);
            switch (alarmStateTransition) {
                case Ack:
                    basicPropertySet.set(CommonAlarmProperties.AckUserName, "ATOM");
                    basicPropertySet.set(CommonAlarmProperties.AckTime, alarmDate.toDate());
                    basicPropertySet.set(CommonAlarmProperties.IsAcked, true);
                    alarmEvent.acknowledge(new EventData(basicPropertySet));
                case Active:
                    basicPropertySet.set(CommonAlarmProperties.ActiveTime, alarmDate.toDate());
                    basicPropertySet.set(CommonAlarmProperties.IsActive, true);
                    alarmEvent.active(new EventData(basicPropertySet));
                    break;
                case Clear:
                    basicPropertySet.set(CommonAlarmProperties.ClearTime, alarmDate.toDate());
                    basicPropertySet.set(CommonAlarmProperties.IsClear, true);
                    alarmEvent.clear(new EventData(basicPropertySet));
                    break;
                case Finished:
                    break;
            }
            journalManager.storeEvent(alarmEvent, alarmStateTransition);
        }
        catch (Exception ex) {
            logger.error("Error Raising Alarm", ex);
            try { SystemLog.log(ex); } catch (Exception lex) { logger.error("Failed to log to SystemLog", lex); }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 8, 2021, 4:38pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/4 "2021-10-08T16:38:00Z")

</div>

If you want it to be a system event, then you just set `com.inductiveautomation.ignition.common.alarming.config.CommonAlarmProperties#IsSystemEvent` on the property set.

---

<div class="post-metadata">

**Author:** ![jtdfan](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@jtdfan](https://forum.inductiveautomation.com/u/jtdfan)\
**Post date:** [October 8, 2021, 9:03pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/5 "2021-10-08T21:03:13Z")

</div>

I tried the following code and setting isSystemFlag didn’t seem to do much either. It is possible I used it incorrectly because I am not sure where I was supposed to set that property value.

```auto
public void raiseAlarm(String alarmName, String source, String user, String displayPath, AlarmPriority alarmPriority, AlarmStateTransition alarmStateTransition, String eventMessage, Integer eventValue) {
        try {
            var addr = InetAddress.getLocalHost();
            String hostname = addr.getHostName();

            QualifiedPath.Builder qualifiedPathBuilder = new QualifiedPath.Builder();
            qualifiedPathBuilder.setAlarm(alarmName.replace(' ', '_'));
            //qualifiedPathBuilder.setEvent(eventMessage);
            //qualifiedPathBuilder.setMachine(hostname);
            qualifiedPathBuilder.setProvider("LIFT");
            //qualifiedPathBuilder.setSource(source);
            //qualifiedPathBuilder.setUser(user);
            qualifiedPathBuilder.setTag("testAlarm");
            QualifiedPath qualifiedPath = qualifiedPathBuilder.build();

            AlarmJournalManager journalManager = liftGatewayContext.getAlarmManager().getJournalManager();
            BasicAlarmEvent alarmEvent = new BasicAlarmEvent(qualifiedPath, displayPath, alarmPriority);
            UnfilteredEventData eventData;
            BasicPropertySet psb = new BasicPropertySet();
            //psb.set(CommonAlarmProperties.Enabled, true);
            DateTime alarmDate = DateTime.now();
            switch (alarmStateTransition) {
                case Ack:
                    psb.set(CommonAlarmProperties.EventValue, eventValue);
                    psb.set(CommonAlarmProperties.Label, eventMessage);
                    eventData = new UnfilteredEventData(alarmDate.getMillis(), psb);
                    //alarmEvent.set(CommonAlarmProperties.IsSystemEvent, true);
                    alarmEvent.acknowledge(eventData);
                    break;
                case Active:
                    psb.set(CommonAlarmProperties.EventValue, eventValue);
                    psb.set(CommonAlarmProperties.Label, eventMessage);
                    eventData = new UnfilteredEventData(alarmDate.getMillis(), psb);
                    //alarmEvent.set(CommonAlarmProperties.IsSystemEvent, true);
                    alarmEvent.active(eventData);
                    break;
                case Clear:
                    psb.set(CommonAlarmProperties.EventValue, eventValue);
                    psb.set(CommonAlarmProperties.Label, eventMessage);
                    eventData = new UnfilteredEventData(alarmDate.getMillis(), psb);
                    //alarmEvent.set(CommonAlarmProperties.IsSystemEvent, true);
                    alarmEvent.clear(eventData);
                    break;
                case Finished:
                    break;
            }
            journalManager.storeEvent(alarmEvent, alarmStateTransition);
        }
        catch (Exception ex) {
            logger.error("Error Raising Alarm", ex);
            try { SystemLog.log(ex); } catch (Exception lex) { logger.error("Failed to log to SystemLog", lex); }
        }
    }

```

 ![Alarms](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/7/c762a9eb564643b9252582b2fb43a636cb397e15.png)

The image shows 2 alarms

1. This is the one generated from the script above. However, the System tag for Active, Unacknowledged alarms does not change values ([System]Gateway/Alarming/Active and Unacked).
2. This alarm is from a tag generated alarm we have configured in one of our UDTs. It seems like I am missing something to tell the gateway there is a new active alarm.

Thank you for the help

---

<div class="post-metadata">

**Author:** ![eric.hollering](https://avatars.discourse-cdn.com/v4/letter/e/ad7895/32.png) [@eric.hollering](https://forum.inductiveautomation.com/u/eric.hollering)\
**Post date:** [October 20, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/6 "2021-10-20T19:43:14Z")

</div>

Still trying to work through this based on the SDK Programmer Guide and the JavaDocs, but struggling with a few things.

The SDK guide says

> Most alarms in Ignition are defined on tags. However, it is possible for modules to generate their own alarms. All alarm evaluation is handled by the AlarmManager, you simply give it the definition of an alarm through AlarmManager.registerAlarm(...), and it provides you with an AlarmEvaluator that you update from time to time with the current value.

However, registerAlarm takes 4 parameters, and we're not sure how to construct them to raise a simple alarm.

Here's what I see in the JavaDocs.

> [AlarmEvaluator](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.11/com/inductiveautomation/ignition/gateway/alarming/evaluation/AlarmEvaluator.html) registerAlarm​([QualifiedPath](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.11/com/inductiveautomation/ignition/common/QualifiedPath.html) sourcePath, [PropertyValueSource](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.11/com/inductiveautomation/ignition/common/config/PropertyValueSource.html) parentProperties, [AlarmConfiguration](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.11/com/inductiveautomation/ignition/common/alarming/config/AlarmConfiguration.html) configuration, [ExpressionParseContext](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.11/com/inductiveautomation/ignition/common/expressions/ExpressionParseContext.html) expressionContext)
> 
> Registers the configuration of an alarm for a specific source, also providing the context for references in bound alarm properties. The result is an AlarmEvaluator which will be used by the source to evaluate values. When the source is done or removed, it should release the AlarmExecutor to unregister it from the system.

So let's say we want to raise a simple alarm that shows the user that a bad thing happened whenever we encounter a condition (hypothetically, we can use as an example, an exception is encountered during a critical operation).

What would we need need to pass in as a QualifiedPath, PropertyValueSource and ExpressionParseContext when we're wanting to raise the alarm on something in memory instead of on a tag?

Once we have an AlarmEvaluator, how do we update it from time to time?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 20, 2021, 9:01pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/7 "2021-10-20T21:01:30Z")

</div>

I don’t think what you’re ultimately looking for is currently possible.  
`registerAlarm` is going to give you back an object that you can manually provide specific values to, and then based on the supplied alarm configuration, the `AlarmEvaluator` will choose whether or not it’s going to actually trigger an alarm. It’s not a true ‘fire off an alarm using the rest of the subsystem’ mechanism.

---

<div class="post-metadata">

**Author:** ![eric.hollering](https://avatars.discourse-cdn.com/v4/letter/e/ad7895/32.png) [@eric.hollering](https://forum.inductiveautomation.com/u/eric.hollering)\
**Post date:** [October 22, 2021, 5:27pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/8 "2021-10-22T17:27:33Z")

</div>

Is there another approach you would recommend?

The best we could come up with under current constraints would be to create and destroy tags just for the sake of raising alarms, which feels hacky.

---

<div class="post-metadata">

**Author:** ![jtdfan](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@jtdfan](https://forum.inductiveautomation.com/u/jtdfan)\
**Post date:** [November 1, 2021, 11:31pm UTC](https://forum.inductiveautomation.com/t/alarming-from-within-a-module/51748/9 "2021-11-01T23:31:00Z")

</div>

I was looking over the platform services document and found the section on Alarming. Can someone provide an example on how to use it?

[https://docs.inductiveautomation.com/display/SE/Working+with+Platform+Services](https://docs.inductiveautomation.com/display/SE/Working+with+Platform+Services)

Should we use an AlarmListener implementation or register to the AlarmManager and use an AlarmExecutor?

We basically want to show an active alarm when some of our functions either have an exception or a “bad” state.

We appreciate any input.
