Name
sn_agent.AgentOSHelper
Description
No description available
Script
var AgentOSHelper = Class.create();
AgentOSHelper.prototype = {
initialize: function(log_id) {
this.LOG_ID = log_id;
},
/**
*
* format OS and OSversion
*
**/
getOsNameAndVersion: function(osName, osVersion) {
var version = this._formatOsVersion(osVersion);
return [this._lookupOsName(osName, version), version];
},
/**
* Drop .0 if the os_version field ends with one.
**/
_formatOsVersion: function(version) {
return version.replace(/\.0+$/,'');
},
/**
*
* OS Names returned from OSQuery or by executing commands are not always correctly formatted.
*
**/
_lookupOsName: function(osName, version) {
var osFormatted = null;
if (this._contains(osName, 'linux') || this._contains(osName, 'CentOS') || this._contains(osName, 'ubuntu'))
osFormatted = this._formatLinuxOSName(osName);
else if (this._contains(osName, 'mac'))
osFormatted = this._formatmacOSName(osName, version);
else
osFormatted = this._formatWindowsOSName(osName);
gs.debug(this.LOG_ID + " In AgentOSHelper.lookupOsName() returning correctly formatted operating "
+ "system for CMDB - " + osFormatted);
return osFormatted;
},
/**
*
* sample input: osName:Mac OS X and osVersion:10.15.7
* output: Mac OS 10 (OS/X)
*
**/
_formatmacOSName: function(osName, osVersion) {
var macOSMajorVersion = osVersion.split('.')[0];
return "Mac OS "+ macOSMajorVersion +" (OS/X)";
},
/**
*
* This is how discovery does today in
* Probe: Linux - Distribution
* Look at the post processor script [3p]
*
**/
_formatLinuxOSName: function(osName) {
if (this._contains(osName, 'red hat'))
return "Linux Red Hat";
else if (this._contains(osName, 'oracle'))
return "Linux Oracle";
else if (this._contains(osName, 'fedora'))
return "Linux Fedora";
else if (this._contains(osName, 'suse'))
return "Linux SuSE";
else if (this._contains(osName, 'centos stream'))
return "Linux CentOS Stream";
else if (this._contains(osName, 'centos'))
return "Linux CentOS";
else if (this._contains(osName, 'ubuntu'))
return "Linux Ubuntu";
else
return "GNU/Linux";
},
/**
*
* format and return the correct Windows OS name
*
**/
_formatWindowsOSName: function(name) {
return new global.WindowsOSNameHelper().formatWindowsOSName(name);
},
/**
*
* Util method to check for Substr
*
* Checks if the string is contained in the original/given String.
*
**/
_contains : function(mainStr, subStr) {
if (mainStr && subStr)
return mainStr.toLowerCase().includes(subStr.toLowerCase());
return false;
},
type: 'AgentOSHelper'
};
Sys ID
4d2116af5f55301069d74db3de7313a8