$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()); $oPage->draw();
$host->addStatusMessage(sprintf(_('<strong>%s</strong> byl přidán mezi kontakty <strong>%s</strong>'), $contact->getName(), $host->getName()), 'success'); } else { $host->addStatusMessage(sprintf(_('<strong>%s</strong> nebyl přidán mezi kontakty <strong>%s</strong>'), $contact->getName(), $host->getName()), 'warning'); } } } else { $hostgroup->addStatusMessage(_('Chyba přiřazení kontaktu'), 'warning'); } break; default: if ($oPage->isPosted()) { $hostgroup->takeData($_POST); if (!$hostgroup->getId()) { $hostgroup->setDataValue('members', array()); } $hostgroupID = $hostgroup->saveToMySQL(); if (is_null($hostgroupID)) { $oUser->addStatusMessage(_('Skupina hostů nebyla uložena'), 'warning'); } else { $oUser->addStatusMessage(_('Skupina hostů byla uložena'), 'success'); } $hostgroup->saveMembers(); } $delete = $oPage->getGetValue('delete', 'bool'); if ($delete == 'true') { $hostgroup->delete(); $oPage->redirect('hostgroups.php'); exit; } break; }
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(); } } } }
$newHostId = (int) $host->insertToMySQL(); if ($newHostId) { $host->addStatusMessage(sprintf(_('Nový host %s %s založen'), $hop, $newHostName), 'success'); $parents[$hop] = array('host_id' => $newHostId, 'address' => $hop, $host->nameColumn => $newHostName); } } if ($pos) { $parentIP = $trace[$pos - 1]; $host->addMember('parents', $parents[$parentIP][$host->myKeyColumn], $parents[$parentIP][$host->nameColumn]); } $host->addMember('contacts', $defaultContactId, $defaultContactName); $host->setDataValue('config_hash', $host->getConfigHash()); $host->setDataValue('check_command', 'check-host-alive'); $host->setDataValue('active_checks_enabled', 1); $host->setDataValue('passive_checks_enabled', 0); $oldNotes = strval($host->getDataValue('notes')); if (strstr($hostGroup->getName(), $oldNotes) == false) { $host->setDataValue('notes', $oldNotes . "\n" . $hostGroup->getName()); } $host->saveToMySQL(); $hostGroup->addMember('members', $host->getId(), $host->getName()); $listing->addItemSmart(new EaseHtmlATag('host.php?host_id=' . $host->getId(), $host->getName())); } if ($hostGroup->saveToMySQL()) { $hostGroup->addStatusMessage(sprintf(_('Hostgrupa %s naplněna'), $hostGroup->getName()), 'success'); } else { $hostGroup->addStatusMessage(sprintf(_('Hostgrupa %s nebyla naplněna'), $hostGroup->getName()), 'warning'); } } $oPage->addItem(new IEPageBottom()); $oPage->draw();