Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
Poc new update field pollers (#8093) (#8100)
Browse files Browse the repository at this point in the history
* Poc new update field pollers (#8093)

* enh(core): add flag for needs reset of poller
Part of POC for bam-766

* enh(core): add new updated pollers field to intall sql and repository

* enh(core): update repositories and poller restart to reflect new update field

* update(sql): change sql upgrade version

* update(sql): remove new sql file
  • Loading branch information
victorvassilev authored Nov 7, 2019
1 parent 83fb066 commit d4e220b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/Centreon/Domain/Repository/NagiosServerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,33 @@ public function truncate()
$stmt = $this->db->prepare($sql);
$stmt->execute();
}

/**
* Sets poller as updated (shows that poller needs restarting)
* @param int $id id of poller
*/
public function setUpdated(int $id): void
{
$sql = "UPDATE `nagios_server` SET `updated` = '1' WHERE `id` = :id";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':id', $id, \PDO::PARAM_INT);
$stmt->execute();
}

/**
* Get Central Poller
* @return int|null
*/
public function getCentral(): ?int
{
$query = "SELECT id FROM nagios_server WHERE localhost = '1' LIMIT 1";
$stmt = $this->db->prepare($query);
$stmt->execute();

if (!$stmt->rowCount()) {
return null;
}

return (int)$stmt->fetch()['id'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function log_error($errno, $errstr, $errfile, $errline)
}
}
$DBRESULT = $pearDB->query("UPDATE `nagios_server` SET `last_restart` = '"
. time() . "' WHERE `id` = '" . $host["id"] . "'");
. time() . "', `updated` = '0' WHERE `id` = '" . $host["id"] . "'");
}

foreach ($msg_restart as $key => $str) {
Expand Down
20 changes: 17 additions & 3 deletions www/include/configuration/configServers/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ function updateServer(int $id, $data): void
*/
function checkChangeState(int $poller_id, int $last_restart): bool
{
global $pearDBO, $conf_centreon;
global $pearDBO, $conf_centreon, $pearDB;

if (!isset($last_restart) || $last_restart == "") {
if (!isset($last_restart) || $last_restart === "") {
return false;
}

Expand Down Expand Up @@ -860,5 +860,19 @@ function checkChangeState(int $poller_id, int $last_restart): bool
REQUEST;

$dbResult = $pearDBO->query($query);
return $dbResult->rowCount() ? true : false;
if ($dbResult->rowCount()) {
// requires restart if storage db has log information about changes
return true;
} else {
// also requires restart if flag updated is set to true
$configStmt = $pearDB->prepare("SELECT updated FROM nagios_server WHERE id = :pollerID LIMIT 1");
$configStmt->bindValue(':pollerID', $poller_id, \PDO::PARAM_INT);
$configStmt->execute();
$row = $configStmt->fetch(\PDO::FETCH_ASSOC);
if ($row['updated']) {
return true;
}
}

return false;
}
1 change: 1 addition & 0 deletions www/install/createTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,7 @@ CREATE TABLE `nagios_server` (
`centreonbroker_logs_path` VARCHAR(255),
`remote_id` int(11) NULL,
`remote_server_centcore_ssh_proxy` enum('0','1') NOT NULL DEFAULT '1',
`updated` enum('1','0') NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
CONSTRAINT `nagios_server_remote_id_id` FOREIGN KEY (`remote_id`) REFERENCES `nagios_server` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Expand Down
2 changes: 2 additions & 0 deletions www/install/sql/centreon/Update-DB-19.10.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--new updated field of pollers-
ALTER TABLE `nagios_server` ADD COLUMN `updated` enum('0','1') NOT NULL DEFAULT '0';

0 comments on commit d4e220b

Please sign in to comment.