How to identify all the currently logged in Users and having a valid session ID?

Rizwan Shaikh
Mega Guru

I am working on a requirement where I need to know if a user is currently logged into the system and has a valid session.

I know How to check for the currently logged in user. I want to know for a specific user.

  1. Lets say I have a X user and want to know he/she is currently logged into the system. How to achieve this?
  2. Also lets say I have a session ID. How to check if its still valid and not expired?

I have tried querying the "v_user_session_list" but it gives me only the current node users.

Any other way to know for overall users?

Help is much appreciated. Thanks!

 

 

1 ACCEPTED SOLUTION

Rizwan Shaikh
Mega Guru

Thanks guys, I was able to figure it out.

The table is sys_user_session table

Below URL will give you all the currently actively logged in User with a valid session ID

https://your_instance_name.service-now.com/sys_user_session_list.do?sysparm_query=nameISNOTEMPTY%5EinvalidatedISEMPTY%5Elast_accessedONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()%5Ename!%3Dguest%5EORname%3DNULL&sysparm_first_row=1&sysparm_view=

To cross verify the count use the below script.
var total_users = 0;
var diag = new Diagnostics();

while (diag.nextNode()) {
    var diagNode = diag.getNode();
    var ss = diagNode.stats.sessionsummary;

    if (ss) {
        gs.print(JSON.stringify(ss));
        total_users += parseInt(diagNode.stats.sessionsummary["@logged_in"]);
    }
}

gs.info(total_users);

View solution in original post

5 REPLIES 5

Rizwan Shaikh
Mega Guru

Thanks guys, I was able to figure it out.

The table is sys_user_session table

Below URL will give you all the currently actively logged in User with a valid session ID

https://your_instance_name.service-now.com/sys_user_session_list.do?sysparm_query=nameISNOTEMPTY%5EinvalidatedISEMPTY%5Elast_accessedONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()%5Ename!%3Dguest%5EORname%3DNULL&sysparm_first_row=1&sysparm_view=

To cross verify the count use the below script.
var total_users = 0;
var diag = new Diagnostics();

while (diag.nextNode()) {
    var diagNode = diag.getNode();
    var ss = diagNode.stats.sessionsummary;

    if (ss) {
        gs.print(JSON.stringify(ss));
        total_users += parseInt(diagNode.stats.sessionsummary["@logged_in"]);
    }
}

gs.info(total_users);