fixed consolidation
This commit is contained in:
@@ -352,6 +352,12 @@ class DeviceController extends mfBaseController
|
|||||||
case "getZabbixConsolidationData":
|
case "getZabbixConsolidationData":
|
||||||
$this->getZabbixConsolidationData();
|
$this->getZabbixConsolidationData();
|
||||||
break;
|
break;
|
||||||
|
case "getZabbixTemplates":
|
||||||
|
$this->getZabbixTemplates();
|
||||||
|
break;
|
||||||
|
case "createZabbixHost":
|
||||||
|
$this->createZabbixHost();
|
||||||
|
break;
|
||||||
case "updateZabbixCoordinates":
|
case "updateZabbixCoordinates":
|
||||||
$this->updateZabbixCoordinates();
|
$this->updateZabbixCoordinates();
|
||||||
break;
|
break;
|
||||||
@@ -674,7 +680,7 @@ class DeviceController extends mfBaseController
|
|||||||
self::returnJson($results);
|
self::returnJson($results);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getZabbixTemplatesAction() {
|
protected function getZabbixTemplates() {
|
||||||
$zabbix = new Zabbix(ZABBIX_API_URL, ZABBIX_API_KEY);
|
$zabbix = new Zabbix(ZABBIX_API_URL, ZABBIX_API_KEY);
|
||||||
$templateNames = [
|
$templateNames = [
|
||||||
"ICMP Ping",
|
"ICMP Ping",
|
||||||
@@ -690,12 +696,12 @@ class DeviceController extends mfBaseController
|
|||||||
self::returnJson($formattedTemplates);
|
self::returnJson($formattedTemplates);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createZabbixHostAction() {
|
protected function createZabbixHost() {
|
||||||
$this->postData = json_decode(file_get_contents('php://input'), true);
|
$this->postData = json_decode(file_get_contents('php://input'), true);
|
||||||
|
|
||||||
$deviceId = $this->postData['deviceId'] ?? null;
|
$deviceId = $this->postData['deviceId'] ?? null;
|
||||||
$templateId = $this->postData['templateId'] ?? null;
|
$templateIds = $this->postData['templateIds'] ?? null;
|
||||||
if (!$deviceId || !$templateId) {
|
if (!$deviceId || !$templateIds) {
|
||||||
self::sendError("Device ID or Template ID is missing.");
|
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.");
|
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'])) {
|
if (isset($result['hostids'])) {
|
||||||
$device->zabbix_host_id = $result['hostids'][0];
|
$device->zabbix_host_id = $result['hostids'][0];
|
||||||
|
|||||||
+13
-5
@@ -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 = [
|
$params = [
|
||||||
'host' => $ip, // Technical name is the IP
|
'host' => $ip, // Technical name is the IP
|
||||||
'name' => $visibleName, // Visible name
|
'name' => $visibleName, // Visible name
|
||||||
'interfaces' => [
|
'interfaces' => [ // <-- Corrected structure
|
||||||
[
|
[
|
||||||
'type' => 1, // Agent interface
|
'type' => 2, // 2 for SNMP
|
||||||
'main' => 1,
|
'main' => 1,
|
||||||
'useip' => 1,
|
'useip' => 1,
|
||||||
'ip' => $ip,
|
'ip' => $ip,
|
||||||
'dns' => '',
|
'dns' => '',
|
||||||
'port' => '10050'
|
'port' => '161',
|
||||||
|
'details' => [
|
||||||
|
'version' => 2,
|
||||||
|
'community' => 'public_xinon'
|
||||||
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'groups' => [['groupid' => $groupId]],
|
'groups' => [['groupid' => $groupId]],
|
||||||
'templates' => [['templateid' => $templateId]]
|
'templates' => $templatesData // Use the correctly formatted array
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->zabbixRequest('host.create', $params);
|
$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">
|
<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>
|
<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>
|
</tt-modal>
|
||||||
</div>
|
</div>
|
||||||
</tt-card>
|
</tt-card>
|
||||||
@@ -180,7 +180,7 @@ Vue.component('device-zabbix-consolidation', {
|
|||||||
try {
|
try {
|
||||||
const response = await axios.post(`${window.TT_CONFIG.API_URL}?do=createZabbixHost`, {
|
const response = await axios.post(`${window.TT_CONFIG.API_URL}?do=createZabbixHost`, {
|
||||||
deviceId: this.zabbixCreateModal.deviceId,
|
deviceId: this.zabbixCreateModal.deviceId,
|
||||||
templateId: this.zabbixCreateModal.selectedTemplateId
|
templateIds: this.zabbixCreateModal.selectedTemplateId
|
||||||
});
|
});
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
window.notify('success', response.data.message);
|
window.notify('success', response.data.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user