Hi ,
I would like to display the below values in a vision window,
- Active OPC connections
- Users count from default user source.
- Users count for AD/Internal hybrid
- Parameters count that has been historized
would like to hear your ideas to retrieve the above info
Which version of Ignition?
For 2 and 3, do you want the total users in those sources or just the logged in users?
I am using 8.1.25.
I require total users count with specific role.
OPC connections or devices?
OPC UA connections as in Status-> Connections-> OPC Connections
from collections import Counter
from itertools import chain
# OPC connections
opcConnections = Counter([system.opc.getServerState(opcServer) for opcServer in system.opc.getServers(includeDisabled = True)])
print opcConnections
# user source
userSource = 'myUserSource'
users = system.user.getUsers(userSource)
roles = Counter(list(chain.from_iterable(user.roles for user in users)))
print roles
2 Likes
# Count tags with history turned on
filters = {
'tagType' : 'AtomicTag',
'recursive' : True
}
provider = '[Test]'
historyCount = 0
for tag in system.tag.browse(provider, filters).getResults():
if 'history' in str(dict(tag).get('attributes', '')):
#print str(tag['fullPath'])
historyCount += 1
print historyCount
3 Likes
Thanks Jordan.
I have achieved the results by modifying the code as below,
#To get the count of historized tag
filters = {
'tagType' : 'AtomicTag',
'recursive' : True
}
provider = '[default]'
historyCount = 0
for tag in system.tag.browse(provider, filters).getResults():
if 'history' in str(dict(tag).get('attributes', '')):
#print str(tag['fullPath'])
historyCount += 1
vTotal = historyCount
system.tag.writeBlocking("[.]Parameters",[vTotal])
#To get the Total no of AD users
userSource = 'XYZ.COM'
users = system.user.getUsers(userSource)
viewer_count = sum(1 for user in users if 'Viewer' in user.roles)
system.tag.writeBlocking("[.]Users",[viewer_count])
#To get the Total no of Local users
userSource1 = 'default'
users1 = system.user.getUsers(userSource1)
viewer_count1 = sum(1 for user in users1 if 'Viewer' in user.roles)
system.tag.writeBlocking("[.]Operators",[viewer_count1])
#To get the Total no of OPC connections
from collections import Counter
from itertools import chain
# OPC connections
opcConnections = Counter([system.opc.getServerState(opcServer) for opcServer in system.opc.getServers(includeDisabled=True)])
connected_count = opcConnections['CONNECTED']
system.tag.writeBlocking("[.]OPCConnections",[connected_count])