Hi
I would like to record the user's login and logout events in separate table in db rather than using audit events.
I have a python lib 'auditing' as:
def Login():
import datetime
user = system.tag.readBlocking("[System]Client/User/Username")[0].value
timestamp = system.date.now()
vLocation =system.tag.readBlocking("[System]Client/Network/Hostname")[0].value
query ="Insert into tvs_mes.tbl_logevents (user,Location,LoginTime,_createdDate,_createdUser) values(?,?,?,?,?)"
args= [user,vLocation,timestamp,timestamp,"ign"]
system.db.runPrepUpdate(query,args)
def Logout():
from time import strftime
user = system.tag.readBlocking("[System]Client/User/Username")[0].value
timestamp = system.date.now()
vLocation =system.tag.readBlocking("[System]Client/Network/Hostname")[0].value
params={"iLogout":timestamp,"iMUser":"update","iUser":user,"iLocation":vLocation}
system.db.runNamedQuery("Logging/UpdateLogout",params)
I tried calling out this function in session startup and shutdown. Unfortunately this did not work but the script worked as expected in the script console.
I even tried inserting data to this table from trigger of audit event and the written trigger in mysql is:
CREATE TRIGGER audit_events_trigger
AFTER INSERT ON audit_events
FOR EACH ROW
BEGIN
IF NEW.ACTION = 'Login Request' THEN
INSERT INTO tbl_logevents (user, Location, LoginTime, _createdDate, _createdUser)
VALUES (NEW.ACTOR, NEW.ACTOR_HOST, NEW.EVENT_TIMESTAMP, NOW(), 'ign');
ELSEIF NEW.ACTION = 'Logout Response' THEN
UPDATE tbl_logevents
SET LogoutTime = NEW.EVENT_TIMESTAMP,
ActiveTime = TIMEDIFF(NEW.EVENT_TIMESTAMP, LoginTime),
_modifiedDate = NOW(),
_modifiedUser = 'UPDATE'
WHERE user = NEW.ACTOR AND Location = NEW.ACTOR_HOST AND LogoutTime IS NULL;
END IF;
END;
Both the method did not worked as expected. Any ideas to achieve this?