/** * Přiřadí služby k hostům podle výsledků scannu */ public function assignServices() { $success = 0; $hostmod = false; foreach ($this->results as $port) { switch ($port) { case 80: if ($this->host->favToIcon()) { $hostmod = true; } break; case 5666: $this->host->setDataValue('platform', 'linux'); $hostmod = true; break; case 12489: $this->host->setDataValue('platform', 'windows'); $hostmod = true; break; default: break; } $this->service->setmyKeyColumn('tcp_port'); $this->service->loadFromMySQL($port); $this->service->setmyKeyColumn('service_id'); $this->service->addMember('host_name', $this->host->getId(), $this->host->getName()); if ($this->service->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Přidána sledovaná služba: %s'), $this->service->getName()), 'success'); $success++; } else { $this->addStatusMessage(sprintf(_('Přidání sledované služby: %s se nezdařilo'), $this->service->getName()), 'error'); } } if ($hostmod) { $this->host->saveToMySQL(); } return $success; }
/* Naplní hodnoty z předloh */ $usedCache = array(); $commandsCache = array(); foreach ($allServices as $rowId => $service) { if (isset($service['use'])) { $remote = $service['check_command-remote']; if (!isset($commandsCache[$remote])) { $command = new IECommand($remote); $commandsCache[$remote] = $command->getData(); } } if (isset($service['use'])) { $use = $service['use']; if (!isset($usedCache[$use])) { $used = new IEService(); $used->setmyKeyColumn('name'); if ($used->loadFromMySQL($use)) { $used->resetObjectIdentity(); $usedCache[$use] = $used->getData(); } } if (isset($usedCache[$use])) { foreach ($usedCache[$use] as $templateKey => $templateValue) { if ($templateKey != 'check_interval') { continue; } if (!is_null($templateValue) && !isset($allServices[$rowId][$templateKey])) { $allServices[$rowId][$templateKey] = $templateValue; } } }