/** * Naplní diagram */ function fillUp() { $members = $this->hostgroup->getDataValue('members'); $host = new IEHost(); $hosts = $host->getColumnsFromMySQL(array('alias', 'address', 'parents', 'notifications_enabled', 'active_checks_enabled', 'passive_checks_enabled', '3d_coords', $host->myCreateColumn, $host->myLastModifiedColumn, $host->nameColumn, $host->myKeyColumn), 'host_id IN ( ' . implode(',', array_keys($members)) . ' )'); foreach ($hosts as $hostNo => $host_info) { if (strstr($host_info['3d_coords'], ',')) { list($x, $y, $z) = explode(',', $host_info['3d_coords']); } else { $x = $y = 0; } if (strlen(trim($host_info['parents']))) { $host_info['parents'] = unserialize($host_info['parents']); } if (isset($host_info[$host->nameColumn])) { $name = $host_info[$host->nameColumn]; } else { continue; } $alias = $host_info['alias']; $color = ''; if ($host_info['active_checks_enabled']) { $color = 'lightgreen'; } if ($host_info['passive_checks_enabled']) { $color = 'lightblue'; } $this->addNode($name, array('id' => 'host_' . $host_info[$host->myKeyColumn], 'node_id' => $host_info[$host->myKeyColumn], 'color' => $color, 'x' => $x, 'y' => $y, 'fixed' => boolval($x + $y), 'shape' => 'point', 'style' => 'filled', 'tooltip' => $alias, 'label' => $name)); if (isset($host_info[$host->nameColumn])) { if (is_array($host_info['parents'])) { foreach ($host_info['parents'] as $parent_name) { $this->addEdge(array($host_info[$host->nameColumn] => $parent_name)); } } } } }
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(); } } } }
/** * Smaže hostgrupu i její použití v hostech * * @param int $id * @return boolean */ function delete($id = null) { if (isset($id) && $this->getId() != $id) { $this->loadFromSQL($id); } else { $id = $this->getId(); } $host = new IEHost(); $hosts = $host->getColumnsFromMySQL(array($host->myKeyColumn), array('hostgroups' => '%' . $this->getName() . '%')); foreach ($hosts as $hostInfo) { $hostId = intval(current($hostInfo)); $host->loadFromMySQL($hostId); $hostgroupNames = $host->getDataValue('hostgroups'); if ($hostgroupNames) { foreach ($hostgroupNames as $hostgroupId => $hostgroupName) { if ($hostgroupId == $this->getId()) { if ($host->delMember('hostgroups', $hostgroupId, $hostgroupName)) { $this->addStatusMessage(sprintf(_('host %s byl odstraněn ze skupiny %s'), $host->getName(), $hostgroupName), 'success'); } else { $this->addStatusMessage(sprintf(_('host %s byl odstraněn ze skupiny %s'), $host->getName(), $hostgroupName), 'error'); } } } } } $subgroup = new IEHostgroup(); $subgroups = $subgroup->getColumnsFromMySQL(array($subgroup->myKeyColumn), array('hostgroup_members' => '%' . $this->getName() . '%')); foreach ($subgroups as $subgroupInfo) { $subgroupId = intval(current($subgroupInfo)); $subgroup->loadFromMySQL($subgroupId); $subgroupgroupNames = $subgroup->getDataValue('hostgroup_members'); if ($subgroupgroupNames) { foreach ($subgroupgroupNames as $subgroupgroupId => $subgroupgroupName) { if ($subgroupgroupId == $this->getId()) { if ($subgroup->delMember('hostgroup_members', $subgroupgroupId, $subgroupgroupName)) { $this->addStatusMessage(sprintf(_('subgroup %s byl odstraněn ze skupiny %s'), $subgroup->getName(), $subgroupgroupName), 'success'); } else { $this->addStatusMessage(sprintf(_('subgroup %s byl odstraněn ze skupiny %s'), $subgroup->getName(), $subgroupgroupName), 'error'); } } } } } return parent::delete($id); }
$hostgroup->delete(); $oPage->redirect('hostgroups.php'); exit; } break; } $oPage->addItem(new IEPageTop(_('Editace skupiny hostů') . ' ' . $hostgroup->getName())); $hostgroupEdit = new IECfgEditor($hostgroup); $form = new EaseTWBForm('Hostgroup', 'hostgroup.php', 'POST', $hostgroupEdit, array('class' => 'form-horizontal')); $form->setTagID($form->getTagName()); if (!is_null($hostgroup->getMyKey())) { $form->addItem(new EaseHtmlInputHiddenTag($hostgroup->getmyKeyColumn(), $hostgroup->getMyKey())); } $form->addItem(new EaseTWSubmitButton(_('Uložit'), 'success')); $oPage->addItem(new IEPageBottom()); $infopanel = new IEInfoBox($hostgroup); $tools = new EaseTWBPanel(_('Nástroje'), 'warning'); if ($hostgroup->getId()) { $tools->addItem($hostgroup->deleteButton()); $tools->addItem(new EaseTWBPanel(_('Transfer'), 'warning', $hostgroup->transferForm())); } $pageRow = new EaseTWBRow(); $pageRow->addColumn(2, $infopanel); $pageRow->addColumn(6, new EaseTWBPanel(new EaseHtmlH1Tag($hostgroup->getDataValue('alias') . ' <small>' . $hostgroup->getName() . '</small>'), 'default', $form)); $pageRow->addColumn(4, $tools); $oPage->container->addItem($pageRow); $operations = $tools->addItem(new EaseTWBPanel(_('Hromadné operace')), 'success'); $operations->addItem(new IEContactAsignForm()); $tools->addItem(new EaseTWBLinkButton('wizard-host.php?hostgroup_id=' . $hostgroup->getId(), EaseTWBPart::GlyphIcon('plus') . _('nový host ve skupině'), 'success')); //$tools->addItem(new EaseTWBLinkButton('hglayouteditor.php?hostgroup_id=' . $hostgroup->getId(), EaseTWBPart::GlyphIcon('globe') . _('Rozvržení topologie'), 'info')); $oPage->draw();