Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 18 additions & 171 deletions src/vSphereCollectionPlan.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,203 +29,50 @@ public function Init(): void

$oRestClient = new RestClient();

// Get last installation date
$sLastInstallDate = '0000-00-00 00:00:00';
try {
$aDatamodelResults = $oRestClient->Get('ModuleInstallation', ['name' => 'datamodel'], 'installed', 1);
if ($aDatamodelResults['code'] != 0 || empty($aDatamodelResults['objects'])) {
throw new Exception($aDatamodelResults['message'], $aDatamodelResults['code']);
}
$aDatamodel = current($aDatamodelResults['objects']);
$sLastInstallDate = $aDatamodel['fields']['installed'];
} catch (Exception $e) {
$sMessage = sprintf('Last Datamodel installation date is considered as not defined due to %s', $e->getMessage());
Utils::Log(LOG_ERR, $sMessage);
}

// Check if Virtualization Management Module is installed
Utils::Log(LOG_INFO, '---------- Check Virtualization Management Module installation ----------');
$this->bVirtualizationMgmtIsInstalled = false;
try {
$aResult = $oRestClient->Get('ModuleInstallation', "SELECT ModuleInstallation WHERE name = 'iTop-virtualization-mgmt' AND installed >= '$sLastInstallDate'", 'version, installed', 1);
if (array_key_exists('objects', $aResult) && isset($aResult['objects'])) {
$this->bVirtualizationMgmtIsInstalled = true;
$aObject = current($aResult['objects']);
$this->sVirtualizationMgmtVersion = $aObject['fields']['version'];
$sVirtualizationMgmtMessage = 'Virtualization Management Module version '.$this->sVirtualizationMgmtVersion.' is installed';
} else {
$this->sVirtualizationMgmtVersion = 'unknown';
$sVirtualizationMgmtMessage = 'Virtualization Management Module is not installed';
}
} catch (Exception $e) {
$sMessage = 'Virtualization Management Module\'s installed version cannot be fetched: '.$e->getMessage();
if (is_a($e, "IOException")) {
Utils::Log(LOG_ERR, $sMessage);
throw $e;
}
}
Utils::Log(LOG_INFO, $sVirtualizationMgmtMessage);
$this->bVirtualizationMgmtIsInstalled = Utils::CheckModuleInstallation('itop-virtualization-mgmt', false, $oRestClient);
$this->sVirtualizationMgmtVersion = $this->bVirtualizationMgmtIsInstalled ? Utils::GetModuleVersion('itop-virtualization-mgmt') : 'unknown';

// Check if Datacenter Management Module is installed
Utils::Log(LOG_INFO, '---------- Check Datacenter Management Module installation ----------');
$this->bDatacenterMgmtIsInstalled = false;
try {
$aResult = $oRestClient->Get('ModuleInstallation', "SELECT ModuleInstallation WHERE name = 'itop-datacenter-mgmt' AND installed >= '$sLastInstallDate'", 'version, installed', 1);
if (array_key_exists('objects', $aResult) && isset($aResult['objects'])) {
$this->bDatacenterMgmtIsInstalled = true;
$aObject = current($aResult['objects']);
$this->sDatacenterMgmtVersion = $aObject['fields']['version'];
$sDatacenterMgmtMessage = 'Datacenter Management Module version '.$this->sDatacenterMgmtVersion.' is installed';
} else {
$this->sDatacenterMgmtVersion = 'unknown';
$sDatacenterMgmtMessage = 'Datacenter Management Module is not installed';
}
} catch (Exception $e) {
$sMessage = 'Datacenter Management Module\'s installed version cannot be fetched: '.$e->getMessage();
if (is_a($e, "IOException")) {
Utils::Log(LOG_ERR, $sMessage);
throw $e;
}
}
Utils::Log(LOG_INFO, $sDatacenterMgmtMessage);
$this->bDatacenterMgmtIsInstalled = Utils::CheckModuleInstallation('itop-datacenter-mgmt', false, $oRestClient);
$this->sDatacenterMgmtVersion = $this->bDatacenterMgmtIsInstalled ? Utils::GetModuleVersion('itop-datacenter-mgmt') : 'unknown';

// Check if Advanced Storage Management Module is installed
Utils::Log(LOG_INFO, '---------- Check Advanced Storage Management Module installation ----------');
$this->bAdvanceStorageMgmtIsInstalled = false;
try {
$aResult = $oRestClient->Get('ModuleInstallation', "SELECT ModuleInstallation WHERE name = 'itop-storage-mgmt' AND installed >= '$sLastInstallDate'", 'version, installed', 1);
if (array_key_exists('objects', $aResult) && isset($aResult['objects'])) {
$this->bAdvanceStorageMgmtIsInstalled = true;
$aObject = current($aResult['objects']);
$this->sAdvanceStorageMgmtVersion = $aObject['fields']['version'];
$sAdvanceStorageMgmtMessage = 'Advanced Storage Management Module version '.$this->sAdvanceStorageMgmtVersion.' is installed';
} else {
$this->sAdvanceStorageMgmtVersion = 'unknown';
$sAdvanceStorageMgmtMessage = 'Advanced Storage Management Module is not installed';
}
} catch (Exception $e) {
$sMessage = 'Advanced Storage Management Module\'s installed version cannot be fetched: '.$e->getMessage();
if (is_a($e, "IOException")) {
Utils::Log(LOG_ERR, $sMessage);
throw $e;
}
}
Utils::Log(LOG_INFO, $sAdvanceStorageMgmtMessage);
$this->bAdvanceStorageMgmtIsInstalled = Utils::CheckModuleInstallation('itop-storage-mgmt', false, $oRestClient);
$this->sAdvanceStorageMgmtVersion = $this->bAdvanceStorageMgmtIsInstalled ? Utils::GetModuleVersion('itop-storage-mgmt') : 'unknown';

// Check if Data model for vSphere is installed
Utils::Log(LOG_INFO, '---------- Check Data model for vSphere installation ----------');
$this->bCbdVMwareDMIsInstalled = false;
try {
$aResult = $oRestClient->Get('ModuleInstallation', "SELECT ModuleInstallation WHERE name = 'combodo-vsphere-datamodel' AND installed >= '$sLastInstallDate'", 'version, installed', 1);
if (array_key_exists('objects', $aResult) && isset($aResult['objects'])) {
$this->bCbdVMwareDMIsInstalled = true;
$aObject = current($aResult['objects']);
$this->sCbdVMwareDMVersion = $aObject['fields']['version'];
$sCbdVMwareDMMessage = 'Data model for vSphere extension version '.$this->sCbdVMwareDMVersion.' is installed';
} else {
$this->sCbdVMwareDMVersion = 'unknown';
$sCbdVMwareDMMessage = 'Data model for vSphere extension is not installed';
}
} catch (Exception $e) {
$sMessage = 'Data model for vSphere extension\'s installed version cannot be fetched: '.$e->getMessage();
if (is_a($e, "IOException")) {
Utils::Log(LOG_ERR, $sMessage);
throw $e;
}
}
Utils::Log(LOG_INFO, $sCbdVMwareDMMessage);
$this->bCbdVMwareDMIsInstalled = Utils::CheckModuleInstallation('combodo-vsphere-datamodel', false, $oRestClient);
$this->sCbdVMwareDMVersion = $this->bCbdVMwareDMIsInstalled ? Utils::GetModuleVersion('combodo-vsphere-datamodel') : 'unknown';

// Check if TeemIp is installed or not
Utils::Log(LOG_INFO, '---------- Check TeemIp installation ----------');
$this->bTeemIpIsInstalled = false;
try {
$aResult = $oRestClient->Get('ModuleInstallation', "SELECT ModuleInstallation WHERE name = 'teemip-ip-mgmt' AND installed >= '$sLastInstallDate'", 'version, installed', 1);
if (array_key_exists('objects', $aResult) && isset($aResult['objects'])) {
$this->bTeemIpIsInstalled = true;
$aObject = current($aResult['objects']);
$this->sTeemIpVersion = $aObject['fields']['version'];
$sTeemIpMessage = 'TeemIp version ' . $this->sTeemIpVersion . ' is installed';
} else {
$this->sTeemIpVersion = 'unknown';
$sTeemIpMessage = 'TeemIp is NOT installed';
}
} catch (Exception $e) {
$sMessage = 'TeemIp is considered as NOT installed due to: ' . $e->getMessage();
if (is_a($e, "IOException")) {
Utils::Log(LOG_ERR, $sMessage);
throw $e;
}
}
Utils::Log(LOG_INFO, $sTeemIpMessage);
// Check if TeemIP is installed or not
Utils::Log(LOG_INFO, '---------- Check TeemIP installation ----------');
$this->bTeemIpIsInstalled = Utils::CheckModuleInstallation('teemip-ip-mgmt', false, $oRestClient);
$this->sTeemIpVersion = $this->bTeemIpIsInstalled ? Utils::GetModuleVersion('teemip-ip-mgmt') : 'unknown';

// If TeemIp should be considered,
$this->bTeemIpIpDiscoveryIsInstalled = false;
$this->bTeemIpNMEIsInstalled = false;
$this->bTeemIpZoneMgmtIsInstalled = false;
$aTeemIpDiscovery = Utils::GetConfigurationValue('teemip_discovery', []);
if ($this->bTeemIpIsInstalled && !empty($aTeemIpDiscovery) && array_key_exists('enable', $aTeemIpDiscovery) && ($aTeemIpDiscovery['enable'] == 'yes')) {
Utils::Log(LOG_INFO, 'TeemIp should be considered.');
Utils::Log(LOG_INFO, 'TeemIP should be considered.');
// Record discovery parameters
$this->bCollectIps = array_key_exists('collect_ips', $aTeemIpDiscovery) ? $aTeemIpDiscovery['collect_ips'] : 'no';
$this->sDefaultIpStatus = array_key_exists('default_ip_status', $aTeemIpDiscovery) ? $aTeemIpDiscovery['default_ip_status'] : 'allocated';
$this->bManageIpv6 = array_key_exists('manage_ipv6', $aTeemIpDiscovery) ? $aTeemIpDiscovery['manage_ipv6'] : 'no';
$this->bManageLogicalInterfaces = array_key_exists('manage_logical_interfaces', $aTeemIpDiscovery) ? $aTeemIpDiscovery['manage_logical_interfaces'] : 'no';

// Check if TeemIp IpDiscovery is installed or not
$oRestClient = new RestClient();
try {
$aResult = $oRestClient->Get('ModuleInstallation', "SELECT ModuleInstallation WHERE name = 'teemip-ip-discovery' AND installed >= '$sLastInstallDate'", 'version, installed', 1);
if (array_key_exists('objects', $aResult) && isset($aResult['objects'])) {
$this->bTeemIpIpDiscoveryIsInstalled = true;
Utils::Log(LOG_INFO, 'TeemIp IP Discovery is installed');
} else {
Utils::Log(LOG_INFO, 'TeemIp IP Discovery is NOT installed');
}
} catch (Exception $e) {
$sMessage = 'TeemIp IP Discovery is considered as NOT installed due to: ' . $e->getMessage();
if (is_a($e, "IOException")) {
Utils::Log(LOG_ERR, $sMessage);
throw $e;
}
}

// Check if TeemIp Network Management Extended is installed or not
$oRestClient = new RestClient();
try {
$aResult = $oRestClient->Get('ModuleInstallation', "SELECT ModuleInstallation WHERE name = 'teemip-network-mgmt-extended' AND installed >= '$sLastInstallDate'", 'version, installed', 1);
if (array_key_exists('objects', $aResult) && isset($aResult['objects'])) {
$this->bTeemIpNMEIsInstalled = true;
Utils::Log(LOG_INFO, 'TeemIp Network Management Extended is installed');
} else {
Utils::Log(LOG_INFO, 'TeemIp Network Management Extended is NOT installed');
}
} catch (Exception $e) {
$sMessage = 'TeemIp Network Management Extended is considered as NOT installed due to: ' . $e->getMessage();
if (is_a($e, "IOException")) {
Utils::Log(LOG_ERR, $sMessage);
throw $e;
}
}

// Check if TeemIp Zone Management is installed or not
$oRestClient = new RestClient();
try {
$aResult = $oRestClient->Get('ModuleInstallation', "SELECT ModuleInstallation WHERE name = 'teemip-zone-mgmt' AND installed >= '$sLastInstallDate'", 'version, installed', 1);
if (array_key_exists('objects', $aResult) && isset($aResult['objects'])) {
$this->bTeemIpZoneMgmtIsInstalled = true;
Utils::Log(LOG_INFO, 'TeemIp Zone Management extension is installed');
} else {
Utils::Log(LOG_INFO, 'TeemIp Zone Management extension is NOT installed');
}
} catch (Exception $e) {
$sMessage = 'TeemIp Zone Management extension is considered as NOT installed due to: ' . $e->getMessage();
if (is_a($e, "IOException")) {
Utils::Log(LOG_ERR, $sMessage);
throw $e;
}
}
// Check if TeemIP modules are installed
$this->bTeemIpIpDiscoveryIsInstalled = Utils::CheckModuleInstallation('teemip-ip-discovery', false, $oRestClient);
$this->bTeemIpNMEIsInstalled = Utils::CheckModuleInstallation('teemip-network-mgmt-extended', false, $oRestClient);
$this->bTeemIpZoneMgmtIsInstalled = Utils::CheckModuleInstallation('teemip-zone-mgmt', false, $oRestClient);
} else {
Utils::Log(LOG_INFO, 'As requested, TeemIp will not be considered.');
Utils::Log(LOG_INFO, 'As requested, TeemIP will not be considered.');
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/vSphereCollector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

class vSphereCollector extends ConfigurableCollector
{

/** @var vSphereCollectionPlan */
protected $oCollectionPlan;

/**
Expand Down
6 changes: 1 addition & 5 deletions src/vSphereIPv4AddressCollector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public function AttributeIsOptional($sAttCode)
if ($sAttCode == 'responds_to_scan') return true;
if ($sAttCode == 'services_list') return true;
if ($sAttCode == 'view_id') return true;
if ($sAttCode == 'ipconfig_id') {
if (strstr($this->oCollectionPlan->GetTeemIpVersion(), '.', true) < '3') {
return true;
}
}
if ($sAttCode == 'ipconfig_id') return !Utils::CheckModuleInstallation('teemip-ip-mgmt/3.0.0');

return parent::AttributeIsOptional($sAttCode);
}
Expand Down
6 changes: 1 addition & 5 deletions src/vSphereIPv6AddressCollector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public function AttributeIsOptional($sAttCode)
if ($sAttCode == 'responds_to_scan') return true;
if ($sAttCode == 'services_list') return true;
if ($sAttCode == 'view_id') return true;
if ($sAttCode == 'ipconfig_id') {
if (strstr($this->oCollectionPlan->GetTeemIpVersion(), '.', true) < '3') {
return true;
}
}
if ($sAttCode == 'ipconfig_id') return !Utils::CheckModuleInstallation('teemip-ip-mgmt/3.0.0');

return parent::AttributeIsOptional($sAttCode);
}
Expand Down
33 changes: 5 additions & 28 deletions src/vSphereVirtualMachineCollector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,11 @@ public function AttributeIsOptional($sAttCode)
{
if ($sAttCode == 'services_list') return true;
if ($sAttCode == 'providercontracts_list') return true;

if ($this->oCollectionPlan->IsAdvanceStorageMgmtInstalled()) {
if ($sAttCode == 'logicalvolumes_list') return false;
} else {
if ($sAttCode == 'logicalvolumes_list') return true;
}

if ($this->oCollectionPlan->IsCbdVMwareDMInstalled()) {
if ($sAttCode == 'uuid') return false;
if ($sAttCode == 'power_state') {
if (!version_compare($this->oCollectionPlan->GetCbdVMwareDMVersion(), '1.0.0', '>' )) {
return true;
} else {
return false;
}
}
} else {
if ($sAttCode == 'uuid') return true;
if ($sAttCode == 'power_state') return true;
}

if ($this->oCollectionPlan->IsTeemIpInstalled()) {
if ($sAttCode == 'managementip') return true;
if ($sAttCode == 'managementip_id') return false;
} else {
if ($sAttCode == 'managementip') return false;
if ($sAttCode == 'managementip_id') return true;
}
if ($sAttCode == 'logicalvolumes_list') return $this->oCollectionPlan->IsAdvanceStorageMgmtInstalled();
if ($sAttCode == 'uuid') return !$this->oCollectionPlan->IsCbdVMwareDMInstalled();
if ($sAttCode == 'power_state') return !Utils::CheckModuleInstallation('combodo-vsphere-datamodel/1.1.0');
if ($sAttCode == 'managementip') return $this->oCollectionPlan->IsTeemIpInstalled();
if ($sAttCode == 'managementip_id') return !$this->oCollectionPlan->IsTeemIpInstalled();

return parent::AttributeIsOptional($sAttCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ public function CheckToLaunch(array $aOrchestratedCollectors): bool
return false;
}
// V 1.1.0 or greater of the extension must be installed
$sCbdVMwareDMVersion = $this->oCollectionPlan->GetCbdVMwareDMVersion();
if (!version_compare($sCbdVMwareDMVersion, '1.0.0', '>' )) {
Utils::Log(LOG_INFO, '> vSpherelnkDatastoreToVirtualMachineCollector will not be launched as version '.$sCbdVMwareDMVersion.' of Data model for vSphere is lower than 1.1.0');
if (!Utils::CheckModuleInstallation('combodo-vsphere-datamodel/1.1.0')) {
Utils::Log(LOG_INFO, '> vSpherelnkDatastoreToVirtualMachineCollector will not be launched as version of Data model for vSphere is lower than 1.1.0');
return false;
}
// VM discovery should be made first
Expand Down