I want to get notification/event on the ejabberd server whenever a client goes online or offline (connection status changes) as I want to take some action based on it. So my question is how to achieve this? Do I need to add/modify in the ejabberd code for this or there are modules available for this?
You will have to write some
You will have to write some source code. Reading what you want, I think the most similar module is mod_logsession, that is included in ejabberd-contrib git repository. You could first modify it to log the successful connection/disconnections. And later modify it to do what you want it to do.