Exemple #1
0
 public function update(Host &$host)
 {
     if ($host == null || $host->getId() == -1) {
         Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__);
         throw new Exception("Host object is not valid or Host.id is not set");
     }
     $dbHost = $this->getById($host->getId());
     if ($dbHost == null) {
         throw new Exception("Host cannot be retreived from the DB");
     }
     $entries = array();
     if ($host->getHostname() != $dbHost->getHostname()) {
         $entries['hostname'] = "'" . $this->db->escape($host->getHostname()) . "'";
     }
     if ($host->getIp() != $dbHost->getIp()) {
         $entries['ip'] = "'" . $this->db->escape($host->getIp()) . "'";
     }
     if ($host->getReporterHostname() != $dbHost->getReporterHostname()) {
         $entries['reporterHostname'] = "'" . $this->db->escape($host->getReporterHostname()) . "'";
     }
     if ($host->getReporterIp() != $dbHost->getReporterIp()) {
         $entries['reporterIp'] = "'" . $this->db->escape($host->getReporterIp()) . "'";
     }
     if ($host->getKernel() != $dbHost->getKernel()) {
         $entries['kernel'] = "'" . $this->db->escape($host->getKernel()) . "'";
     }
     if ($host->getOsId() != $dbHost->getOsId()) {
         $entries['osId'] = $this->db->escape($host->getOsId());
     }
     if ($host->getArchId() != $dbHost->getArchId()) {
         $entries['archId'] = $this->db->escape($host->getArchId());
     }
     if ($host->getDomainId() != $dbHost->getDomainId()) {
         $entries['domainId'] = $this->db->escape($host->getDomainId());
     }
     if ($host->getType() != $dbHost->getType()) {
         $entries['type'] = "'" . $this->db->escape($host->getType()) . "'";
     }
     if ($host->getOwnRepositoriesDef() != $dbHost->getOwnRepositoriesDef()) {
         $entries['ownRepositoriesDef'] = "'" . $this->db->escape($host->getOwnRepositoriesDef()) . "'";
     }
     if (sizeof($entries) > 0) {
         # Construct SQL query
         $sql = "update Host set";
         $sqle = "";
         foreach ($entries as $column => $value) {
             $sqle .= " {$column}={$value},";
         }
         # Remove last comma
         $sqle = preg_replace('/(.*),$/', '\\1', $sqle);
         $sql .= $sqle . " where id=" . $host->getId();
         $this->db->query($sql);
         Utils::log(LOG_DEBUG, "Host updated", __FILE__, __LINE__);
     }
 }
Exemple #2
0
 public function onHostStatusChange(Host $host)
 {
     $isActive = $host->isActive();
     $hostname = $host->getHostname();
     if ($isActive) {
         $this->active[$hostname] = $this->hosts[$hostname];
     } else {
         unset($this->active[$hostname]);
     }
 }
 public function removeHostFromHostGroups(Host &$host)
 {
     if ($host == null || $host->getId() == -1) {
         Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__);
         throw new Exception("Host object is not valid or Host.id is not set");
     }
     Utils::log(LOG_DEBUG, "Removing the host from all host groups [host=" . $host->getHostname() . "]", __FILE__, __LINE__);
     $this->getPakiti()->getDao("HostGroup")->removeHostFromHostGroups($host->getId());
 }
 public function removeHostTags(Host &$host)
 {
     if ($host == null || $host->getId() == -1) {
         Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__);
         throw new Exception("Host object is not valid or Host.id is not set");
     }
     Utils::log(LOG_DEBUG, "Removing all tags associated with the host [hostname='{$host->getHostname()}']", __FILE__, __LINE__);
     $this->getPakiti()->getDao("Tag")->deleteTagsByHostId($host->getId());
 }