Check user role on all active clients

I have a “maintenance” user role defined on my gateway. What I’d like to do is be able to monitor the role of the user logged in to each client. Then, if there are no users logged in with the “maintenance” role, I could automatically take my PLC out of maintenance mode. I know that I could setup a Client script to monitor the “[System]Client/User/RolesString” but that only tells me about that client. If there’s another client that still has a maintenance user logged in, I would want to leave the PLC in maintenance mode.

Anyone know of a way to loop through all the instances of client tags?

Figured it out. The system.util.getSessionInfo() method gives a list of all the active sessions and their information. I wrote a gateway timer script to periodically check what user roles are logged in.

sessions = system.util.getSessionInfo()
maint = 0
for sess in sessions:
	if not sess["isDesigner"]:
		user = system.user.getUser("default",sess["username"])
		for role in user.getRoles():
			if role == "Maintenance" or role == "Administrator":
				maint += 1
1 Like