RE: Client Audit

Amos Fong, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Hi there,
I want to track the action of the user / client . For this lieray audit software is available but it is only for  enterprise edition. But i want to achieve this thing in liferay 6.2 community edition. Can anyone please help me out.
​​​​​​​ 
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Vivek,

You are right, the audit plugin is only EE for 6.2. With that said, if you look at the code base you will find that the plumbing for the auditing feature is there, and the pieces that are missing are easily created. There is a destination on the message bus called liferay/audit ... but it has no message listeners (I think, I'm going from memory here). You need to --

1. Create message listeners and register them with the destination
2. Create processor classes based on how you want to store the records (database? file? etc)
3. If you choose to use the DB, then you need to create a service builder plugin to create the tables and services you will use in your processor to save events
4. You need to create a control panel plugin that will be used to read the audit records (if you need to do this)

.. it's not a small task, but pretty straight forward and no more than a day or two (depending on how fancy you want to make it).
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Thanks Andrew,
I am using model listeners for the sake of  storing info on some action like create, update,etc. But i am not getting how to track the complete activity of user,i.e, when he goes from one page to another also. I thought i could do that using event listeners like onClick() that we have on JS, but how can i do that on liferay since as i know we don't have any listener like onClick() in liferay. Pleasae help emoticon
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Vivek,

Well, I'm not sure that you should be doing that in the portal to be honest. I'll explain how you CAN in a second, but I think you should consider your architecture a little. You are, potentially, add ing a lot of load to your app server and your database (assuming you are storing these in a db) because you are tasking LIFERAY with all the detection and recording activities. A system requiring this much auditing would, from my experience, have proxies higher up the nextwork path that would be responsible to tracking this kind of stuff. For example, if you have an apache or nginx in front of your Liferay server, then you can use the access logs as a way to track all the requested paths. 

But ... if you MUST ask Liferay to do it.

There are a few properties that you can use that might be all you need for out of the box.
#
# Set this to true to track user clicks in memory for the duration of a
# user's session. Setting this to true allows you to view all live sessions
# in the Admin portlet.
#
session.tracker.memory.enabled=true

#
# Set this to true to track user clicks in the database after a user's
# session is invalidated. Setting this to true allows you to generate usage
# reports from the database. Use this cautiously because this will store a
# lot of usage data.
#
session.tracker.persistence.enabled=false

#
# Set this to true to convert the tracked paths to friendly URLs.
#
session.tracker.friendly.paths.enabled=false

Now they come with performance costs, so again, consider them and their values carefully. Now, if you need your records to be stored in a specific format or location or whatever, then you may have to opt for a custom solution. For this scenario, I think what you would want here is a static portlet. So you would create a portlet and then configure this property in your portal-ext.


... with this property configured (with your portlet name) the porlet will automatically live on every page. The view for the portlet can be empty, such that the portlet is on the page but since it doesn't render any content, you won't "see it" per se. Now, in terms of the recording, if you want just the pages, then I think you could probably get away with just using the render method and in that method get the user out of the request (be careful ... there is user and a REAL user, if you are supporting impersonation then you might want to grab both) and then record the record. If they refresh the same page, let's say user profile, then you would see 

userid       page
1234         home
1234         user-profile
1234         user-profile

in your trail. This is a pretty basic record though. I mean, there are so many more options to consider. The real user, as I said a moment ago, but also in a clustered environment you might want to record which node they are on, their source ip, etc.

Regardless, I would still consider wiring up the handlers and using the message bus so that you can record the records asynchronously and not block the request. It would also allow you to more easily buffer and pool records so that, for example, you collect 50 records at a time and then do a batch write rather than hammering your database with a write for ever page requested (same goes for file I/O and not thrashing your HDD)
​​​​​​​

Anyway, that's one way to do it -- with a poor mans audit. 
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Hi Andrew,
After much attempts i came to knew about usertracker. So i decided to get the info using usertracker service. But in that when i am using functions like getUserId , GerFriendlyURL() , etc   . it is giving  nullpointer exception. But when i am  giving the user id , etc  by my self  then it is working fine and storing the data in the database of usertracker table. But i am not getting why it is showing null Pointer Exception for getting those values dynamically !!
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Vivek,

​​​​​​​Are you referring to the live.session feature that Liferay has? If you are, you made sure to enable the property required to make it active in your portal ext?
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
HI Andrew!!I am now using the UserTracker function of liferay. It seemed to work well but it has one problem !! it is showing NullPointerException when I am using user.getUserId() or themeDisplay.getUserId(). Then i to check it printed the value of System.out.print(user) and System.out.print(themeDisplay) . It printed "null"  which means both the user and theme Display objects  are empty that's why it gave error  for themeDisplay.getUserId(). So please help me resolve this issue  in getting the values of userid , groupid,etc.  
thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Vivek Mehta
I want to track the action of the user / client . For this lieray audit software is available but it is only for  enterprise edition. But i want to achieve this thing in liferay 6.2 community edition. Can anyone please help me out.
​​​​​​​ 
In case any part of this answer to your identical question (posted 7 hours before your repeated post) wasn't enough: Please do not simply repost the same words but post a reply so that we can keep the same topic together.

We're here to help out, unless we see that there's no effort put into questions, or they're repeated verbatim without additional clarification, or they're crossposted (without links between the questions) all over the internet.
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
sorry everyone.
this question went to spam earlier. so i posted that question again.