mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
WIP Historical database manager (setup)
This commit is contained in:
parent
12b76a03b1
commit
c7706a6bfa
@ -248,6 +248,18 @@ if (isset($config['error_config_update_config'])) {
|
||||
ui_print_success_message(__('Correct update the setup options'));
|
||||
}
|
||||
|
||||
if (is_array($config['error_config_update_config']['errors']) === true) {
|
||||
foreach ($config['error_config_update_config']['errors'] as $msg) {
|
||||
ui_print_error_message($msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($config['error_config_update_config']['warnings']) === true) {
|
||||
foreach ($config['error_config_update_config']['warnings'] as $msg) {
|
||||
ui_print_warning_message($msg);
|
||||
}
|
||||
}
|
||||
|
||||
unset($config['error_config_update_config']);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,10 @@
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Config functions.
|
||||
// Config functions.
|
||||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
use PandoraFMS\Core\DBMaintainer;
|
||||
use PandoraFMS\Core\Config;
|
||||
|
||||
|
||||
/**
|
||||
@ -147,6 +150,8 @@ function config_update_config()
|
||||
}
|
||||
|
||||
$error_update = [];
|
||||
$errors = [];
|
||||
$warnings = [];
|
||||
|
||||
$sec2 = get_parameter('sec2');
|
||||
|
||||
@ -1448,6 +1453,27 @@ function config_update_config()
|
||||
break;
|
||||
|
||||
case 'hist_db':
|
||||
if ($config['dbname'] == get_parameter('history_db_name')
|
||||
&& $config['dbport'] == get_parameter('history_db_port')
|
||||
&& $config['dbhost'] == io_input_password(get_parameter('history_db_host'))
|
||||
) {
|
||||
// Same definition for active and historical database!
|
||||
// This is a critical error.
|
||||
$errors[] = __('Active and historical database cannot be the same.');
|
||||
} else {
|
||||
if (!config_update_value('history_db_host', get_parameter('history_db_host'))) {
|
||||
$error_update[] = __('Host');
|
||||
}
|
||||
|
||||
if (!config_update_value('history_db_port', get_parameter('history_db_port'))) {
|
||||
$error_update[] = __('Port');
|
||||
}
|
||||
|
||||
if (!config_update_value('history_db_name', get_parameter('history_db_name'))) {
|
||||
$error_update[] = __('Database name');
|
||||
}
|
||||
}
|
||||
|
||||
if (!config_update_value('history_db_enabled', get_parameter('history_db_enabled'))) {
|
||||
$error_update[] = __('Enable history database');
|
||||
}
|
||||
@ -1456,18 +1482,6 @@ function config_update_config()
|
||||
$error_update[] = __('Enable history event');
|
||||
}
|
||||
|
||||
if (!config_update_value('history_db_host', get_parameter('history_db_host'))) {
|
||||
$error_update[] = __('Host');
|
||||
}
|
||||
|
||||
if (!config_update_value('history_db_port', get_parameter('history_db_port'))) {
|
||||
$error_update[] = __('Port');
|
||||
}
|
||||
|
||||
if (!config_update_value('history_db_name', get_parameter('history_db_name'))) {
|
||||
$error_update[] = __('Database name');
|
||||
}
|
||||
|
||||
if (!config_update_value('history_db_user', get_parameter('history_db_user'))) {
|
||||
$error_update[] = __('Database user');
|
||||
}
|
||||
@ -1507,6 +1521,72 @@ function config_update_config()
|
||||
) {
|
||||
$error_update[] = __('Delay');
|
||||
}
|
||||
|
||||
if ((bool) $config['history_db_enabled'] === true) {
|
||||
$dbm = new DBMaintainer(
|
||||
[
|
||||
'host' => $config['history_db_host'],
|
||||
'port' => $config['history_db_port'],
|
||||
'name' => $config['history_db_name'],
|
||||
'user' => $config['history_db_user'],
|
||||
'pass' => $config['history_db_pass'],
|
||||
]
|
||||
);
|
||||
|
||||
// Performs several checks and installs if needed.
|
||||
if ($dbm->check() === false) {
|
||||
$errors[] = $dbm->getLastError();
|
||||
}
|
||||
}
|
||||
|
||||
// Historical configuration tokens (stored in historical db).
|
||||
if (Config::set(
|
||||
'days_purge',
|
||||
get_parameter('history_dbh_purge'),
|
||||
true
|
||||
) !== true
|
||||
) {
|
||||
$error_update[] = __('Historical database purge');
|
||||
}
|
||||
|
||||
if (Config::set(
|
||||
'days_compact',
|
||||
get_parameter('history_dbh_days_compact'),
|
||||
true
|
||||
) !== true
|
||||
) {
|
||||
$error_update[] = __('Historical database days compact');
|
||||
}
|
||||
|
||||
if (Config::set(
|
||||
'step_compact',
|
||||
get_parameter('history_dbh_step_compact'),
|
||||
true
|
||||
) !== true
|
||||
) {
|
||||
$error_update[] = __('Historical database step compact');
|
||||
}
|
||||
|
||||
if (Config::set(
|
||||
'event_purge',
|
||||
get_parameter('history_dbh_events_purge'),
|
||||
true
|
||||
) !== true
|
||||
) {
|
||||
$error_update[] = __('Historical database events purge');
|
||||
}
|
||||
|
||||
if (Config::set(
|
||||
'string_purge',
|
||||
get_parameter('history_dbh_string_purge'),
|
||||
true
|
||||
) !== true
|
||||
) {
|
||||
$error_update[] = __('Historical database string purge');
|
||||
}
|
||||
|
||||
// Disable history db in history db.
|
||||
Config::set('history_db_enabled', 0, true);
|
||||
break;
|
||||
|
||||
case 'ehorus':
|
||||
@ -1675,6 +1755,14 @@ function config_update_config()
|
||||
$config['error_config_update_config']['correct'] = true;
|
||||
}
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$config['error_config_update_config']['errors'] = $errors;
|
||||
}
|
||||
|
||||
if (count($warnings) > 0) {
|
||||
$config['error_config_update_config']['warnings'] = $warnings;
|
||||
}
|
||||
|
||||
enterprise_include_once('include/functions_policies.php');
|
||||
$enterprise = enterprise_include_once('include/functions_skins.php');
|
||||
if ($enterprise !== ENTERPRISE_NOT_HOOK) {
|
||||
|
@ -3747,18 +3747,22 @@ function ui_print_event_priority(
|
||||
/**
|
||||
* Print a code into a DIV and enable a toggle to show and hide it.
|
||||
*
|
||||
* @param string $code Html code.
|
||||
* @param string $name Name of the link.
|
||||
* @param string $title Title of the link.
|
||||
* @param string $id Block id.
|
||||
* @param boolean $hidden_default If the div will be hidden by default (default: true).
|
||||
* @param boolean $return Whether to return an output string or echo now (default: true).
|
||||
* @param string $toggle_class Toggle class.
|
||||
* @param string $container_class Container class.
|
||||
* @param string $main_class Main object class.
|
||||
* @param string $img_a Image (closed).
|
||||
* @param string $img_b Image (opened).
|
||||
* @param string $clean Do not encapsulate with class boxes, clean print.
|
||||
* @param string $code Html code.
|
||||
* @param string $name Name of the link.
|
||||
* @param string $title Title of the link.
|
||||
* @param string $id Block id.
|
||||
* @param boolean $hidden_default If the div will be hidden by default (default: true).
|
||||
* @param boolean $return Whether to return an output string or echo now (default: true).
|
||||
* @param string $toggle_class Toggle class.
|
||||
* @param string $container_class Container class.
|
||||
* @param string $main_class Main object class.
|
||||
* @param string $img_a Image (closed).
|
||||
* @param string $img_b Image (opened).
|
||||
* @param string $clean Do not encapsulate with class boxes, clean print.
|
||||
* @param boolean $reverseImg Reverse image.
|
||||
* @param boolean $swtich Use switch input instead image.
|
||||
* @param string $attributes_switch Switch attributes (class...).
|
||||
* @param string|null $switch_name Use custom switch input name or generate one.
|
||||
*
|
||||
* @return string HTML.
|
||||
*/
|
||||
@ -3777,7 +3781,8 @@ function ui_toggle(
|
||||
$clean=false,
|
||||
$reverseImg=false,
|
||||
$switch=false,
|
||||
$attributes_switch=''
|
||||
$attributes_switch='',
|
||||
$switch_name=null
|
||||
) {
|
||||
// Generate unique Id.
|
||||
$uniqid = uniqid('');
|
||||
@ -3813,7 +3818,9 @@ function ui_toggle(
|
||||
$main_class = '';
|
||||
}
|
||||
|
||||
$container_class = 'white-box-content-clean';
|
||||
if ($container_class == 'white-box-content') {
|
||||
$container_class = 'white-box-content-clean';
|
||||
}
|
||||
}
|
||||
|
||||
// Link to toggle.
|
||||
@ -3821,11 +3828,15 @@ function ui_toggle(
|
||||
$output .= '<div class="'.$header_class.'" style="cursor: pointer;" id="tgl_ctrl_'.$uniqid.'">';
|
||||
if ($reverseImg === false) {
|
||||
if ($switch === true) {
|
||||
if (empty($switch_name) === true) {
|
||||
$switch_name = 'box_enable_toggle'.$uniqid;
|
||||
}
|
||||
|
||||
$output .= html_print_div(
|
||||
[
|
||||
'class' => 'float-left',
|
||||
'content' => html_print_checkbox_switch_extended(
|
||||
'box_enable_toggle'.$uniqid,
|
||||
$switch_name,
|
||||
1,
|
||||
($hidden_default === true) ? 0 : 1,
|
||||
false,
|
||||
@ -3895,7 +3906,7 @@ function ui_toggle(
|
||||
$output .= ' var hide_tgl_ctrl_'.$uniqid.' = '.(int) $hidden_default.";\n";
|
||||
$output .= ' /* <![CDATA[ */'."\n";
|
||||
$output .= " $(document).ready (function () {\n";
|
||||
$output .= " $('#checkbox-box_enable_toggle".$uniqid."').click(function() {\n";
|
||||
$output .= " $('#checkbox-".$switch_name."').click(function() {\n";
|
||||
$output .= ' if (hide_tgl_ctrl_'.$uniqid.") {\n";
|
||||
$output .= ' hide_tgl_ctrl_'.$uniqid." = 0;\n";
|
||||
$output .= " $('#tgl_div_".$uniqid."').toggle();\n";
|
||||
@ -3910,13 +3921,13 @@ function ui_toggle(
|
||||
$output .= ' hide_tgl_ctrl_'.$uniqid." = 0;\n";
|
||||
$output .= " $('#tgl_div_".$uniqid."').toggle();\n";
|
||||
$output .= " $('#image_".$uniqid."').attr({src: '".$image_a."'});\n";
|
||||
$output .= " $('#checkbox-box_enable_toggle".$uniqid."').prop('checked', true);\n";
|
||||
$output .= " $('#checkbox-".$switch_name."').prop('checked', true);\n";
|
||||
$output .= " }\n";
|
||||
$output .= " else {\n";
|
||||
$output .= ' hide_tgl_ctrl_'.$uniqid." = 1;\n";
|
||||
$output .= " $('#tgl_div_".$uniqid."').toggle();\n";
|
||||
$output .= " $('#image_".$uniqid."').attr({src: '".$image_b."'});\n";
|
||||
$output .= " $('#checkbox-box_enable_toggle".$uniqid."').prop('checked', false);\n";
|
||||
$output .= " $('#checkbox-".$switch_name."').prop('checked', false);\n";
|
||||
$output .= " }\n";
|
||||
$output .= " });\n";
|
||||
$output .= " });\n";
|
||||
@ -3947,7 +3958,11 @@ function ui_toggle(
|
||||
* - main_class
|
||||
* - img_a
|
||||
* - img_b
|
||||
* - clean.
|
||||
* - clean
|
||||
* - reverseImg
|
||||
* - switch
|
||||
* - attributes_switch
|
||||
* - switch_name.
|
||||
*
|
||||
* @return string HTML code with toggle content.
|
||||
*/
|
||||
@ -3965,7 +3980,11 @@ function ui_print_toggle($data)
|
||||
(isset($data['main_class']) === true) ? $data['main_class'] : 'box-shadow white_table_graph',
|
||||
(isset($data['img_a']) === true) ? $data['img_a'] : 'images/arrow_down_green.png',
|
||||
(isset($data['img_b']) === true) ? $data['img_b'] : 'images/arrow_right_green.png',
|
||||
(isset($data['clean']) === true) ? $data['clean'] : false
|
||||
(isset($data['clean']) === true) ? $data['clean'] : false,
|
||||
(isset($data['reverseImg']) === true) ? $data['reverseImg'] : false,
|
||||
(isset($data['switch']) === true) ? $data['switch'] : false,
|
||||
(isset($data['attributes_switch']) === true) ? $data['attributes_switch'] : '',
|
||||
(isset($data['switch_name']) === true) ? $data['switch_name'] : null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -48,19 +48,48 @@ final class Config
|
||||
|
||||
/**
|
||||
* Load history database settings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function loadHistoryDBSettings()
|
||||
{
|
||||
if (self::$settings === null) {
|
||||
$data = \db_get_all_rows_filter('tconfig', [], false, 'AND', true);
|
||||
self::$settings = array_reduce(
|
||||
$data,
|
||||
function ($carry, $item) {
|
||||
$carry[$item['token']] = $item['value'];
|
||||
},
|
||||
[]
|
||||
);
|
||||
global $config;
|
||||
|
||||
if ((bool) $config['history_db_enabled'] === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Connect if needed.
|
||||
if (isset($config['history_db_connection']) === false
|
||||
|| $config['history_db_connection'] === false
|
||||
) {
|
||||
ob_start();
|
||||
$config['history_db_connection'] = db_connect(
|
||||
$config['history_db_host'],
|
||||
$config['history_db_name'],
|
||||
$config['history_db_user'],
|
||||
io_output_password($config['history_db_pass']),
|
||||
$config['history_db_port'],
|
||||
false
|
||||
);
|
||||
ob_get_clean();
|
||||
}
|
||||
|
||||
$data = \db_get_all_rows_sql(
|
||||
'SELECT * FROM `tconfig`',
|
||||
false,
|
||||
false,
|
||||
$config['history_db_connection']
|
||||
);
|
||||
|
||||
self::$settings = array_reduce(
|
||||
$data,
|
||||
function ($carry, $item) {
|
||||
$carry[$item['token']] = $item['value'];
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -80,6 +109,7 @@ final class Config
|
||||
) {
|
||||
if ($history_db === true) {
|
||||
self::loadHistoryDBSettings();
|
||||
|
||||
if (isset(self::$settings[$token]) === true) {
|
||||
return self::$settings[$token];
|
||||
}
|
||||
@ -103,18 +133,46 @@ final class Config
|
||||
* @param mixed $value Value to be.
|
||||
* @param boolean $history_db Save to history_db settings.
|
||||
*
|
||||
* @return void
|
||||
* @return boolean Success or not.
|
||||
*/
|
||||
public static function set(string $token, $value, bool $history_db=false)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$rs = false;
|
||||
|
||||
if ($history_db !== false) {
|
||||
if (self::get($token, null, $history_db) === null) {
|
||||
// Create.
|
||||
$rs = \db_process_sql(
|
||||
sprintf(
|
||||
'INSERT INTO `tconfig` (`token`, `value`)
|
||||
VALUES ("%s", "%s")',
|
||||
$token,
|
||||
$value
|
||||
),
|
||||
'affected_rows',
|
||||
$config['history_db_connection']
|
||||
);
|
||||
} else {
|
||||
// Update.
|
||||
$rs = \db_process_sql(
|
||||
sprintf(
|
||||
'UPDATE `tconfig`
|
||||
SET `value`= "%s"
|
||||
WHERE `token` = "%s"',
|
||||
$value,
|
||||
$token
|
||||
),
|
||||
'affected_rows',
|
||||
$config['history_db_connection']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (self::get($token) === null) {
|
||||
config_update_value($token, $value);
|
||||
}
|
||||
$rs = \config_update_value($token, $value);
|
||||
}
|
||||
|
||||
return ($rs !== false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace PandoraFMS\Core;
|
||||
/**
|
||||
* Class to handle database mantainer (not queries).
|
||||
*/
|
||||
final class DBMantainer
|
||||
final class DBMaintainer
|
||||
{
|
||||
const ESSENTIAL_TABLES = [
|
||||
'tagente_datos',
|
@ -732,7 +732,7 @@ div#container {
|
||||
margin: 0 auto;
|
||||
min-width: 960px;
|
||||
text-align: left;
|
||||
height: 100%;
|
||||
min-height: 100%;
|
||||
background: #fff;
|
||||
width: 100%;
|
||||
}
|
||||
|
@ -3,3 +3,13 @@ span.subtitle {
|
||||
font-weight: normal;
|
||||
font-family: "lato-bolder";
|
||||
}
|
||||
|
||||
span.subtitle-2 {
|
||||
font-size: 1em;
|
||||
font-weight: normal;
|
||||
font-family: "lato-bolder";
|
||||
}
|
||||
|
||||
.no-borders {
|
||||
border: 0 !important;
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ return array(
|
||||
'Mpdf\\Utils\\UtfString' => $vendorDir . '/mpdf/mpdf/src/Utils/UtfString.php',
|
||||
'PandoraFMS\\Agent' => $baseDir . '/include/lib/Agent.php',
|
||||
'PandoraFMS\\Core\\Config' => $baseDir . '/include/lib/Core/Config.php',
|
||||
'PandoraFMS\\Core\\DBMantainer' => $baseDir . '/include/lib/Core/DBMantainer.php',
|
||||
'PandoraFMS\\Core\\DBMaintainer' => $baseDir . '/include/lib/Core/DBMaintainer.php',
|
||||
'PandoraFMS\\Dashboard\\Cell' => $baseDir . '/include/lib/Dashboard/Cell.php',
|
||||
'PandoraFMS\\Dashboard\\Manager' => $baseDir . '/include/lib/Dashboard/Manager.php',
|
||||
'PandoraFMS\\Dashboard\\Widget' => $baseDir . '/include/lib/Dashboard/Widget.php',
|
||||
|
@ -392,7 +392,7 @@ class ComposerStaticInitfdecadadce22e6dde51e9535fe4ad7aa
|
||||
'Mpdf\\Utils\\UtfString' => __DIR__ . '/..' . '/mpdf/mpdf/src/Utils/UtfString.php',
|
||||
'PandoraFMS\\Agent' => __DIR__ . '/../..' . '/include/lib/Agent.php',
|
||||
'PandoraFMS\\Core\\Config' => __DIR__ . '/../..' . '/include/lib/Core/Config.php',
|
||||
'PandoraFMS\\Core\\DBMantainer' => __DIR__ . '/../..' . '/include/lib/Core/DBMantainer.php',
|
||||
'PandoraFMS\\Core\\DBMaintainer' => __DIR__ . '/../..' . '/include/lib/Core/DBMaintainer.php',
|
||||
'PandoraFMS\\Dashboard\\Cell' => __DIR__ . '/../..' . '/include/lib/Dashboard/Cell.php',
|
||||
'PandoraFMS\\Dashboard\\Manager' => __DIR__ . '/../..' . '/include/lib/Dashboard/Manager.php',
|
||||
'PandoraFMS\\Dashboard\\Widget' => __DIR__ . '/../..' . '/include/lib/Dashboard/Widget.php',
|
||||
|
Loading…
x
Reference in New Issue
Block a user