Skip to content

Commit 15c0347

Browse files
authored
impersonationInsights.js
This script help to get the impersonator and impersonated user details, and duration of impersonation
1 parent 4beeead commit 15c0347

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Server-Side Components/Background Scripts/Retrieve Impersonation Insights/impersonationInsights.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
var impersonatorSysId = 'zane.sulikowski'; //Replace it with the userID of userfor whom we need to check impersonation details
1+
var impersonatorUserID = 'zane.sulikowski'; //Replace it with the user ID of user for whom we need to check impersonation details
22

3-
var checkUserId = new GlideRecord('sys_user');
4-
if (checkUserId.get('user_name', impersonatorSysId)) {
3+
var isUserPresent = new GlideRecord('sys_user');
4+
if (isUserPresent.get('user_name', impersonatorUserID)) {
55

6-
var eventsGR = new GlideRecord('sysevent');
7-
eventsGR.addEncodedQuery("name=impersonation.start^ORname=impersonation.end^parm1=" + impersonatorSysId + "^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");
8-
eventsGR.orderBy('sys_created_on');
9-
eventsGR.query();
6+
var queryEvents = new GlideRecord('sysevent');
7+
queryEvents.addEncodedQuery("name=impersonation.start^ORname=impersonation.end^parm1=" + impersonatorUserID + "^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");
8+
queryEvents.orderBy('sys_created_on');
9+
queryEvents.query();
1010

1111
//This object will hold all events grouped by impersonated user which is in parm2
1212
var userEvents = {};
1313

14-
while (eventsGR.next()) {
15-
var impersonatedId = eventsGR.getValue('parm2');
14+
while (queryEvents.next()) {
15+
var impersonatedId = queryEvents.getValue('parm2');
1616
if (!userEvents[impersonatedId])
1717
userEvents[impersonatedId] = [];
1818
userEvents[impersonatedId].push({
19-
name: eventsGR.getValue('name'),
20-
time: eventsGR.getValue('sys_created_on')
19+
name: queryEvents.getValue('name'),
20+
time: queryEvents.getValue('sys_created_on')
2121
});
2222
}
2323

@@ -55,6 +55,6 @@ for (var userId in userEvents) {
5555
var minutes = Math.floor((totalSeconds % 3600) / 60);
5656
var seconds = Math.floor(totalSeconds % 60);
5757

58-
gs.info(impersonatorSysId + " impersonated User: " + getUserName(userId) +
58+
gs.info(impersonatorUserID + " impersonated User: " + getUserName(userId) +
5959
" - Total Duration of impersonation is : " + hours + "hrs " + minutes + "min " + seconds + "sec (" + totalSeconds + "sec)");
6060
}

0 commit comments

Comments
 (0)