$host_group = $oPage->getRequestValue('host_group', 'int'); $host = new IEHost(); $host->owner =& $oUser; if ($hostName && $platform) { $host->setData(array($host->userColumn => $oUser->getUserID(), 'host_name' => $hostName, 'use' => 'generic-host', 'platform' => 'generic', 'register' => true, 'generate' => TRUE, 'platform' => $platform, 'alias' => $hostName, 'active_checks_enabled' => 0, 'passive_checks_enabled' => 1, 'check_freshness' => 1, 'freshness_threshold' => 900, 'flap_detection_enabled' => 0, 'check_command' => 'return-unknown')); if ($host_group) { $hostgroup = new IEHostgroup($host_group); $host->addMember('hostgroups', $hostgroup->getId(), $hostgroup->getName()); $hostgroup->addMember('members', $host->getId(), $host->getName()); $hostgroup->saveToMySQL(); } if ($host->saveToMysql()) { $hostGroup = new IEHostgroup(); if ($hostGroup->loadDefault()) { $hostGroup->setDataValue($hostGroup->nameColumn, EaseShared::user()->getUserLogin()); $hostGroup->addMember('members', $host->getId(), $host->getName()); $hostGroup->saveToMySQL(); $host->addMember('hostgroups', $hostGroup->getId(), $hostGroup->getName()); $host->saveToMysql(); } $oPage->redirect('host.php?host_id=' . $host->getId()); exit; } } else { if ($oPage->isPosted()) { $oPage->addStatusMessage(_('Prosím zastejte název sledovaného hosta'), 'warning'); } } $oPage->addItem(new IEPageTop(_('Průvodce založením hosta'))); $oPage->container->addItem(new EaseTWBPanel(_('Nový pasivně sledovaný host'), 'info', new IEPassiveCheckedHostForm('passive'))); $oPage->addItem(new IEPageBottom());
public function fixHostNameIDs() { $hostsOK = array(); $hostsErr = array(); $host = new IEHost(); $service = new IEService(); $services = $service->getColumnsFromMySQL(array($service->myKeyColumn, $service->nameColumn, 'host_name'), null, null, $service->myKeyColumn); foreach ($services as $serviceId => $serviceInfo) { $service->loadFromMySQL($serviceId); foreach ($service->getDataValue('host_name') as $hostId => $hostName) { if (!strlen($hostName)) { unset($service->data['host_name'][$hostId]); $hostsOK[] = '(undefined)'; } $hostFound = $host->loadFromMySQL($hostName); if ($hostId != $host->getId()) { if ($service->delMember('host_name', $hostId, $hostName) && $service->addMember('host_name', $host->getId(), $hostName)) { $hostsOK[] = $hostName; } else { $hostsErr[] = $hostName; } } } if (count($hostsOK)) { if ($service->saveToMySQL()) { $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $service->getName(), implode(',', $hostsOK)), array('class' => 'list-group-item')); $this->addStatusMessage(sprintf(_('%s : %s'), $service->getName(), implode(',', $hostsOK)), 'success'); $hostsOK = array(); } } } $hostgroup = new IEHostgroup(); $hostgroups = $hostgroup->getListing(); foreach ($hostgroups as $hostgroupId => $hostgroupInfo) { $hostgroup->loadFromMySQL($hostgroupId); foreach ($hostgroup->getDataValue('members') as $hostId => $hostName) { $hostFound = $host->loadFromMySQL($hostName); if ($hostId != $host->getId()) { if ($hostgroup->delMember('members', $hostId, $hostName) && $hostgroup->addMember('members', $host->getId(), $hostName)) { $hostsOK[] = $hostName; } else { $hostsErr[] = $hostName; } } } if (count($hostsOK)) { if ($hostgroup->saveToMySQL()) { $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $hostgroup->getName(), implode(',', $hostsOK)), array('class' => 'list-group-item')); $this->addStatusMessage(sprintf(_('%s : %s'), $hostgroup->getName(), implode(',', $hostsOK)), 'success'); $hostsOK = array(); } } } $childsAssigned = $host->myDbLink->queryToArray('SELECT ' . $host->myKeyColumn . ',' . $host->nameColumn . ' FROM ' . $host->myTable . ' WHERE ' . 'parents' . ' IS NOT NULL && parents !=\'a:0:{}\'', $host->myKeyColumn); foreach ($childsAssigned as $chid_id => $child_info) { $child = new IEHost($chid_id); $parents = $child->getDataValue('parents'); foreach ($parents as $parent_id => $parent_name) { $parent = new IEHost($parent_name); if ($parent->getId()) { //Ok Host toho jména existuje if ($parent->getId() != $parent_id) { //Ale nesedí ID $child->delMember('parents', $parent_id, $parent_name); $child->addMember('parents', $parent->getId(), $parent_name); $child->saveToMySQL(); $this->addItemSmart(sprintf(_('Rodič <strong>%s</strong> hosta %s má špatné ID'), $parent_name, $child_info[$host->nameColumn]), array('class' => 'list-group-item')); } } else { //Host tohoto jména neexistuje, nemůže být tedy PARENT $this->addItemSmart(sprintf(_('Rodič <strong>%s</strong> hosta %s neexistuje'), $parent_name, $child_info[$host->nameColumn]), array('class' => 'list-group-item')); $child->delMember('parents', $parent->getId(), $parent_name); $child->saveToMySQL(); } } } }