Perspective Auditing

Just wanted to share a solution to how to audit/log user actions via perspective. An Ignition rep helped us out with this and I imagine some people may have a similar need/issue.

First thing was that registering perspective user login/logout does NOT work with the default audit database. You need to create your own audit table to do this, so we made a table named PERSPECTIVE_AUDIT_TABLE.

To register login/logout user events, in Designer go to Project->Session Events->Startup (or Shutdown). then you can insert code like we did:

userName = session.props.auth.user.userName
action = "Login"
system.db.runPrepUpdate("INSERT INTO PERSPECTIVE_AUDIT_TABLE(ACTOR,ACTION) VALUES (?,?)", [userName, action])	

Logging user control changes such as button presses, etc. are done via component event scripting. For example for a slider action we used:

userName = self.session.props.auth.user.userName
action = self.view.params.Farm + " " + self.view.params.ControllerName+" forced on for " + str(self.getSibling("NumericEntryField").props.value) + " Minutes"
system.db.runPrepUpdate("INSERT INTO PERSPECTIVE_AUDIT_TABLE(ACTOR,ACTION) VALUES (?,?)", [userName,action])	

Anyways we really appreciate the help from the Ignition team and hope this can help other people. Thanks.

6 Likes

This was very handy. I was looking for a good way to handle tag events, this works good. Thanks.

Note that first-party Perspective auditing landed in 8.0.8 - login, logout, and security level changes included. Also, 8.0.12 (probably) will have a system.util.audit() function available in all scopes.

Can I ask why don’t you use the perspective audit table for manually insert data and create a new table?

Nader - you’re correct as of right now. However at the time we had the need, the perpective audit table was not yet available.

1 Like

Hi Paul

Is there any restriction on using system.db.runPrepUpdate("INSERT INTO audit_events …) in perspective?
Because I can insert new row in audit table with system.db.runPrepUpdate("INSERT INTO audit_events …) in vision but it seems it doesn’t work in perspective.
The reason I don’t use `system.util.audit()’ is this is npt available in 8.0.12.

Thanks for your post bro @richard.d.white