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.
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.
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.
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.
Your very first line of code is not doing anything because you’re not saving that value into a variable.
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))
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.
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.
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))
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.