added new device consolidation

This commit is contained in:
2025-08-19 19:19:08 +02:00
parent ba34e2ad56
commit 7dd0733d6d
6 changed files with 802 additions and 2 deletions
+79
View File
@@ -113,4 +113,83 @@ class Zabbix {
));
return $response['result'];
}
public function getAllHostsWithDetails() {
$response = $this->zabbixRequest('host.get', [
'output' => ['hostid', 'host', 'name', 'status'],
'selectInventory' => ['location_lat', 'location_lon'],
'selectParentTemplates' => ['templateid', 'name'],
'selectHostGroups' => 'extend' // This is the new line
]);
return $response['result'] ?? [];
}
public function updateHostInventory($hostId, $inventoryData) {
// First, get the current inventory to avoid overwriting existing fields
$hostResponse = $this->zabbixRequest('host.get', [
'hostids' => $hostId,
'selectInventory' => 'extend'
]);
$currentInventory = $hostResponse['result'][0]['inventory'] ?? [];
// Merge new coordinates into the existing inventory
$newInventory = array_merge($currentInventory, $inventoryData);
$params = [
'hostid' => $hostId,
'inventory_mode' => 0, // Set to manual mode
'inventory' => $newInventory
];
$response = $this->zabbixRequest('host.update', $params);
return $response['result'] ?? ['error' => $response['error'] ?? 'Unknown error'];
}
public function getTemplateIdByName($templateName) {
$response = $this->zabbixRequest('template.get', [
'output' => ['templateid'],
'filter' => ['host' => [$templateName]]
]);
return $response['result'][0]['templateid'] ?? null;
}
public function getTemplatesByNames(array $templateNames) {
$response = $this->zabbixRequest('template.get', [
'output' => ['templateid', 'name'],
'filter' => ['host' => $templateNames]
]);
return $response['result'] ?? [];
}
public function createHost($visibleName, $ip, $groupId, $templateId) {
$params = [
'host' => $ip, // Technical name is the IP
'name' => $visibleName, // Visible name
'interfaces' => [
[
'type' => 1, // Agent interface
'main' => 1,
'useip' => 1,
'ip' => $ip,
'dns' => '',
'port' => '10050'
]
],
'groups' => [['groupid' => $groupId]],
'templates' => [['templateid' => $templateId]]
];
$response = $this->zabbixRequest('host.create', $params);
return $response['result'] ?? ['error' => $response['error'] ?? 'Unknown error'];
}
public function getHostGroupIdByName($groupName) {
$response = $this->zabbixRequest('hostgroup.get', [
'output' => ['groupid'],
'filter' => ['name' => [$groupName]]
]);
return $response['result'][0]['groupid'] ?? null;
}
}