From ebc06a020893ed5b69e004c3fab6653cae98bdef Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Wed, 20 Aug 2025 09:40:39 +0200 Subject: [PATCH] fixed consolidation --- application/Device/DeviceController.php | 16 +++++++++++----- lib/Zabbix/Zabbix.php | 18 +++++++++++++----- .../DeviceZabbixConsolidation.js | 4 ++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/application/Device/DeviceController.php b/application/Device/DeviceController.php index eb3326c5a..2ff9a1f40 100644 --- a/application/Device/DeviceController.php +++ b/application/Device/DeviceController.php @@ -352,6 +352,12 @@ class DeviceController extends mfBaseController case "getZabbixConsolidationData": $this->getZabbixConsolidationData(); break; + case "getZabbixTemplates": + $this->getZabbixTemplates(); + break; + case "createZabbixHost": + $this->createZabbixHost(); + break; case "updateZabbixCoordinates": $this->updateZabbixCoordinates(); break; @@ -674,7 +680,7 @@ class DeviceController extends mfBaseController self::returnJson($results); } - protected function getZabbixTemplatesAction() { + protected function getZabbixTemplates() { $zabbix = new Zabbix(ZABBIX_API_URL, ZABBIX_API_KEY); $templateNames = [ "ICMP Ping", @@ -690,12 +696,12 @@ class DeviceController extends mfBaseController self::returnJson($formattedTemplates); } - protected function createZabbixHostAction() { + protected function createZabbixHost() { $this->postData = json_decode(file_get_contents('php://input'), true); $deviceId = $this->postData['deviceId'] ?? null; - $templateId = $this->postData['templateId'] ?? null; - if (!$deviceId || !$templateId) { + $templateIds = $this->postData['templateIds'] ?? null; + if (!$deviceId || !$templateIds) { self::sendError("Device ID or Template ID is missing."); } @@ -717,7 +723,7 @@ class DeviceController extends mfBaseController self::sendError("Host group '$groupName' not found in Zabbix."); } - $result = $zabbix->createHost($device->name, $device->ip, $groupId, $templateId); + $result = $zabbix->createHost($device->name, $device->ip, $groupId, $templateIds); if (isset($result['hostids'])) { $device->zabbix_host_id = $result['hostids'][0]; diff --git a/lib/Zabbix/Zabbix.php b/lib/Zabbix/Zabbix.php index cff576073..eaf19e6e2 100644 --- a/lib/Zabbix/Zabbix.php +++ b/lib/Zabbix/Zabbix.php @@ -162,22 +162,30 @@ class Zabbix { } - public function createHost($visibleName, $ip, $groupId, $templateId) { + public function createHost($visibleName, $ip, $groupId, $templateIds) { + $templatesData = array_map(function($id) { + return ['templateid' => $id]; + }, $templateIds); + $params = [ 'host' => $ip, // Technical name is the IP 'name' => $visibleName, // Visible name - 'interfaces' => [ + 'interfaces' => [ // <-- Corrected structure [ - 'type' => 1, // Agent interface + 'type' => 2, // 2 for SNMP 'main' => 1, 'useip' => 1, 'ip' => $ip, 'dns' => '', - 'port' => '10050' + 'port' => '161', + 'details' => [ + 'version' => 2, + 'community' => 'public_xinon' + ] ] ], 'groups' => [['groupid' => $groupId]], - 'templates' => [['templateid' => $templateId]] + 'templates' => $templatesData // Use the correctly formatted array ]; $response = $this->zabbixRequest('host.create', $params); diff --git a/public/js/pages/DeviceZabbixConsolidation/DeviceZabbixConsolidation.js b/public/js/pages/DeviceZabbixConsolidation/DeviceZabbixConsolidation.js index c9d0880db..7c48b892a 100644 --- a/public/js/pages/DeviceZabbixConsolidation/DeviceZabbixConsolidation.js +++ b/public/js/pages/DeviceZabbixConsolidation/DeviceZabbixConsolidation.js @@ -98,7 +98,7 @@ Vue.component('device-zabbix-consolidation', {

Bitte wählen Sie ein Template für das Gerät {{ zabbixCreateModal.deviceName }}.

- +
@@ -180,7 +180,7 @@ Vue.component('device-zabbix-consolidation', { try { const response = await axios.post(`${window.TT_CONFIG.API_URL}?do=createZabbixHost`, { deviceId: this.zabbixCreateModal.deviceId, - templateId: this.zabbixCreateModal.selectedTemplateId + templateIds: this.zabbixCreateModal.selectedTemplateId }); if (response.data.success) { window.notify('success', response.data.message);