Example #1
0
 /**
  * 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);
 }
Example #2
0
 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();
             }
         }
     }
 }