[IGN-3870] Alarm count status help. (system.alarm.queryStatus)

Hello Everybody,
I am working on a task where I need to get Alarm counts and display on dashboard.
With the below script executing in gateway script timer I am able to get counts in Default Tag provider but as soon as I change the Tag provider count becomes Zero, Where as I know there are few alarm on tags in those provider.

Code:
system.tag.read(“Alarms_Count”)
state = [“ActiveUnacked”]
alarms = system.alarm.queryStatus(Source=[“default”],state = state)
system.tag.write(“Alarms_Count”,len(alarms))

Eg: I have Tag providers as default /Provider 1/Provider 2. as soon as I change Source from default to Provider 1 or 2 counts are 0

Thanks for the help ! :slightly_smiling_face:

try source, without the majuscule.

  1. If you supply snippets on the forums, please either use the UI to format the code using the </> formatting tool, or place all of your code between triple backticks
    ```
    code here
    ```
    to allow for easier reading.
  2. If you have code that isn’t doing what you want, we need to see the exact code you’re using when it’s not doing what you want - not the code which IS working for you.
  3. If you’re like me and had to go look up “majuscule”, I’l save you the trouble and recommend you just use lower-cased argument names because everything in Jython is case-sensitive.
  4. Your very first line of code is not doing anything because you’re not saving that value into a variable.
  5. NEVER paste the “curly” quotes and NEVER use the curly quotes in your Jython code - they will always break your code.

Try this:

state = ["ActiveUnacked"]
alarms = system.alarm.queryStatus(source=["Provider 1"],state = state)
system.tag.write("Alarms_Count",len(alarms))
2 Likes

Oops, my bad. Some French leaked out I guess.

The forum itself converts regular quotes to curly quotes if one fails to use the pre-formatted text button, fwiw.

The forum itself converts regular quotes to curly quotes

Ah, thanks - I was unaware.

I will also say, that if I’m posting from my phone, it doesn’t matter if I’m using pre-formatted text or not the quotes are always the wrong ones. Very frustrating.

Thanks for the prompt reply,

state = ["ActiveUnacked"]

alarms = system.alarm.queryStatus(source=["*default*"],state = state)

system.tag.write("Alarms_Count",len(alarms))

OR

state = ["ActiveUnacked"]

alarms = system.alarm.queryStatus(source=["*Ignition_Remote_IO_2*"],state = state)

system.tag.write("Alarms_Count",len(alarms))

OR

state = ["ActiveUnacked"]

alarms = system.alarm.queryStatus(source=["*Ignition_Remote_IO_3*"],state = state)

system.tag.write("Alarms_Count",len(alarms))

Capture

source argument default works but other three don’t work

If these are on separate gateways, I would use the script with it’s own tag on each gateway. Then, pont your dashboard indicator to the proper tag.

I implement your suggestion it still doesn’t work, default has counts but Igition_Remote_IO_2 doesn’t.

state = ["ActiveUnacked"]

alarms = system.alarm.queryStatus(source=["*default*"],state = state)

system.tag.write("Alarms_Count",len(alarms))

state = ["ActiveUnacked"]

alarms = system.alarm.queryStatus(source=["*Ignition_Remote_IO_2*"],state = state)

system.tag.write("[Ignition_Remote_IO_2]Alarms_Count",len(alarms))

I’m curious, why the wild card characters? I mean you only have 1 source for each provider correct?

If you remove the * does it work then?

If I remove wildcard I don’t get counts, below are some snaps from Alarm table Source column:

Capture2

Capture1

1 Like

All your providers in the source column are lower case. French leakage aside,

e.g.

alarms = system.alarm.queryStatus(source=["*ignition_remote_io_gateway*"],state = state)

1 Like

If you want a total of all alarms why not use [System]Gateway/Alarming/Active and Unacked?

Already tried that, result is same :expressionless:

Strangely there are 0 alarms in any category at mentioned path whereas with above script for default provider I have couple of thousand alarms.

I am seeing some behavior that I am still tracking down when using a source parameter with a remote gateway, but if you are looking for alarms in a specific provider, why aren’t you using the provider parameter? e.g.:

state = ["ActiveUnacked"]
system.alarm.queryStatus(provider="Provider 1", state=state)

edit: I am realizing that provider isn’t documented in the User Manual for some reason. I am looking into that as well.

Garth

1 Like

Do all the providers show up in the status table? Assuming yes:

Looking at your other posts, it looks like you’re on v7.9. This script should work to count all of them by provider, then write to a dataset tag. You should then be able to do a lookup expression to grab the one you want.

import re
from collections import Counter

pattern = re.compile(r'(?<=prov:)(.*)(?=:/tag)')

alarms = system.alarm.queryStatus()

counters = {}

for alarm in alarms:
	provider = pattern.findall(str(alarm.getSource()))[0]
	if provider not in counters.keys():
		counters[provider] = 1
	else:
		counters[provider] += 1
	

headers = ['provider', 'qty']
data = [[key, value] for key, value in sorted(counters.iteritems())]

system.tag.write('[Test]Alarms_Count', system.dataset.toDataSet(headers, data))
1 Like

There is an issue with how source is handling the searching that is related to a bug that has already been reported in both 7.9 and 8.x versions and this looks related to the case of the provider changing.

The provider kwarg was added to the code base specifically to handle remote gateways way back in 2015. If you can leverage that, it would likely be to your benefit.

The user manuals have been updated to reflect that availability of this kwarg.

Garth

1 Like

Thanks for the help !
Following code is now working as required :grin:

#system.tag.read("Alarms_Count")

state = ["ActiveUnacked"]

alarms = system.alarm.queryStatus(provider=["Ignition_Remote_IO_Gateway"],state = state)

system.tag.write("Alarms_Count",len(alarms))


#system.tag.read("[Ignition_Remote_IO_2]Alarms_Count")
state = ["ActiveUnacked"]

alarms = system.alarm.queryStatus(provider=["Ignition_Remote_IO_2"],state = state)

system.tag.write("[Ignition_Remote_IO_2]Alarms_Count",len(alarms))


state = ["ActiveUnacked"]

alarms = system.alarm.queryStatus(provider=["Ignition_Remote_IO_3"],state = state)

system.tag.write("[Ignition_Remote_IO_3]Alarms_Count",len(alarms))