pandora HA review

This commit is contained in:
fbsanchez 2019-08-10 02:13:01 +02:00
parent 4f25e42be1
commit adbb48ab87
11 changed files with 148 additions and 60 deletions

View File

@ -9,4 +9,13 @@ DELETE FROM `tconfig` WHERE `token` LIKE 'integria_api_password';
DELETE FROM `tconfig` WHERE `token` LIKE 'integria_inventory';
DELETE FROM `tconfig` WHERE `token` LIKE 'integria_url';
ALTER TABLE `tdatabase` MODIFY `last_error` text;
ALTER TABLE `tdatabase` MODIFY `host` VARCHAR(255);
ALTER TABLE `tdatabase` ADD COLUMN `label` VARCHAR(255);
ALTER TABLE `tdatabase` MODIFY `os_user` VARCHAR(255);
ALTER TABLE `tdatabase` MODIFY `db_port` INT UNSIGNED NOT NULL;
ALTER TABLE `tdatabase` MODIFY `os_port` INT UNSIGNED NOT NULL;
ALTER TABLE `tdatabase` ADD COLUMN `ssh_key` TEXT;
ALTER TABLE `tdatabase` ADD COLUMN `ssh_pubkey` TEXT;
COMMIT;

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 default 22,
`os_user` VARCHAR(255) default '',
`db_port` int unsigned 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

@ -624,3 +624,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

@ -1570,6 +1570,7 @@ function html_print_input_image($name, $src, $value, $style='', $return=false, $
'onkeypress',
'onkeydown',
'onkeyup',
'class',
];
foreach ($attrs as $attribute) {
@ -3152,7 +3153,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

@ -2678,6 +2678,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;
}

View File

@ -2438,14 +2438,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 default 22,
`os_user` VARCHAR(255) default '',
`db_port` int unsigned 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 ;