fixed consolidation
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -98,7 +98,7 @@ Vue.component('device-zabbix-consolidation', {
|
||||
|
||||
<tt-modal v-if="zabbixCreateModal.show" :show.sync="zabbixCreateModal.show" title="Gerät in Zabbix anlegen" @submit="submitCreateZabbixHost" :save-loading="zabbixCreateModal.loading">
|
||||
<p>Bitte wählen Sie ein Template für das Gerät <strong>{{ zabbixCreateModal.deviceName }}</strong>.</p>
|
||||
<tt-select label="Template" :options="zabbixCreateModal.templates" v-model="zabbixCreateModal.selectedTemplateId" sm row required/>
|
||||
<tt-select label="Template" :options="zabbixCreateModal.templates" multiple v-model="zabbixCreateModal.selectedTemplateId" sm row required/>
|
||||
</tt-modal>
|
||||
</div>
|
||||
</tt-card>
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user