Merge branch 'Device/edit-zabbix-sync' into 'master'

changed how zabbix syncs

See merge request fronk/thetool!1217
This commit is contained in:
Luca Haid
2025-04-14 11:54:18 +00:00
2 changed files with 3 additions and 5 deletions
@@ -24,8 +24,7 @@ class DeviceMonitoringController extends mfBaseController {
public function syncToolZabbix() { public function syncToolZabbix() {
foreach (DeviceModel::getAll() as $device) { foreach (DeviceModel::getAll() as $device) {
$ip = $device->ip; $hosts = array_merge($this->zabbix->getHosts(null, $device->ip), $this->zabbix->getHosts($device->name));
$hosts = $this->zabbix->getHosts($ip);
if (empty($hosts)) { if (empty($hosts)) {
echo "{$device->name}({$device->ip}) not found in Zabbix." . PHP_EOL; echo "{$device->name}({$device->ip}) not found in Zabbix." . PHP_EOL;
@@ -36,12 +35,11 @@ class DeviceMonitoringController extends mfBaseController {
$icmpItems = $this->zabbix->getICMPItems($hostId); $icmpItems = $this->zabbix->getICMPItems($hostId);
$status = 0; $status = 0;
foreach ($icmpItems as $icmpItem) { foreach ($icmpItems as $icmpItem)
if (strpos($icmpItem['key_'], 'icmpping[') !== false) { if (strpos($icmpItem['key_'], 'icmpping[') !== false) {
$status = $icmpItem['lastvalue'] + 1; $status = $icmpItem['lastvalue'] + 1;
break; break;
} }
}
echo "{$device->name}({$device->ip}) found in Zabbix with host ID: {$hostId} and status: {$status}" . PHP_EOL; echo "{$device->name}({$device->ip}) found in Zabbix with host ID: {$hostId} and status: {$status}" . PHP_EOL;
$device->zabbix_online = $status; $device->zabbix_online = $status;
+1 -1
View File
@@ -58,7 +58,7 @@ class Zabbix {
return $response['result']; return $response['result'];
} elseif ($ip) { } elseif ($ip) {
$response = $this->zabbixRequest('host.get', array( $response = $this->zabbixRequest('host.get', array(
'search' => array('ip' => array($ip)) 'search' => array('host' => array($ip))
)); ));
return $response['result']; return $response['result'];
} }