From eed1ea8926e4b478d3751a81cce7d11119eb55b5 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Mon, 17 Jun 2024 14:45:08 +0200 Subject: [PATCH] Update data-collector-base to 1.4.0 --- .github/workflows/package.yml | 2 +- module.snmp-discovery-collector.php | 2 +- src/SnmpDiscoveryCollector.class.inc.php | 34 +----------------------- 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index f2c1b9d..ddb3662 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -12,7 +12,7 @@ jobs: uses: actions/checkout@v4 with: repository: Combodo/itop-data-collector-base - ref: 1.3.1 + ref: 1.4.0 sparse-checkout: | conf core diff --git a/module.snmp-discovery-collector.php b/module.snmp-discovery-collector.php index d8f81be..2e916ea 100755 --- a/module.snmp-discovery-collector.php +++ b/module.snmp-discovery-collector.php @@ -7,6 +7,6 @@ SetupWebPage::AddModule( __FILE__, // Path to the current file, all other file names are relative to the directory containing this file - 'snmp-discovery-collector/1.3.0', + 'snmp-discovery-collector/1.3.1', [] ); diff --git a/src/SnmpDiscoveryCollector.class.inc.php b/src/SnmpDiscoveryCollector.class.inc.php index 7f5f611..11d41ef 100644 --- a/src/SnmpDiscoveryCollector.class.inc.php +++ b/src/SnmpDiscoveryCollector.class.inc.php @@ -27,7 +27,7 @@ public function Init(): void parent::Init(); // Check if modules are installed - static::CheckModuleInstallation('sv-snmp-discovery', true); + Utils::CheckModuleInstallation('sv-snmp-discovery', true); // Load SNMP discovery application settings $this->LoadApplicationSettings(); @@ -132,38 +132,6 @@ protected function HeaderIsAllowed(string $sHeader): bool return array_key_exists($sHeader, $this->aFields); } - /** - * Check if the given module is installed in iTop - * - * @param string $sName Name of the module to be found - * @param bool $bRequired Whether to throw exceptions when module not found - * @return bool True when the given module is installed, false otherwise - * @throws Exception When the module is required but could not be found - * - * @todo Workaround needed until PR merged in data-collector-base - * @link https://github.com/Combodo/itop-data-collector-base/pull/39 - */ - protected static function CheckModuleInstallation(string $sName, bool $bRequired = false): bool - { - $oRestClient = new RestClient(); - try { - $aResults = $oRestClient->Get('ModuleInstallation', ['name' => $sName], 'name,version'); - if ($aResults['code'] != 0 || empty($aResults['objects'])) { - throw new Exception($aResults['message'], $aResults['code']); - } - $aObject = current($aResults['objects']); - Utils::Log(LOG_DEBUG, sprintf('iTop module %s version %s is installed.', $aObject['fields']['name'], $aObject['fields']['version'])); - } catch (Exception $e) { - $sMessage = sprintf('%s iTop module %s is considered as not installed due to: %s', $bRequired ? 'Required' : 'Optional', $sName, $e->getMessage()); - if ($bRequired) throw new Exception($sMessage, 0, $e); - else { - Utils::Log(LOG_INFO, $sMessage); - return false; - } - } - return true; - } - /** * Load the SNMP discovery application settings (ID and subnet to discover) * @return void