system.perspective.getSessionInfo / page path

I use system.perspective.getSessionInfo to create this nifty page to see who's in the system.

What I's really like to add is to know what page path the users have loaded in the pageids. Essentially the contents of below:
image

Any ideas? I have put a suggestion in the suggestion box to add this to getSessionInfo, just thought I'd put this out there to get any other ideas I may be missing...

Thanks!

I would guess implementing this would be difficult as a session could be using multiple pages at any one time in different tabs/windows and maybe even different browsers.

I've previosuly wanted to do something similiar so that a user would have their previous pages automatically open when they logged back in, but we struggled to get any information of this sort, and it might not be possible. I wonder if being browser based would limit what kind of data can be returned.

Yes.

You would have to track such things yourself, in the various session/page/view life cycle events, while the session is active. But it will be a bit tricky, as you will likely miss page/view closure events when the user closes tabs (browsers don't necessarily honor JS requests to intervene in those operations).

I started working that and saving to a tag but then decided I didn't need it that bad. Figured this would be something IA could add as they do know the pages from the server in the session details / Pages, you know, if they wanted to...

Just making sure I wasn't missing something.


image

The session info payload is deliberately flattened so that it's easier to represent in a '2d' format like a dataset, and so it's not (even more complicated) for new users.

In the meantime, you could get access to the same information the status page gives you with a modification of the code here:

1 Like

Thank you, very kindly sir! I'll look into this.

In case folks are interested, I did get this to work. I noticed most of my main pages would load at address 'C$0:0$0:2', a couple base pages at 'C'. This helped me target the path that I wanted to see and not all the embedded views. Thanks again everyone for your help!

inputPageIds = []	# my fuunction passes in pageids from getSessionInfo() call

from com.inductiveautomation.ignition.gateway import IgnitionGateway

project_name = system.util.getProjectName()
# project_name = 'myProject'

context = IgnitionGateway.get()
mod_mgr = context.getModuleManager()
# need to get "com.inductiveautomation.perspective.common.api.PropertyType" from module manager to
# get the "props" and "custom" enums for fetching the session props and the custom props
prop_type_class = mod_mgr.resolveClass('com.inductiveautomation.perspective.common.api.PropertyType')
# the below uses the gateway context module manager to function essentially as an import statement
persp_ctx_class = mod_mgr.resolveClass('com.inductiveautomation.perspective.gateway.api.PerspectiveContext')
# instantiate the PerspectiveContext using the gateway context
persp_ctx = persp_ctx_class.get(context)
# get the PerspectiveSessionMonitor object running in gateway context
psm = persp_ctx.getSessionMonitor()
# grab <InternalSession> object list for the target project
int_sessions = psm.getClientSessionsForProject(project_name)
#	return int_sessions
active_sessions = {}
#	listResults = []
dictResults = {}

# loop over internal sessions to build a map of active sessions with the target view open
for i, sess in enumerate(int_sessions):
	# loop over the open pages for each session and get the id for each
	for page in sess.getPages():
		# this returns the page id that matches the gateway Status -> Connections -> Perspective Sessions -> Session detail page
		page_id = page.getId()
		if page_id not in inputPageIDs : continue
		views = page.getViews()
		for view in views :
			system.perspective.print(str(view.getId()))
			result = str(view.getId()).split('@') 	# split at @.  left (0) is page path, right (1) is address
			# With the way I have things configured, all my pages appear to be at address C$0:0$0:2,
			#	a few home pages come in at "C".  This takes 'C$0:0$0:2' if there, 'C' if not
			if result[1] in ['C', 'C$0:0$0:2' ] :	
				pageKey = "_" + page_id 
				if pageKey in dictResults.keys() :
					if dictResults[pageKey]['key'] != 'C' : continue
					
#					listResults.append( [page_id, result] )
				# write to dict structure formatted string of page path.  (some string parts removed for easier reading.)
				dictResults.update( { "_" + page_id : { "path" : str(result[0]).split("/",1)[1].replace("/Large",""), "key" : str(result[1]) } } )
				if str(result[1]) == 'C$0:0$0:2' : break  # no need to keep looking on views if I found a 'C$0:0$0:2'
				
return dictResults

3 Likes