Merge branch 'ent-4190-mejoras-para-el-menu-de-gestionar-ha' into 'develop'

pandora HA review

See merge request artica/pandorafms!2654
This commit is contained in:
Alejandro Fraguas 2019-09-20 13:57:03 +02:00
commit 0418c86867
12 changed files with 190 additions and 61 deletions

View File

@ -1,9 +1,21 @@
START TRANSACTION;
ALTER TABLE `tdatabase` MODIFY `last_error` text;
ALTER TABLE `tdatabase` MODIFY `host` VARCHAR(255) DEFAULT '';
ALTER TABLE `tdatabase` ADD COLUMN `label` VARCHAR(255) DEFAULT '';
ALTER TABLE `tdatabase` MODIFY `os_user` VARCHAR(255) DEFAULT '';
ALTER TABLE `tdatabase` MODIFY `db_port` INT UNSIGNED NOT NULL DEFAULT 3306;
ALTER TABLE `tdatabase` MODIFY `os_port` INT UNSIGNED NOT NULL DEFAULT 22;
ALTER TABLE `tdatabase` ADD COLUMN `ssh_key` TEXT;
ALTER TABLE `tdatabase` ADD COLUMN `ssh_pubkey` TEXT;
UPDATE `tdatabase` set `label`=`host`;
UPDATE `tlayout_data` SET `height` = 70 , `width` = 70 WHERE `height` = 0 && `width` = 0 && image NOT LIKE '%dot%' && ((`type` IN (0,5)) ||
(`type` = 10 && `image` IS NOT NULL && `image` != '' && `image` != 'none') ||
(`type` = 11 && `image` IS NOT NULL && `image` != '' && `image` != 'none' && `show_statistics` = 0));
ALTER TABLE `treport_content` ADD COLUMN `uncompressed_module` TINYINT DEFAULT '0';
ALTER TABLE `treport_content_template` ADD COLUMN `uncompressed_module` TINYINT DEFAULT '0';

View File

@ -219,14 +219,17 @@ CREATE TABLE IF NOT EXISTS `tdashboard` (
-- Table `tdatabase`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tdatabase` (
`id` int(10) unsigned NOT NULL auto_increment,
`host` varchar(100) default '',
`os_port` int(4) unsigned default '22',
`os_user` varchar(100) default '',
`db_port` int(4) unsigned default '3306',
`id` INT(10) unsigned NOT NULL auto_increment,
`host` VARCHAR(255) default '',
`label` VARCHAR(255) default '',
`os_port` INT UNSIGNED NOT NULL DEFAULT 22,
`os_user` VARCHAR(255) default '',
`db_port` INT UNSIGNED NOT NULL DEFAULT 3306,
`status` tinyint(1) unsigned default '0',
`action` tinyint(1) unsigned default '0',
`last_error` varchar(255) default '',
`ssh_key` TEXT,
`ssh_pubkey` TEXT,
`last_error` TEXT,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 ;

View File

@ -1,15 +1,25 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2018 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* Manage database HA cluster.
*
* @category Manager
* @package Pandora FMS
* @subpackage Database HA cluster
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2007-2012 Artica Soluciones Tecnologicas, http://www.artica.es
* This code is NOT free software. This code is NOT licenced under GPL2 licence
* You cannnot redistribute it without written permission of copyright holder.
* ============================================================================
*/
global $config;
check_login();
@ -24,8 +34,6 @@ if (! check_acl($config['id_user'], 0, 'PM')) {
}
ui_require_css_file('firts_task');
?>
<?php
ui_print_info_message(['no_close' => true, 'message' => __('There are no HA clusters defined yet.') ]);
?>
@ -44,8 +52,9 @@ ui_print_info_message(['no_close' => true, 'message' => __('There are no HA clus
</p>
<?php
if (check_acl($config['id_user'], 0, 'AW')) {
if (check_acl($config['id_user'], 0, 'PM')) {
echo "<div id='create_master_window'></div>";
echo "<div id='msg'></div>";
?>
<input style="margin-bottom:20px;" onclick="show_create_ha_cluster();" type="submit" class="button_task" value="<?php echo __('Add new node'); ?>" />
<?php
@ -53,35 +62,3 @@ ui_print_info_message(['no_close' => true, 'message' => __('There are no HA clus
?>
</div>
</div>
<script type="text/javascript">
function show_create_ha_cluster() {
var params = {};
params["dialog_master"] = 1;
params["page"] = "enterprise/include/ajax/HA_cluster.ajax";
jQuery.ajax ({
data: params,
dataType: "html",
type: "POST",
url: "ajax.php",
success: function (data) {
$("#create_master_window").dialog ({
title: '<?php echo __('Add master node'); ?>',
resizable: true,
draggable: true,
modal: true,
close: function() {
},
overlay: {
opacity: 0.5,
background: "black"
},
width: 800,
height: 600
}).empty()
.html(data)
.show ();
}
});
}
</script>

View File

@ -630,3 +630,21 @@ define('DEFAULT_NODE_COLOR', COL_NOTINIT);
define('DEFAULT_NODE_IMAGE', 'images/networkmap/unknown.png');
define('NODE_IMAGE_PADDING', 5);
// Pandora Database HA constants.
define('HA_ACTION_NONE', 0);
define('HA_ACTION_DEPLOY', 1);
define('HA_ACTION_RECOVER', 2);
define('HA_ACTION_PROMOTE', 3);
define('HA_ACTION_DEMOTE', 4);
define('HA_ACTION_DISABLE', 5);
define('HA_ACTION_ENABLE', 6);
define('HA_ACTION_CLEANUP', 7);
define('HA_ACTION_RESYNC', 8);
define('HA_UNINITIALIZED', 0);
define('HA_ONLINE', 1);
define('HA_PENDING', 2);
define('HA_PROCESSING', 3);
define('HA_DISABLED', 4);
define('HA_FAILED', 5);

View File

@ -68,6 +68,57 @@ function agents_get_agent_id_by_module_id($id_agente_modulo)
}
/**
* Search for agent data anywhere.
*
* Note: This method matches with server (perl) locate_agent.
* Do not change order!
*
* @param string $field Alias, name or IP address of searchable agent.
*
* @return array Agent of false if not found.
*/
function agents_locate_agent(string $field)
{
global $config;
$table = 'tagente';
if (is_metaconsole()) {
$table = 'tmetaconsole_agent';
}
// Alias.
$sql = sprintf(
'SELECT *
FROM %s
WHERE alias = "%s"',
$table,
$field
);
$agent = db_get_row_sql($sql);
if ($agent !== false) {
return $agent;
}
// Addr.
$agent = agents_get_agent_with_ip($field);
if ($agent !== false) {
return $agent;
}
// Name.
$sql = sprintf(
'SELECT *
FROM %s
WHERE nombre = "%s"',
$table,
$field
);
return db_get_row_sql($sql);
}
/**
* Get agent id from an agent alias.
*

View File

@ -46,6 +46,25 @@ function db_select_engine()
}
/**
* Connects to target DB.
*
* @param array $setup Database definition.
*
* @return mixed Dbconnection or null.
*/
function get_dbconnection(array $setup)
{
return mysqli_connect(
$setup['dbhost'],
$setup['dbuser'],
$setup['dbpass'],
$setup['dbname'],
$setup['dbport']
);
}
function db_connect($host=null, $db=null, $user=null, $pass=null, $port=null, $critical=true, $charset=null)
{
global $config;

View File

@ -98,6 +98,23 @@ function hd($var, $file='', $oneline=false)
}
/**
* Encapsulation (ob) for debug print function.
*
* @param mixed $var Variable to be dumped.
* @param string $file Target file path.
* @param boolean $oneline Show in oneline.
*
* @return string Dump string.
*/
function obhd($var, $file='', $oneline=false)
{
ob_start();
hd($var, $file, $oneline);
return ob_get_clean();
}
function debug()
{
$args_num = func_num_args();
@ -1570,6 +1587,7 @@ function html_print_input_image($name, $src, $value, $style='', $return=false, $
'onkeypress',
'onkeydown',
'onkeyup',
'class',
];
foreach ($attrs as $attribute) {
@ -3152,7 +3170,8 @@ function html_print_input($data, $wrapper='div', $input_only=false)
((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['disabled']) === true) ? $data['disabled'] : false),
((isset($data['required']) === true) ? $data['required'] : false),
((isset($data['class']) === true) ? $data['class'] : '')
((isset($data['class']) === true) ? $data['class'] : ''),
((isset($data['autocomplete']) === true) ? $data['autocomplete'] : 'off')
);
break;

View File

@ -2679,6 +2679,7 @@ function get_shape_status_set($type)
case STATUS_MODULE_UNKNOWN:
case STATUS_AGENT_UNKNOWN:
case STATUS_AGENT_DOWN:
case STATUS_AGENT_NO_MONITORS:
$return = ['class' => 'status_rounded_rectangles'];
break;

View File

@ -1915,8 +1915,10 @@ function load_modal(settings) {
text: settings.modal.cancel,
click: function() {
$(this).dialog("close");
if (typeof settings.cleanup == "function") {
settings.cleanup();
}
}
},
{
class:

View File

@ -452,6 +452,9 @@ select:-internal-list-box {
.mw120px {
min-width: 120px;
}
.mw180px {
min-width: 180px;
}
.mw250px {
min-width: 250px;
}
@ -3182,6 +3185,7 @@ table#policy_modules td * {
#news_board {
min-width: 530px;
width: 100%;
}
#right_column_logon_ok {

View File

@ -2439,14 +2439,17 @@ CREATE TABLE IF NOT EXISTS `tdashboard` (
-- Table `tdatabase`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tdatabase` (
`id` int(10) unsigned NOT NULL auto_increment,
`host` varchar(100) default '',
`os_port` int(4) unsigned default '22',
`os_user` varchar(100) default '',
`db_port` int(4) unsigned default '3306',
`id` INT(10) unsigned NOT NULL auto_increment,
`host` VARCHAR(255) default '',
`label` VARCHAR(255) default '',
`os_port` INT UNSIGNED NOT NULL DEFAULT 22,
`os_user` VARCHAR(255) default '',
`db_port` INT UNSIGNED NOT NULL DEFAULT 3306,
`status` tinyint(1) unsigned default '0',
`action` tinyint(1) unsigned default '0',
`last_error` varchar(255) default '',
`ssh_key` TEXT,
`ssh_pubkey` TEXT,
`last_error` TEXT,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 ;

View File

@ -140,6 +140,7 @@ our @EXPORT = qw(
generate_agent_name_hash
long_to_ip
ip_to_long
get_enabled_servers
);
# ID of the different servers
@ -2053,6 +2054,25 @@ sub long_to_ip {
return inet_ntoa pack("N", ($ip_long));
}
###############################################################################
# Returns a list with enabled servers.
###############################################################################
sub get_enabled_servers {
my $conf = shift;
if (ref($conf) ne "HASH") {
return ();
}
my @server_list = map {
if ($_ =~ /server$/i && $conf->{$_} > 0) {
$_
} else {
}
} keys %{$conf};
return @server_list;
}
# End of function declaration
# End of defined Code