# New Alarm Alert as a Popup

**URL:** <https://forum.inductiveautomation.com/t/new-alarm-alert-as-a-popup/15828>\
**Category:** Ignition\
**Created:** [October 31, 2017, 4:17pm UTC](https://forum.inductiveautomation.com/t/new-alarm-alert-as-a-popup/15828 "2017-10-31T16:17:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [November 1, 2017, 5:07am UTC](https://forum.inductiveautomation.com/t/new-alarm-alert-as-a-popup/15828/2 "2017-11-01T05:07:47Z")

</div>

I would start this a different route. It looks like you are polling for changes to alarm states, when really, we should be reacting to events relating to alarm state changes. This is going to be a long winded answer, so hear goes.

1. Create a new shared script. For this example, create it at shared.alarming. The following will create an object, that extends Ignition’s AlarmListener interface. This is how we get the alarm event from the gateway to the client.

Post the following code:

```auto
from com.inductiveautomation.ignition.common.alarming import AlarmListener
class MyAlarmListener(AlarmListener):
	def __init__ (self):
		system.util.getLogger("MyAlarmListener").info("Constructing Object")
		
	def onAcknowledge(self,evt):
		system.util.getLogger("MyAlarmListener").info("OnAcknowledge")
		system.util.sendMessage(project="prime",messageHandler="onAcknowledge",payload = {"event":evt},scope = "C")
		
	def onActive(self,evt):
		system.util.getLogger("MyAlarmListener").info("OnActive")
		system.util.sendMessage(project="prime",messageHandler="onActive",payload = {"event":evt},scope = "C")
			
	def onClear(self,evt):
		system.util.getLogger("MyAlarmListener").info("OnClear")
		system.util.sendMessage(project="prime",messageHandler="onClear",payload = {"event":evt},scope = "C")

```

If you dont need one of the event, let’s say onAcknowledge, replace the code with

```auto
def onAcknowledge(self,evt):
	pass

```

1. Create message handlers in the client scope. You will need onActive, onAcknowledge, and onClear defined, in line with what you put in MyAlarmListener

Hear is some sample code, which may be put into onActive.

```auto
	from java.util import Date
	name = payload["event"].getName()
	dPath = payload["event"].getDisplayPathOrSource()
	tStamp = Date(payload["event"].getActiveData().getTimestamp())
	message = "<html>New Alarm <b>%s</b> occurred at %s."%(str(dPath),tStamp)
	system.gui.messageBox(message,"New Alarm")
#	print payload["event"]

```

1. Register the alarm listener with the system. This script essentially says “Hey, listen for every alarm, and use MyAlarmListener to figure out what to do”. Put this in the gateway startup script.

```auto
from com.inductiveautomation.ignition.gateway import SRContext
from com.inductiveautomation.ignition.common import QualifiedPath
context = SRContext.get()

l = shared.alarming.MyAlarmListener()
system.util.getGlobals()["alarm-listener"] = l

n = context.getSystemProperties().getSystemName()
v = QualifiedPath.Builder()
#	v.setSystem(n)

system.util.getLogger("listener test").info("registering listener")
context.getAlarmManager().addListener(v.build(),l)

```

1. Finally, you need this in the gateway shutdown script.

```auto
from com.inductiveautomation.ignition.gateway import SRContext
from com.inductiveautomation.ignition.common import QualifiedPath
if "alarm-listener" in system.util.getGlobals():
	context = SRContext.get()
	v = QualifiedPath.Builder()
	
	system.util.getLogger("listener test").info("unregistering listener")
	context.getAlarmManager().removeListener(v.build(),system.util.getGlobals()["alarm-listener"])

```

If you have any questions, please let me know.

---

_[View the full topic](https://forum.inductiveautomation.com/t/new-alarm-alert-as-a-popup/15828)._
