# System.alarm.querystatus top 10 items

**URL:** <https://forum.inductiveautomation.com/t/system-alarm-querystatus-top-10-items/96693>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [October 2, 2024, 4:42am UTC](https://forum.inductiveautomation.com/t/system-alarm-querystatus-top-10-items/96693 "2024-10-02T04:42:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kim\_JinGeun1](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Kim\_JinGeun1](https://forum.inductiveautomation.com/u/Kim_JinGeun1)\
**Post date:** [October 2, 2024, 4:42am UTC](https://forum.inductiveautomation.com/t/system-alarm-querystatus-top-10-items/96693/1 "2024-10-02T04:42:09Z")

</div>

I would like to retrieve the 10 most recent alarms from system.alarm.querystatus. What should I do?

---

<div class="post-metadata">

**Author:** ![Kim\_JinGeun1](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Kim\_JinGeun1](https://forum.inductiveautomation.com/u/Kim_JinGeun1)\
**Post date:** [October 2, 2024, 5:07am UTC](https://forum.inductiveautomation.com/t/system-alarm-querystatus-top-10-items/96693/3 "2024-10-02T05:07:25Z")

</div>

```python
def getAlarms(self, value, app=None):
	states = []
	for i in range(len(self.custom.states)):
		states.append(self.custom.states[i])
	alarms = system.alarm.queryStatus(state=states, priority=["Critical"])#, all_properties=[('App', '=', app)])
	data = []
	for alarm in alarms:
		displayPath = alarm.getDisplayPath()
		priority = alarm.getPriority()
		priorityOrdinal = alarm.getPriority().ordinal()
		state = alarm.getState().ordinal() #0=ClearUnacked, 1=ClearAcked, 2=ActiveUnacked, 3=ActiveAcked
		stateOrder = [1,0,3,2].index(state)
		id = alarm.getId()
		name = alarm.getName()
		
		timestamp = None
		timestampMS = None
		eventValue = None
		
		active = {}
		if alarm.getActiveData() != None:
			for prop in alarm.getActiveData().getValues():
				active[prop.getProperty().getName()] = prop.getValue()
			
		clear = {}
		if alarm.getClearedData() != None:
			for prop in alarm.getClearedData().getValues():
				clear[prop.getProperty().getName()] = prop.getValue()
		
		stateDict = active if state in [2,3] else clear
		if "eventTime" in stateDict:
			timestamp = system.date.format(stateDict["eventTime"], "M/d/yy hh:mm:ss a")
			timestampMS = stateDict["eventTime"]
		
		if "eventValue" in stateDict:
			eventValue = str(stateDict["eventValue"])
		
		ack = {"isAcked":False, "id":id}
		if state in [1,3]:
			ack["isAcked"] = True
			for prop in alarm.getAckData().getValues():
				propValue = str(prop.getValue())
				if prop.getProperty().getName() == "eventTime":
					propValue = system.date.format(prop.getValue(), "M/d/yy hh:mm:ss a")
				ack[prop.getProperty().getName()] = propValue
		ack = system.util.jsonEncode(ack)
		if state == 2:
			data.append({"id":id, "displayPath":displayPath, "name":name, "priority":priority, "priorityOrdinal":priorityOrdinal, "state":state, "stateOrder":stateOrder, "timestamp":timestamp, "timestampMS":timestampMS, "value":eventValue, "ack":ack})
	
	data.sort(key=lambda x: (x["stateOrder"], x["priorityOrdinal"], x["timestampMS"]), reverse=True)
	return data

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 2, 2024, 6:19am UTC](https://forum.inductiveautomation.com/t/system-alarm-querystatus-top-10-items/96693/4 "2024-10-02T06:19:37Z")

</div>

> [@Kim\_JinGeun1](#):
>
> `alarm.getClearedData().getValues()`

instead of all of these " **get** Function()" calls you can drop the "get" and access them in a more pythonic way:  
e.g.

```python
alarm.getClearedData().getValues() -->
alarm.clearedData.values

active[prop.getProperty().getName()] = prop.getValue() ->
active[prop.property] = prop.value

```

Basically, just drop the "get" and make it camelCase.  
Jython automatically converts JavaBean conventioned Java getters and setters into a more Pythonic style by removing the gets/sets to make them more familiar to Python programmers and also simpler to read and write.

Something I find useful is running this on an obj to see what methods/props it has, and their types. You can also refer to the [javadocs](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.41/index.html):

```python
obj = prop
for d in dir(obj): print d, getattr(obj, d)

```

> [@Kim\_JinGeun1](#):
>
> ```python
> states = []
> for i in range(len(self.custom.states)):
> states.append(self.custom.states[i])
> 
> ```

You can also replace this above with this below:

```python
states = list(self.custom.states)

```
