# Access alarms associated data dynamically in pipeline script

**URL:** <https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715>\
**Category:** Ignition\
**Created:** [May 18, 2022, 11:34am UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715 "2022-05-18T11:34:56Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 18, 2022, 11:34am UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/1 "2022-05-18T11:34:56Z")

</div>

Hello folks,

I’m trying to access alarm events associated data without knowing what it is. In a notification pipeline script block.

A bit like I would do

```python
for k, v in alarm.items()

```

with a dictionnary.

Is there any way to figure out what data is present on an alarm ?

---

<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:** [May 18, 2022, 2:35pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/2 "2022-05-18T14:35:07Z")

</div>

[`PyAlarmEvent`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.16/com/inductiveautomation/ignition/common/alarming/PyAlarmEvent.html) implements a bunch of interfaces, including `Iterable<PropertyValue>`, so even something as simple as:

```python
for pv in alarm:
    print pv.property, pv.value

```

Should work. No automatic unpacking, though, unfortunately.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 18, 2022, 2:36pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/3 "2022-05-18T14:36:40Z")

</div>

I though I tried that…  
I’ll try again, thanks Paul

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 18, 2022, 2:51pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/4 "2022-05-18T14:51:35Z")

</div>

Yeah so here's the issue: In the script block of the notification pipeline, it's not a `PyAlarmEvent` but this pretty thing: `com.inductiveautomation.ignition.alarming.pipelines.blocks.ScriptableBlock$ScriptableBlockPyAlarmEvent`

So i get this error when trying to iterate through it:

> com.inductiveautomation.ignition.common.script.JythonExecException: TypeError: 'com.inductiveautomation.ignition.alarming.pipelines.blocks.ScriptableBlock$ScriptableBlockPyAlarmEvent' object is not iterable

---

<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:** [May 18, 2022, 3:19pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/5 "2022-05-18T15:19:45Z")

</div>

Sure… but:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/c/4ce090716072cc6d9b4b97a971afcb6532e98849.png)

Any of these should do the trick?

```auto
for prop in alarm.properties:
    print prop.name, prop.type, prop.defaultValue
    print alarm.get(prop)

for prop in alarm.sourceEvent().properties:
    print prop.name, prop.type, prop.defaultValue
    print alarm.get(prop)

for pv in alarm.sourceEvent().values:
    prop = pv.prop
    print prop.name, prop.type, prop.defaultValue
    print pv.value

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 18, 2022, 8:23pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/6 "2022-05-18T20:23:15Z")

</div>

First one resulted in an error: `NoneType is not iterable`  
Second and third ones give me some results, but not the associated data. I’ll investigate those tomorrow, see if I can get something out of them

---

<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:** [May 18, 2022, 9:13pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/7 "2022-05-18T21:13:55Z")

</div>

Ohhh, my fault.

I think you need to step from the alarm event into the active/clear/ack data:  
[https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.16/com/inductiveautomation/ignition/common/alarming/AlarmEvent.html#getActiveData()](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.16/com/inductiveautomation/ignition/common/alarming/AlarmEvent.html#getActiveData())

Which will itself be another property set that (again, theoretically) should be directly iterable.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 18, 2022, 9:20pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/8 "2022-05-18T21:20:22Z")

</div>

I’ll try this tomorrow if I can find some time between changing diapers (I’m on 4months old poop factory duty).  
I do have another question though: How can I properly test pipeline scripts ? Is there some way for me to mock up a pipeline alarm event in the script console to inspect the object and play around with it ?  
I did try to import a few things in the script console, but everything failed. Couldn’t figure out the right things I’d need.  
I’ve been doing it directly in the pipeline, logging things and sending email notifications to output data, but that’s far from ideal…

---

<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:** [May 18, 2022, 9:21pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/9 "2022-05-18T21:21:25Z")

</div>

You can send basic test events through the system via the web interface:  
[https://docs.inductiveautomation.com/display/DOC81/Alarm+Notification#AlarmNotification-NotificationTesting](https://docs.inductiveautomation.com/display/DOC81/Alarm+Notification#AlarmNotification-NotificationTesting)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 18, 2022, 9:23pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/10 "2022-05-18T21:23:31Z")

</div>

I have a set of boolean tags with alarms configured on them, it’s much easier to just click the tags to send an alarm through the pipeline.  
But it doesn’t help in inspecting the event object itself, I’d rather be able to instantiate a dummy event in the console and mess with it there.

---

<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:** [May 18, 2022, 9:25pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/11 "2022-05-18T21:25:14Z")

</div>

With sufficient effort, you could generate an event on the gateway the same way the testing page does, but you won’t be able to do it from the designer - you won’t have the right classes, so you’d at best be `system.util.sendMessage`-ing to the gateway to describe the event.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 18, 2022, 9:28pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/12 "2022-05-18T21:28:25Z")

</div>

Eh, `sendMessage`ing things to a page that would display the info actually sounds like an improvement… Would be more readable than the logs.  
Is this a terrible idea ?

---

<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:** [May 18, 2022, 10:17pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/13 "2022-05-18T22:17:37Z")

</div>

You’re in unsupported territory as far as creating and firing the events goes. I’d have to look at how the test page does it to know how to properly do that.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 23, 2022, 3:13pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/14 "2022-05-23T15:13:33Z")

</div>

So, here’s the simplest I could do…

```python
context = [
	(str(p.property.name).lstrip("context_"), p.value)
	for p in event.sourceEvent().activeData if str(p.property.name).startswith('context')
]

```

(I prefixed them with ‘context\_’ myself so I could differentiate them, but I guess I could use the type of the property instead)  
I kinda feel like there should be an easier way to get unknown associated data from an event in a pipeline script :X

---

<div class="post-metadata">

**Author:** ![tyler.bennett](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@tyler.bennett](https://forum.inductiveautomation.com/u/tyler.bennett)\
**Post date:** [October 14, 2022, 5:49pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/15 "2022-10-14T17:49:08Z")

</div>

This works (see below), at least in Ignition v8.1.18. Posting here for the benefit of others.

```python
def handleAlarm(event):
# Uncomment next two lines for debug output (if needed), prints event properties to wrapper.log, 
	for d in dir(event): print d
	for p in event.getProperties():	print"'event['{}']: {} {}".format(p, event[p], type(event[p]))

```

I found there are several properties not listed in [available documentation](https://docs.inductiveautomation.com/display/DOC81/Notification+Block#NotificationBlock-MessageProperties).  
Specifically `projectName` and `pipelineName` were useful to me.  
Here is some sample output from the second line, modified to remove identifying details.

```auto
event['branchDepth'] <type 'int'>
event['notes'] <type 'unicode'>
event['itemPath'] <type 'unicode'>
event['activeDuration'] <type 'unicode'>
event['timeOnDelaySeconds']	<type 'float'>
event['shelvingAllowed']	<type 'bool'>
event['isActive'] <type 'bool'>
event['eventTime'] <type 'java.util.Date'>
event['source'] <type 'com.inductiveautomation.ignition.common.QualifiedPath'>
event['ackUserName'] <type 'unicode'>
event['enabled'] <type 'bool'>
event['isAcked']: <type 'instancemethod'>
event['mode'] <type 'com.inductiveautomation.ignition.common.alarming.config.AlarmMode'>
event['ackTime'] <type 'NoneType'>
event['ackUser'] <type 'NoneType'>
event['clearTime'] <type 'java.util.Date'>
event['deadband'] <type 'float'>
event['timeOffDelaySeconds']	<type 'float'>
event['state'] <type 'com.inductiveautomation.ignition.common.alarming.AlarmState'>
event['pipelineVersion']	<type 'long'>
event['displayPath'] <type 'com.inductiveautomation.ignition.common.StringPath'>
event['displayPathOrSource']	<type 'unicode'>
event['pipelineTransitionCount']	<type 'int'>
event['pipelineName'] <type 'unicode'>
event['projectName'] <type 'unicode'>
event['fullItemPath'] <type 'unicode'>
event['itemName'] <type 'unicode'>
event['label']	<type 'unicode'>
event['priority']	<type 'com.inductiveautomation.ignition.common.alarming.AlarmPriority'>
event['isJournaled']	<type 'bool'>
event['ackNotesReqd']	<type 'bool'>
event['timestampSource']	<type 'com.inductiveautomation.ignition.common.sqltags.model.types.TimestampSource'>
event['ackMode']	<type 'com.inductiveautomation.ignition.common.sqltags.model.types.AlertAckMode'>
event['eventValue']	<type 'bool'>
event['isShelved']	<bound method com.inductiveautomation.ignition.alarming.pipelines.blocks.ScriptableBlock$ScriptableBlockPyAlarmEvent.isShelved of Event[name=Alarm, source=prov:default:/tag:_Test-Tyler/TestBool:/alm:Alarm, priority=Low, desc=null]> <type 'instancemethod'>
event['ackDuration']:	<type 'unicode'>
event['activeTime']:	<type 'java.util.Date'>
event['isClear']	<type 'bool'>
event['eventState']	<type 'com.inductiveautomation.ignition.common.alarming.AlarmStateTransition'>
event['name']: Alarm <type 'unicode'>
event['deadbandMode']	<type 'com.inductiveautomation.ignition.common.sqltags.model.types.DeadbandMode'>

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 15, 2022, 6:45am UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/16 "2022-10-15T06:45:27Z")

</div>

I don't think `getProperties` gets you **associated** data.  
I found those in `event.sourceEvent().activeData`

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [November 15, 2024, 10:12pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/17 "2024-11-15T22:12:37Z")

</div>

I (Ignition 8.1.42 within Alarm Pipeline script) was able to retrieve associated data via `event.sourceEvent().getActiveData()`. and also `event.getActiveData()`.

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [November 15, 2024, 10:43pm UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/18 "2024-11-15T22:43:31Z")

</div>

.. and then accessing specifics of each [PropertyValue](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.42/com/inductiveautomation/ignition/common/config/PropertyValue.html) using:

```python
myLogger = system.util.getLogger("Test_Pipeline")
activeData = event.getActiveData()
for prop in activeData:
	myLogger.info("key={}, value={}".format(prop.getProperty().getName(), prop.getValue()))

```

---

<div class="post-metadata">

**Author:** ![tyler.bennett](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@tyler.bennett](https://forum.inductiveautomation.com/u/tyler.bennett)\
**Post date:** [January 8, 2025, 12:21am UTC](https://forum.inductiveautomation.com/t/access-alarms-associated-data-dynamically-in-pipeline-script/59715/19 "2025-01-08T00:21:24Z")

</div>

Here is my latest attempt to identify and access alarm associated data from an event in an alarm notification pipeline script, without prior knowledge what alarm associated data might exist.

The basic approach here is to create a set from the properties found in in `event.getActiveData().getProperties()` and then remove any matching properties that exist in the built-in `CommonAlarmProperties` and `AlarmModeProperties`. In theory that leaves only the alarm associated data.

```python
def handleAlarm(event):
	from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties, AlarmModeProperties
	associatedDataProps = list(set(event.getActiveData().getProperties()).difference(AlarmModeProperties.values()).difference(CommonAlarmProperties.values()))

	for prop in associatedDataProps:
		print prop, event.get(prop)

```

Seems to work. Has anyone discovered better solutions?
