Auto-synchronizer MC
This commit is contained in:
parent
9d8079ad77
commit
78487fa4e5
|
@ -0,0 +1,13 @@
|
|||
START TRANSACTION;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tsync_queue` (
|
||||
`id` serial,
|
||||
`sql` MEDIUMTEXT,
|
||||
`target` bigint(20) unsigned NOT NULL,
|
||||
`utimestamp` bigint(20) default '0',
|
||||
`error` MEDIUMTEXT,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
COMMIT;
|
|
@ -4023,3 +4023,15 @@ SELECT `id_recon_script`,`type`, `name`, `description`, `script`, `macros` FROM
|
|||
DELETE FROM `tconfig` WHERE `token` = 'ipam_installed';
|
||||
|
||||
DELETE FROM `tconfig` WHERE `token` = 'ipam_recon_script_id';
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- Table `tsync_queue`
|
||||
-- ----------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `tsync_queue` (
|
||||
`id` serial,
|
||||
`sql` MEDIUMTEXT,
|
||||
`target` bigint(20) unsigned NOT NULL,
|
||||
`utimestamp` bigint(20) default '0',
|
||||
`error` MEDIUMTEXT,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
* @subpackage DataBase
|
||||
*/
|
||||
|
||||
use PandoraFMS\Enterprise\Metaconsole\Synchronizer;
|
||||
|
||||
require_once $config['homedir'].'/include/functions_extensions.php';
|
||||
require_once $config['homedir'].'/include/functions_groups.php';
|
||||
require_once $config['homedir'].'/include/functions_agents.php';
|
||||
|
@ -1351,20 +1353,54 @@ function db_process_sql($sql, $rettype='affected_rows', $dbconnection='', $cache
|
|||
{
|
||||
global $config;
|
||||
|
||||
$rc = false;
|
||||
switch ($config['dbtype']) {
|
||||
case 'mysql':
|
||||
return @mysql_db_process_sql($sql, $rettype, $dbconnection, $cache);
|
||||
default:
|
||||
$rc = @mysql_db_process_sql($sql, $rettype, $dbconnection, $cache);
|
||||
break;
|
||||
|
||||
break;
|
||||
case 'postgresql':
|
||||
return @postgresql_db_process_sql($sql, $rettype, $dbconnection, $cache, $status);
|
||||
$rc = @postgresql_db_process_sql($sql, $rettype, $dbconnection, $cache, $status);
|
||||
break;
|
||||
|
||||
break;
|
||||
case 'oracle':
|
||||
return oracle_db_process_sql($sql, $rettype, $dbconnection, $cache, $status, $autocommit);
|
||||
|
||||
break;
|
||||
$rc = oracle_db_process_sql($sql, $rettype, $dbconnection, $cache, $status, $autocommit);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($rc !== false) {
|
||||
if (enterprise_hook('is_metaconsole') === true
|
||||
&& (bool) $config['centralized_management'] === true
|
||||
&& $dbconnection === ''
|
||||
) {
|
||||
$errors = null;
|
||||
try {
|
||||
// Synchronize changes to nodes if needed.
|
||||
$sync = new Synchronizer();
|
||||
if ($sync !== null) {
|
||||
if ($sync->queue($sql) === false) {
|
||||
// Launch events per failed query.
|
||||
$errors = $sync->getLatestErrors();
|
||||
if ($errors !== null) {
|
||||
$errors = join(', ', $errors);
|
||||
} else {
|
||||
$errors = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors = $e->getMessage();
|
||||
}
|
||||
|
||||
if ($errors !== null) {
|
||||
// TODO: Generate pandora event.
|
||||
error_log($errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rc;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3981,3 +3981,15 @@ CREATE TABLE IF NOT EXISTS `tipam_supernet_network` (
|
|||
FOREIGN KEY (`id_supernet`) REFERENCES tipam_supernet(`id`) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
FOREIGN KEY (`id_network`) REFERENCES tipam_network(`id`) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- Table `tsync_queue`
|
||||
-- ----------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `tsync_queue` (
|
||||
`id` serial,
|
||||
`sql` MEDIUMTEXT,
|
||||
`target` bigint(20) unsigned NOT NULL,
|
||||
`utimestamp` bigint(20) default '0',
|
||||
`error` MEDIUMTEXT,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
|
Loading…
Reference in New Issue