Recording Session Logins

Hello all! This is my first post. I’m happy to be a part of this community.

I’m trying to do something I expect is very common, but I’m spinning my wheels a little bit. I am using Ignition perspective in v8.1.48 and the current goal is to log various bits of user information each time an operator logs into a perspective project. Most of my experience is with the Vision module. I initially attempted to do this in a startup event, but found this unreliable for my use case.

The trouble I’m running into is that some of the information I am logging is coming into my database as NULL. What I’m attempting to do is fire a change script off of the ‘authenticated’ session property. the following is the execution of this:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):    if currentValue.value != previousValue.value and currentValue.value == True:
        params = {     'ip_addr'    :    self.props.address
                    ,'host'        :    self.props.host
                    ,'userName'    :    self.props.auth.user.userName
                    ,'userID'    :    self.props.auth.user.id
                    ,'project'    :    system.util.getProjectName()
                    ,'timestamp':    system.date.now()
                    }
        system.db.runNamedQuery(path = 'Logging/logUserAuth', parameters = params)

What I’m finding is my records only capture the host property, the user id, project name and timestamp. The ip address and username are coming in as NULL, but the same properties are showing up on screen in labels I’ve bound to them. I suspect this might be a timing issue?
I’m using an internal ignition identity provider and user source, in case that matters.

My questions are these:

  1. Is this the best method for doing something like this? I’m open to alternatives provided they allow me some degree of flexibility with what I am logging.
  2. Why are my values coming in as NULL? Are the session properties not populated at the same time that the authenticated property is set?

Thanks for your help.

They are, but change scripts run in parallel, and will inevitably have timing-related problems.

Good to know! Is there a better event I should be driving this off of to do this? Or should I just tack this script inside of an invokeLater with a short delay (maybe 500-1000ms)? I’m typically hesitant to run delayed-event scripts like this.

invokeLater doesn't exist for Perspective, but Perspective also tolerates .sleep() where Vision does not. Consider a 5ms or 10ms delay. Or, perhaps, attach change events directly to the properties of interest and log them separately.

invokeLater doesn't exist for Perspective, but Perspective also tolerates .sleep() where Vision does not.

Shoot :man_facepalming: you’re right.

I’ll go with the delay as you’ve suggested. I think independently logging each property might overcomplicate things for what I’m doing. I’ll consider it more if I run into any reliability issues.

I really appreciate your help, here and elsewhere on the forum! :slight_smile:

Adding an update here for anyone here in the future:

I applied the fix discussed above but it did not resolve my issue. The problem came down to casing issues with multiple of my named query parameter names. (‘username’ vs ‘userName’, ‘IP_addr’ vs ‘ip_addr’ etc.)

Embarrassing to admit but I believe it’s better to maintain accuracy on these forums than pride.

Fixing the parameter names to match my dictionary keys resolved my issue, without the addition of the time delay.

3 Likes