Skip to content

Commit

Permalink
Update data-collector-base to 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipska committed Jun 17, 2024
1 parent 19d249d commit eed1ea8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion module.snmp-discovery-collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
[]
);
34 changes: 1 addition & 33 deletions src/SnmpDiscoveryCollector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eed1ea8

Please sign in to comment.