How can you capture the "last logged in user" User ID

jwelton
Tera Contributor

Hello community!

We want to capture the login User ID of the last person to log into a discovered CI even if it does not match to a corresponding record in the Users table (sys_user).

It appears that Discovery will discover the Username (login ID, User ID, etc.) of the person who last logged into the discovered CI and then populate the "Assigned to" field with the "Name" of the record that matches the corresponding "User ID" in the Users table. If a matching record is not found, the field is blank. We want to capture the discovered login name even it is not in the User table.

Does anyone know have any ideas?

Thanks in advance,
Jeff

9 REPLIES 9

jwelton
Tera Contributor

We added the field to the cmdb_ci_computer table.


shane_davis
Tera Expert

I am looking at the Sensor "Windows - OS Information" as it is out of the box and would like to report on the last logged on user as discussed above. Unfortunately, I'm very new to scripting and not sure exactly what steps to complete the task in. My assumption is and the default script is below. Any help will be appreciated.

1. Create a string field on the cmdb_ci_computer table called u_lastuserid
2. Modify the Sensor "Windows - OS Information"
.....this sensor is currently active with locations being discovered.
3. It will work!
`````````````````````````````````````````````````````````````````
new DiscoverySensor({
process: function(result) {
this.parseResult(result);
},

parseResult: function(result) {
current.os_version = result.Win32_OperatingSystem.Version;
current.os_service_pack = result.Win32_OperatingSystem.CSDVersion;

var man = result.Win32_ComputerSystem.Manufacturer;
var mod = result.Win32_ComputerSystem.Model;

var mm = MakeAndModel.fromNames(man, mod);
current.manufacturer = mm.getManufacturerSysID();
current.model_id = mm.getModelNameSysID();
current.short_description = result.Win32_OperatingSystem.Description;

// Contrary to what the name implies, this returns *OS* address width, not CPU
var processors = g_array_util.ensureArray(result.Win32_Processor);
current.os_address_width = processors[0].AddressWidth;

this.setAssignedTo(result);
},

setAssignedTo: function(result) {
var userName = result.Win32_ComputerSystem.UserName;

if (!gs.nil(userName)) {
var x = userName.indexOf("\\");

if (x > -1)
userName = userName.substring(x + 1);

var nameField = gs.getProperty('glide.discovery.assigned_user_match_field', "user_name");
var userID = GlideUser.getSysId(nameField, userName);

var atOverwrite = JSUtil.toBoolean(gs.getProperty('glide.wmi.assigned_to_always_overwrite', "true"));
if (!atOverwrite)
if (this._isAssignedToFilled())
return;

current.assigned_to = userID;
}
},

/*
* Is the assigned_to field already populated? Return true if yes; false if no.
*/
_isAssignedToFilled: function() {
var compGr = this.getCmdbRecord();
if (JSUtil.notNil(compGr.assigned_to + ''))
return true;

return false;
},

type: "DiscoverySensor"
});


Make sure you update the OS Information probe to have the new sensor respond to it though.


Anjali Arora
Tera Expert

Hi, 

 

We want to achieve the same requirement but we are London and Discovery is using the "Windows OS - Desktops" pattern.

I have added an extension to populate my custom field "Logged in user"  from the "Assigned to" field. But it gets populated with value returned from "Win32_ComputerSystem.UserName".

I am unable to find where exactly Discovery strips user name from "Win32_ComputerSystem.UserName" before populating the Assigned To field. Can you please guide me?

 

Regards

Anjali Arora

p_s_kumar
Tera Contributor

Hi Anjali,

Were you able to get this information from Discovery. I have the same requirement to capture the last logged in user name and we are in Newyork. Any infor  will be of great help.

 

Thank you