Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

determine which node a user is logged into?

bbarnard
Kilo Contributor

I would like to be able to determine which node a user is logged into? I'm able to see logged in users (v_user_session) but if I understand correctly this list only contains user sessions on the node that I'm currently logged into. Is there a way to determine which node a user is logged into (which node they have an active session on)?

 

-Thanks

9 REPLIES 9

Hi Brian,



Have you found something around this?



BR
Marc.


andrew_lawlor
Giga Expert

I think a simple way to do this for an individual user is to query the syslog_transaction table. Here's a basic script that should suite your needs. You can add it to a Script Include and call it from a UI Action on the User table to provide a quick way to find a user's node. Just keep in mind that any given user can have multiple sessions open with different browsers -- so you might want to use the session field of the syslog_transaction table to account for this.



function findUserNode(userID) {



if (userID)


  {


  var logs = new GlideRecord('syslog_transaction');


  logs.addQuery('sys_created_by', userID);


  logs.addQuery('sys_created_on', '>', gs.minutesAgo(15)); // This is arbitrary


    // You should add an order by here -- use sys_created_on    


  logs.setLimit(1);


  logs.query();


  if (logs.next())   // change to a loop if you want nodes for multiple sessions.


  {


  var node = logs.system_id.toString();


  var num = node.indexOf(':');


  var nodeName = node.substring(parseInt(num + 1), parseInt(node.length));


  gs.addInfoMessage("User " + userID + " is currently logged into node: " + nodeName);


  }


  else


  {


  gs.addInfoMessage("User " + userID + "is not currently logged in");


  }


  }


}


I'm working on something similar, and after thinking about it for awhile, we can get much more useful and relevant information using GlideAggregate instead:



function getSessionInfo(userID) {


if (userID)


{


var ga = new GlideAggregate('syslog_transaction');


ga.addQuery('sys_created_on', '>', gs.minutesAgo(15)); // again, this is arbitrary.


ga.addQuery('sys_created_by', userID);


ga.groupBy('session'); // This gives us relevant data for each session -- one user might have multiple sessions going.


ga.groupBy('system_id'); // Also grouping by node.


ga.addAggregate('AVG', 'network_time'); // Additional info, if you want it.


ga.addAggregate('AVG', 'response_time');


ga.query();




while (ga.next())


{


gs.print("Data for session ID: " + ga.session);


gs.print("User: " + userID);


gs.print("Node: " + ga.system_id);


var secs = (parseFloat(ga.getAggregate('AVG', 'response_time')))/1000;


gs.print("AVG Response Time: " + secs);



} // end while


} // end if


}



Something like this would work well in a UI action (infomessage), homepage widget or as its own UI Page/GlideDialogWindow.



Andrew


nadiarussell
Tera Contributor

If your just looking to find what node a user is on you can check it 2 different ways.



        1. Have the user type stats.do in the left nav. Then ask them for the cluster node name.


        2. Under System Diagnostics > Active Transactions (All Nodes) add the user field to your list view and search for the user that way.



Nadia


San18
ServiceNow Employee
ServiceNow Employee

Screen Shot 2018-01-03 at 2.32.46 PM.png



Transaction(All user ) >


System Id will tell you node   , created by will be the user