Merge branch 'ent-4289-8282-RWORKS-Poder-escoger-el-servidor-que-ejecute-una-CronJob' into 'develop'
implemented consoles management See merge request artica/pandorafms!5558
This commit is contained in:
commit
35a1c2332d
|
@ -1,5 +1,19 @@
|
|||
START TRANSACTION;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tconsole` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id_console` BIGINT NOT NULL DEFAULT 0,
|
||||
`description` TEXT,
|
||||
`version` TINYTEXT,
|
||||
`last_execution` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`console_type` TINYINT NOT NULL DEFAULT 0,
|
||||
`timezone` TINYTEXT,
|
||||
`public_url` TEXT,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
ALTER TABLE `tuser_task_scheduled` ADD COLUMN `id_console` BIGINT NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE `tdatabase` ADD COLUMN `ssh_status` TINYINT UNSIGNED DEFAULT 0;
|
||||
ALTER TABLE `tdatabase` ADD COLUMN `db_status` TINYINT UNSIGNED DEFAULT 0;
|
||||
ALTER TABLE `tdatabase` ADD COLUMN `replication_status` TINYINT UNSIGNED DEFAULT 0;
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Consoles manager.
|
||||
*
|
||||
* @category Tools
|
||||
* @package Pandora FMS
|
||||
* @subpackage Enterprise
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2021 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 for 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
use PandoraFMS\Console;
|
||||
use PandoraFMS\View;
|
||||
|
||||
// Begin.
|
||||
global $config;
|
||||
check_login();
|
||||
|
||||
if (check_acl($config['id_user'], 0, 'PM') === false
|
||||
&& is_user_admin($config['id_user']) === false
|
||||
) {
|
||||
db_pandora_audit(
|
||||
AUDIT_LOG_ACL_VIOLATION,
|
||||
'Trying to access Consoles Management'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$ajax_url = ui_get_full_url('ajax.php');
|
||||
|
||||
$message = '';
|
||||
$error = false;
|
||||
|
||||
// Check is any consoles are registered.
|
||||
$results = db_get_all_rows_in_table('tconsole');
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($results === false) {
|
||||
$message = ui_print_info_message(
|
||||
__('If you want to have your consoles registered, you must define them by editing config.php in each individual console and wait for cron to run in order to be registered.')
|
||||
);
|
||||
}
|
||||
|
||||
View::render(
|
||||
'consoles/list',
|
||||
[
|
||||
'ajax_url' => $ajax_url,
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
|
@ -308,6 +308,13 @@ if ($access_console_node === true) {
|
|||
$sub['godmode/servers/modificar_server']['id'] = 'Manage_servers';
|
||||
}
|
||||
|
||||
if ((bool) check_acl($config['id_user'], 0, 'PM') === true
|
||||
|| is_user_admin($config['id_user']) === true
|
||||
) {
|
||||
$sub['godmode/consoles/consoles']['text'] = __('Manage consoles');
|
||||
$sub['godmode/consoles/consoles']['id'] = 'Manage consoles';
|
||||
}
|
||||
|
||||
// This subtabs are only for Pandora Admin.
|
||||
if ((bool) check_acl($config['id_user'], 0, 'PM') === true) {
|
||||
enterprise_hook('ha_cluster');
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/**
|
||||
* Ajax script for Consoles' List view.
|
||||
*
|
||||
* @category Consoles
|
||||
* @package Community
|
||||
* @subpackage Software agents repository
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ==========================================================
|
||||
* Copyright (c) 2005-2022 Artica Soluciones Tecnológicas S.L
|
||||
* This code is NOT free software. This code is NOT licenced under GPL2 licence
|
||||
* You cannot redistribute it without written permission of copyright holder.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Begin.
|
||||
global $config;
|
||||
|
||||
// Login check.
|
||||
check_login();
|
||||
|
||||
require_once $config['homedir'].'/include/functions_ui.php';
|
||||
|
||||
use PandoraFMS\Console;
|
||||
|
||||
if (check_acl($config['id_user'], 0, 'PM') === false
|
||||
&& is_user_admin($config['id_user']) === false
|
||||
) {
|
||||
db_pandora_audit(
|
||||
AUDIT_LOG_ACL_VIOLATION,
|
||||
'Trying to access Consoles Management'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$get_all_datatables_formatted = (bool) get_parameter('get_all_datatables_formatted');
|
||||
$delete = (bool) get_parameter('delete');
|
||||
|
||||
if ($get_all_datatables_formatted === true) {
|
||||
$results = db_get_all_rows_in_table('tconsole', 'id_console');
|
||||
|
||||
if ($results === false) {
|
||||
$results = [];
|
||||
}
|
||||
|
||||
$count = count($results);
|
||||
|
||||
if ($results) {
|
||||
$data = array_reduce(
|
||||
$results,
|
||||
function ($carry, $item) {
|
||||
$item['last_execution'] = ui_print_timestamp($item['last_execution'], true);
|
||||
$item['console_type'] = ((int) $item['console_type'] === 1) ? __('Reporting').'  '.html_print_image('images/report_list.png', true) : __('Standard');
|
||||
// Transforms array of arrays $data into an array
|
||||
// of objects, making a post-process of certain fields.
|
||||
$tmp = (object) $item;
|
||||
$carry[] = $tmp;
|
||||
return $carry;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Datatables format: RecordsTotal && recordsfiltered.
|
||||
echo json_encode(
|
||||
[
|
||||
'data' => $data,
|
||||
'recordsTotal' => $count,
|
||||
'recordsFiltered' => $count,
|
||||
]
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($delete === true) {
|
||||
$id = get_parameter('id');
|
||||
|
||||
try {
|
||||
$console = new Console($id);
|
||||
$console->delete();
|
||||
$console->save();
|
||||
echo json_encode(['result' => __('Console successfully deleted')]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['result' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
// phpcs:disable Squiz.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Console entity class.
|
||||
*
|
||||
* @category Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage OpenSource
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2021 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 for 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Begin.
|
||||
namespace PandoraFMS;
|
||||
|
||||
/**
|
||||
* PandoraFMS console entity.
|
||||
*/
|
||||
class Console extends Entity
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Builds a PandoraFMS\Console object from given id.
|
||||
*
|
||||
* @param integer $id Id console.
|
||||
*/
|
||||
public function __construct(?int $id=null)
|
||||
{
|
||||
$table = 'tconsole';
|
||||
$filter = ['id' => $id];
|
||||
|
||||
$this->existsInDB = false;
|
||||
|
||||
if (is_numeric($id) === true
|
||||
&& $id > 0
|
||||
) {
|
||||
parent::__construct(
|
||||
$table,
|
||||
$filter,
|
||||
null,
|
||||
false
|
||||
);
|
||||
$this->existsInDB = true;
|
||||
} else {
|
||||
// Create empty skel.
|
||||
parent::__construct($table, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves current definition of a Console to database.
|
||||
*
|
||||
* @return mixed Affected rows of false in case of error.
|
||||
* @throws \Exception On error.
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if ($this->fields['id'] > 0) {
|
||||
// Update.
|
||||
$updates = $this->fields;
|
||||
|
||||
$rs = \db_process_sql_update(
|
||||
$this->table,
|
||||
$updates,
|
||||
['id' => $this->fields['id']]
|
||||
);
|
||||
|
||||
if ($rs === false) {
|
||||
global $config;
|
||||
throw new \Exception(
|
||||
__METHOD__.' error: '.$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Creation.
|
||||
$inserts = $this->fields;
|
||||
|
||||
// Clean null fields.
|
||||
foreach ($inserts as $k => $v) {
|
||||
if ($v === null) {
|
||||
unset($inserts[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
$rs = \db_process_sql_insert(
|
||||
$this->table,
|
||||
$inserts
|
||||
);
|
||||
|
||||
if ($rs === false) {
|
||||
global $config;
|
||||
throw new \Exception(
|
||||
__METHOD__.' error: '.$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
|
||||
$this->fields['id'] = $rs;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove this Console.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if ($this->existsInDB === true) {
|
||||
\db_process_delete_temp(
|
||||
$this->table,
|
||||
'id',
|
||||
$this->fields['id']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3769,6 +3769,7 @@ CREATE TABLE IF NOT EXISTS `tuser_task_scheduled` (
|
|||
`flag_delete` TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`id_grupo` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`enabled` TINYINT UNSIGNED NOT NULL DEFAULT 1,
|
||||
`id_console` BIGINT NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
|
@ -4189,6 +4190,21 @@ CREATE TABLE IF NOT EXISTS `tmonitor_filter` (
|
|||
PRIMARY KEY (`id_filter`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Table `tconsole`
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `tconsole` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id_console` BIGINT NOT NULL DEFAULT 0,
|
||||
`description` TEXT,
|
||||
`version` TINYTEXT,
|
||||
`last_execution` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`console_type` TINYINT NOT NULL DEFAULT 0,
|
||||
`timezone` TINYTEXT,
|
||||
`public_url` TEXT,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Table `tagent_filter`
|
||||
-- ---------------------------------------------------------------------
|
||||
|
@ -4207,6 +4223,7 @@ CREATE TABLE IF NOT EXISTS `tagent_filter` (
|
|||
PRIMARY KEY (`id_filter`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Table `tevent_sound`
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE TABLE `tevent_sound` (
|
||||
|
|
|
@ -0,0 +1,217 @@
|
|||
<?php
|
||||
/**
|
||||
* Console: Consoles list page.
|
||||
*
|
||||
* @category View
|
||||
* @package Pandora FMS
|
||||
* @subpackage Alert
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2021 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 for 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Header.
|
||||
\ui_print_page_header(
|
||||
// Title.
|
||||
__('%s registered consoles', $config['rb_product_name']),
|
||||
// Icon.
|
||||
'',
|
||||
// Return.
|
||||
false,
|
||||
// Help.
|
||||
'',
|
||||
// Godmode.
|
||||
true,
|
||||
// Options.
|
||||
''
|
||||
);
|
||||
|
||||
if (empty($message) === false) {
|
||||
echo $message;
|
||||
}
|
||||
|
||||
// Auxiliar to display deletion modal.
|
||||
echo '<div id="delete_modal" class="invisible"></div>';
|
||||
echo '<div id="msg" class="invisible"></div>';
|
||||
|
||||
|
||||
// Consoles list.
|
||||
try {
|
||||
$columns = [
|
||||
'id_console',
|
||||
'description',
|
||||
'version',
|
||||
'last_execution',
|
||||
'console_type',
|
||||
'timezone',
|
||||
'public_url',
|
||||
'options',
|
||||
];
|
||||
|
||||
$column_names = [
|
||||
__('Console ID'),
|
||||
__('Description'),
|
||||
__('Version'),
|
||||
__('Last Execution'),
|
||||
__('Console type'),
|
||||
__('Timezone'),
|
||||
__('Public URL'),
|
||||
[
|
||||
'text' => __('Options'),
|
||||
'class' => 'action_buttons',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$tableId = 'consoles_list';
|
||||
// Load datatables user interface.
|
||||
ui_print_datatable(
|
||||
[
|
||||
'id' => $tableId,
|
||||
'class' => 'info_table',
|
||||
'style' => 'width: 99%',
|
||||
'columns' => $columns,
|
||||
'column_names' => $column_names,
|
||||
'ajax_url' => 'include/ajax/consoles.ajax',
|
||||
'ajax_data' => ['get_all_datatables_formatted' => 1],
|
||||
'ajax_postprocess' => 'process_datatables_item(item)',
|
||||
'no_sortable_columns' => [-1],
|
||||
'order' => [
|
||||
'field' => 'id',
|
||||
'direction' => 'asc',
|
||||
],
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
/**
|
||||
* Process datatable item before draw it.
|
||||
*/
|
||||
function process_datatables_item(item) {
|
||||
item.options = '<a href="javascript:" onclick="delete_key(\'';
|
||||
item.options += item.id;
|
||||
item.options += '\')" ><?php echo html_print_image('images/cross.png', true, ['title' => __('Delete'), 'class' => 'invert_filter']); ?></a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete selected key
|
||||
*/
|
||||
function delete_key(id) {
|
||||
$('#delete_modal').empty();
|
||||
$('#delete_modal').html('<?php echo __('<span>Are you sure?</span><br><br><i>WARNING: you also need to delete config.php options in your console or delete the whole console.</i>'); ?>');
|
||||
$('#delete_modal').dialog({
|
||||
title: '<?php echo __('Delete'); ?>',
|
||||
buttons: [
|
||||
{
|
||||
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel',
|
||||
text: '<?php echo __('Cancel'); ?>',
|
||||
click: function(e) {
|
||||
$(this).dialog('close');
|
||||
cleanupDOM();
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
text: 'Delete',
|
||||
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next',
|
||||
click: function(e) {
|
||||
$.ajax({
|
||||
method: 'post',
|
||||
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
|
||||
data: {
|
||||
page: 'include/ajax/consoles.ajax',
|
||||
delete: 1,
|
||||
id
|
||||
},
|
||||
datatype: "json",
|
||||
success: function (data) {
|
||||
showMsg(data);
|
||||
},
|
||||
error: function(e) {
|
||||
showMsg(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Process ajax responses and shows a dialog with results.
|
||||
*/
|
||||
function showMsg(data) {
|
||||
var title = "<?php echo __('Success'); ?>";
|
||||
var dt_satellite_agents = $("#<?php echo $tableId; ?>").DataTable();
|
||||
dt_<?php echo $tableId; ?>.draw(false);
|
||||
|
||||
var text = '';
|
||||
var failed = 0;
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
text = data['result'];
|
||||
} catch (err) {
|
||||
title = "<?php echo __('Failed'); ?>";
|
||||
text = err.message;
|
||||
failed = 1;
|
||||
}
|
||||
if (!failed && data['error'] != undefined) {
|
||||
title = "<?php echo __('Failed'); ?>";
|
||||
text = data['error'];
|
||||
failed = 1;
|
||||
}
|
||||
if (data['report'] != undefined) {
|
||||
data['report'].forEach(function (item){
|
||||
text += '<br>'+item;
|
||||
});
|
||||
}
|
||||
|
||||
$('#msg').empty();
|
||||
$('#msg').html(text);
|
||||
$('#msg').dialog({
|
||||
width: 450,
|
||||
position: {
|
||||
my: 'center',
|
||||
at: 'center',
|
||||
of: window,
|
||||
collision: 'fit'
|
||||
},
|
||||
title: title,
|
||||
buttons: [
|
||||
{
|
||||
class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
|
||||
text: 'OK',
|
||||
click: function(e) {
|
||||
if (!failed) {
|
||||
$(".ui-dialog-content").dialog("close");
|
||||
$('.info').hide();
|
||||
} else {
|
||||
$(this).dialog('close');
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue