-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] Added compatibility for Zabbix 5.2 and 5.4
- Loading branch information
1 parent
57c7fac
commit e666d53
Showing
7 changed files
with
76 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Zabbix CSV Import Frontend Module | ||
* | ||
* @version 5.0.2 | ||
* @version 5.0.0 | ||
* @author Wolfgang Alper <[email protected]> | ||
* @copyright IntelliTrend GmbH, https://www.intellitrend.de | ||
* @license GNU Lesser General Public License v3.0 | ||
|
@@ -19,6 +19,7 @@ | |
|
||
use APP; | ||
use CController as CAction; | ||
use CWebUser; | ||
|
||
/** | ||
* Please see Core\CModule class for additional reference. | ||
|
@@ -29,6 +30,10 @@ class Module extends \Core\CModule { | |
* Initialize module. | ||
*/ | ||
public function init(): void { | ||
// Only super admins should see the menu entry | ||
if (CWebUser::getType() != USER_TYPE_SUPER_ADMIN) { | ||
return; | ||
} | ||
// Initialize main menu (CMenu class instance). | ||
APP::Component()->get('menu.main')->findOrAdd(_('Configuration'))->getSubmenu()->add((new \CMenuItem(_('Host CSV Importer')))->setAction('ichi.import')); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Zabbix CSV Import Frontend Module | ||
* | ||
* @version 5.0.2 | ||
* @version 5.0.0 | ||
* @author Wolfgang Alper <[email protected]> | ||
* @copyright IntelliTrend GmbH, https://www.intellitrend.de | ||
* @license GNU Lesser General Public License v3.0 | ||
|
@@ -23,6 +23,8 @@ | |
use CRoleHelper; | ||
use CUploadFile; | ||
use API; | ||
use CSession; // 5.0.0 | ||
use CSessionHelper; // 5.2.0+ | ||
|
||
/** | ||
* Host CSV importer module action. | ||
|
@@ -61,6 +63,8 @@ class CsvHostImport extends CAction { | |
8 => 'A PHP extension stopped the file upload.', | ||
]; | ||
|
||
const HOSTLIST_KEY = 'ichi.hostlist'; | ||
|
||
private $hostlist = []; | ||
private $step = 0; | ||
|
||
|
@@ -101,7 +105,11 @@ protected function checkInput(): bool { | |
* @return bool | ||
*/ | ||
protected function checkPermissions(): bool { | ||
return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); | ||
if (version_compare(ZABBIX_VERSION, '5.4.0', '>=')) { | ||
return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); | ||
} else { | ||
return ($this->getUserType() == USER_TYPE_SUPER_ADMIN); | ||
} | ||
} | ||
|
||
private function csvParse(): bool { | ||
|
@@ -261,6 +269,39 @@ private function importHosts(): bool { | |
return true; | ||
} | ||
|
||
private function loadSession() { | ||
if (version_compare(ZABBIX_VERSION, '5.2.0', '>=')) { | ||
if (!CSessionHelper::has(self::HOSTLIST_KEY)) { | ||
return false; | ||
} | ||
$this->hostlist = CSessionHelper::get(self::HOSTLIST_KEY); | ||
return true; | ||
} else { | ||
if (!CSession::keyExists(self::HOSTLIST_KEY)) { | ||
return false; | ||
} | ||
$this->hostlist = CSession::getValue(self::HOSTLIST_KEY); | ||
return true; | ||
} | ||
} | ||
|
||
private function saveSession() { | ||
if (version_compare(ZABBIX_VERSION, '5.2.0', '>=')) { | ||
CSessionHelper::set(self::HOSTLIST_KEY, $this->hostlist); | ||
} else { | ||
CSession::setValue(self::HOSTLIST_KEY, $this->hostlist); | ||
} | ||
} | ||
|
||
private function clearSession() { | ||
if (version_compare(ZABBIX_VERSION, '5.2.0', '>=')) { | ||
CSessionHelper::unset([self::HOSTLIST_KEY]); | ||
} else { | ||
CSession::unsetValue([self::HOSTLIST_KEY]); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Prepare the response object for the view. Method called by Zabbix core. | ||
* | ||
|
@@ -287,17 +328,16 @@ protected function doAction() { | |
if (!$this->csvParse()) { | ||
$this->step = 0; | ||
} | ||
$_SESSION['ichi.hostlist'] = $this->hostlist; | ||
$this->saveSession(); | ||
break; | ||
case 2: | ||
// import | ||
if (!isset($_SESSION['ichi.hostlist'])) { | ||
if (!$this->loadSession()) { | ||
error(_('Missing host list in session.')); | ||
break; | ||
} | ||
$this->hostlist = $_SESSION['ichi.hostlist']; | ||
if ($this->importHosts()) { | ||
unset($_SESSION['ichi.hostlist']); | ||
$this->clearSession(); | ||
} | ||
break; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Zabbix CSV Import Frontend Module | ||
* | ||
* @version 5.0.2 | ||
* @version 5.0.0 | ||
* @author Wolfgang Alper <[email protected]> | ||
* @copyright IntelliTrend GmbH, https://www.intellitrend.de | ||
* @license GNU Lesser General Public License v3.0 | ||
|
@@ -56,7 +56,11 @@ protected function checkInput(): bool { | |
* @return bool | ||
*/ | ||
protected function checkPermissions(): bool { | ||
return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); | ||
if (version_compare(ZABBIX_VERSION, '5.4.0', '>=')) { | ||
return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_GENERAL); | ||
} else { | ||
return ($this->getUserType() == USER_TYPE_SUPER_ADMIN); | ||
} | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Zabbix CSV Import Frontend Module | ||
* | ||
* @version 5.0.2 | ||
* @version 5.0.0 | ||
* @author Wolfgang Alper <[email protected]> | ||
* @copyright IntelliTrend GmbH, https://www.intellitrend.de | ||
* @license GNU Lesser General Public License v3.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/** | ||
* Zabbix CSV Import Frontend Module | ||
* | ||
* @version 5.0.2 | ||
* @version 5.0.0 | ||
* @author Wolfgang Alper <[email protected]> | ||
* @copyright IntelliTrend GmbH, https://www.intellitrend.de | ||
* @license GNU Lesser General Public License v3.0 | ||
|
@@ -66,9 +66,10 @@ | |
); | ||
$hostlist = $data['hostlist']; | ||
|
||
$table = (new CTable()) | ||
->setId('hostlist-table') | ||
->addClass(ZBX_STYLE_VALUEMAP_LIST_TABLE); | ||
$table = (new CTable())->setId('hostlist-table'); | ||
if (defined('ZBX_STYLE_VALUEMAP_LIST_TABLE')) { | ||
$table->addClass(ZBX_STYLE_VALUEMAP_LIST_TABLE); | ||
} | ||
|
||
$cols = []; | ||
|
||
|
@@ -99,9 +100,10 @@ | |
// import | ||
$hostlist = $data['hostlist']; | ||
|
||
$table = (new CTable()) | ||
->setId('hostlist-table') | ||
->addClass(ZBX_STYLE_VALUEMAP_LIST_TABLE); | ||
$table = (new CTable())->setId('hostlist-table'); | ||
if (defined('ZBX_STYLE_VALUEMAP_LIST_TABLE')) { | ||
$table->addClass(ZBX_STYLE_VALUEMAP_LIST_TABLE); | ||
} | ||
|
||
$table->setColumns([ | ||
(new CTableColumn(_('Name'))) | ||
|