Ejemplo n.º 1
0
 /**
  * Vytvoří nového hosta patřícího rovnou do výchozí skupiny uživatele
  *
  * @param array $data asiciativní pole dat
  *
  * @return int|null id nově vloženého řádku nebo null, pokud se data
  * nepovede vložit
  */
 public function insertToMySQL($data = null)
 {
     if (!is_null($data)) {
         $this->takeData($data);
     }
     $hostgroup = new IEHostgroup($this->user->getUserLogin());
     $this->addMember('hostgroups', $hostgroup->getId(), $hostgroup->getName());
     return parent::insertToMySQL();
 }
Ejemplo n.º 2
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);
 }
$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();
Ejemplo n.º 4
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();
             }
         }
     }
 }
Ejemplo n.º 5
0
            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;
}
$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();
Ejemplo n.º 6
0
    $forceIP = false;
}
if (is_null($hostId) || !$ip) {
    $oPage->container->addItem(endRouteForm($host));
} else {
    $defaultContactId = $oUser->getDefaultContact()->getId();
    $defaultContactName = $oUser->getDefaultContact()->getName();
    $hgName = sprintf(_('Cesta k %s'), $host->getName());
    $hostGroup = new IEHostgroup($hgName);
    if ($hostGroup->getId()) {
    } else {
        $hostGroup->setUpUser($oUser);
        $hostGroup->setName($hgName);
    }
    $listing = new EaseHtmlOlTag();
    $infopanel = $oPage->container->addItem(new EaseTWBPanel($hostGroup->getName(), 'info', $listing));
    $trace = array();
    //??? $mtr = shell_exec('mtr -4 --no-dns -c 1 -p   ' . $ip);
    $mtr = shell_exec('traceroute -n -w 1 ' . $ip);
    $mtrlines = explode("\n", $mtr);
    foreach ($mtrlines as $mtrline) {
        $linea = explode(' ', trim($mtrline));
        if ($linea[0] == 'traceroute' || !isset($linea[2])) {
            continue;
        }
        if ($linea[2] != '*') {
            $trace[] = $linea[2];
        }
    }
    $trace[] = $ip;
    $parents = array();