Custom id improvements
This commit is contained in:
parent
cfe2b108af
commit
867fccf604
|
@ -528,10 +528,10 @@ $table_advanced->data[0][1] = html_print_input_text(
|
|||
20,
|
||||
65,
|
||||
true,
|
||||
$disabledBecauseInPolicy,
|
||||
(($config['module_custom_id_ro']) ? true : $disabledBecauseInPolicy),
|
||||
false,
|
||||
'',
|
||||
$classdisabledBecauseInPolicy
|
||||
(($config['module_custom_id_ro']) ? 'readonly' : $classdisabledBecauseInPolicy)
|
||||
);
|
||||
|
||||
$table_advanced->data[0][3] = __('Unit');
|
||||
|
|
|
@ -344,6 +344,9 @@ $table->data[$i++][1] = html_print_checkbox_switch('console_log_enabled', 1, $co
|
|||
$table->data[$i][0] = __('Enable audit log').ui_print_help_tip(__('Log location').': pandora_console/log/audit.log', true);
|
||||
$table->data[$i++][1] = html_print_checkbox_switch('audit_log_enabled', 1, $config['audit_log_enabled'], true);
|
||||
|
||||
$table->data[$i][0] = __('Module custom ID readonly').ui_print_help_tip(__('Useful for integrations'), true);
|
||||
$table->data[$i++][1] = html_print_checkbox_switch('module_custom_id_ro', 1, $config['module_custom_id_ro'], true);
|
||||
|
||||
echo '<form id="form_setup" method="post" action="index.php?sec=gsetup&sec2=godmode/setup/setup&section=general&pure='.$config['pure'].'">';
|
||||
|
||||
echo '<fieldset>';
|
||||
|
@ -387,7 +390,7 @@ $table_mail_conf->data[6][1] = html_print_input_password('email_password', io_ou
|
|||
|
||||
$uniqid = uniqid();
|
||||
|
||||
$table_mail_conf->data[7][0] = html_print_button(__('Email test'), 'email_test_dialog', false, "show_email_test('$uniqid');", 'class="sub next"', true);
|
||||
$table_mail_conf->data[7][0] = html_print_button(__('Email test'), 'email_test_dialog', false, "show_email_test('".$uniqid."');", 'class="sub next"', true);
|
||||
|
||||
print_email_test_modal_window($uniqid);
|
||||
|
||||
|
@ -404,7 +407,14 @@ html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'
|
|||
echo '</div>';
|
||||
echo '</form>';
|
||||
|
||||
// Print the modal window for the summary of each alerts group
|
||||
|
||||
/**
|
||||
* Print the modal window for the summary of each alerts group
|
||||
*
|
||||
* @param string $id Id.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function print_email_test_modal_window($id)
|
||||
{
|
||||
// Email config table.
|
||||
|
|
|
@ -35,6 +35,9 @@ enterprise_include_once('include/functions_modules.php');
|
|||
enterprise_include_once('include/functions_clusters.php');
|
||||
enterprise_include_once('include/functions_alerts.php');
|
||||
|
||||
// Clases.
|
||||
use PandoraFMS\Module;
|
||||
|
||||
|
||||
/**
|
||||
* Parse the "other" parameter.
|
||||
|
@ -2515,6 +2518,70 @@ function api_get_module_id($id, $thrash1, $name, $thrash3)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves custom_id from given module_id.
|
||||
*
|
||||
* @param integer $id Module id.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function api_get_module_custom_id($id)
|
||||
{
|
||||
if (is_metaconsole()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$module = new Module($id);
|
||||
if (!util_api_check_agent_and_print_error(
|
||||
$module->id_agente(),
|
||||
'json'
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
returnError('id_not_found', 'json');
|
||||
}
|
||||
|
||||
returnData('json', $module->custom_id());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves custom_id from given module_id.
|
||||
*
|
||||
* @param integer $id Module id.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function api_set_module_custom_id($id, $value)
|
||||
{
|
||||
if (is_metaconsole()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$module = new Module($id);
|
||||
if (!util_api_check_agent_and_print_error(
|
||||
$module->id_agente(),
|
||||
'json',
|
||||
'AW'
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$module->custom_id($value);
|
||||
$module->save();
|
||||
} catch (Exception $e) {
|
||||
returnError('id_not_found', 'json');
|
||||
}
|
||||
|
||||
returnData('json', ['type' => 'string', 'data' => $module->custom_id()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get modules for an agent, and print all the result like a csv.
|
||||
*
|
||||
|
|
|
@ -331,6 +331,10 @@ function config_update_config()
|
|||
$error_update[] = __('Audit log enabled');
|
||||
}
|
||||
|
||||
if (!config_update_value('module_custom_id_ro', get_parameter('module_custom_id_ro'))) {
|
||||
$error_update[] = __('Module Custom ID read only');
|
||||
}
|
||||
|
||||
if (!config_update_value('unique_ip', get_parameter('unique_ip'))) {
|
||||
$error_update[] = __('unique_ip');
|
||||
}
|
||||
|
@ -1946,6 +1950,10 @@ function config_process_config()
|
|||
config_update_value('audit_log_enabled', 0);
|
||||
}
|
||||
|
||||
if (!isset($config['module_custom_id_ro'])) {
|
||||
config_update_value('module_custom_id_ro', 0);
|
||||
}
|
||||
|
||||
if (!isset($config['elasticsearch_ip'])) {
|
||||
config_update_value('elasticsearch_ip', '');
|
||||
}
|
||||
|
|
|
@ -99,6 +99,8 @@ our @EXPORT = qw(
|
|||
get_user_exists
|
||||
get_user_profile_id
|
||||
get_group_children
|
||||
get_agentmodule_custom_id
|
||||
set_agentmodule_custom_id
|
||||
is_agent_address
|
||||
is_group_disabled
|
||||
get_agent_status
|
||||
|
@ -446,6 +448,35 @@ sub get_agentmodule_data ($$$$$) {
|
|||
return @rows;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
## Return module custom ID given the module id.
|
||||
##########################################################################
|
||||
sub get_agentmodule_custom_id ($$) {
|
||||
my ($dbh, $id_agent_module) = @_;
|
||||
|
||||
my $rc = get_db_value(
|
||||
$dbh,
|
||||
"SELECT custom_id FROM tagente_modulo WHERE id_agente_modulo = ?",
|
||||
safe_input($id_agent_module)
|
||||
);
|
||||
return defined($rc) ? $rc : undef;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
## Updates module custom ID given the module id and custom Id.
|
||||
##########################################################################
|
||||
sub set_agentmodule_custom_id ($$$) {
|
||||
my ($dbh, $id_agent_module, $custom_id) = @_;
|
||||
|
||||
my $rc = db_update(
|
||||
$dbh,
|
||||
"UPDATE tagente_modulo SET custom_id = ? WHERE id_agente_modulo = ?",
|
||||
safe_input($custom_id),
|
||||
safe_input($id_agent_module)
|
||||
);
|
||||
return defined($rc) ? ($rc eq '0E0' ? 0 : $rc) : -1;
|
||||
}
|
||||
|
||||
########################################################################
|
||||
## SUB get_agentmodule_status (agent_module_id)
|
||||
## Return agent module status. given "agent_module_id"
|
||||
|
|
|
@ -118,6 +118,8 @@ sub help_screen{
|
|||
help_screen_line('--get_planned_downtimes_items', '<name> [<id_group> <type_downtime> <type_execution> <type_periodicity>]', 'Get all items of planned downtimes');
|
||||
help_screen_line('--set_planned_downtimes_deleted', '<name> ', 'Deleted a planned downtime');
|
||||
help_screen_line('--get_module_id', '<agent_id> <module_name>', 'Get the id of an module');
|
||||
help_screen_line('--get_module_custom_id', '<agentmodule_id>', 'Get the custom_id of given module');
|
||||
help_screen_line('--set_module_custom_id', '<agentmodule_id> [<custom_id>]', 'Set (or erase if empty) the custom_id of given module');
|
||||
help_screen_line('--get_agent_group', '<agent_name> [<use_alias>]', 'Get the group name of an agent');
|
||||
help_screen_line('--get_agent_group_id', '<agent_name> [<use_alias>]', 'Get the group ID of an agent');
|
||||
help_screen_line('--get_agent_modules', '<agent_name> [<use_alias>]', 'Get the modules of an agent');
|
||||
|
@ -4616,6 +4618,39 @@ sub cli_get_module_id() {
|
|||
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Retrieves the module custom_id given id_agente_modulo.
|
||||
# Related option: --get_module_custom_id
|
||||
# perl pandora_manage.pl /etc/pandora/pandora_server.conf --get_module_custom_id 4
|
||||
##############################################################################
|
||||
|
||||
sub cli_get_module_custom_id {
|
||||
my $module_id = $ARGV[2];
|
||||
|
||||
my $custom_id = get_agentmodule_custom_id($dbh, $module_id);
|
||||
|
||||
if (defined($custom_id)) {
|
||||
print $custom_id;
|
||||
}
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Update sor erases the module custom_id given id_agente_modulo.
|
||||
# Related option: --get_module_custom_id
|
||||
# perl pandora_manage.pl /etc/pandora/pandora_server.conf --get_module_custom_id 4 test
|
||||
##############################################################################
|
||||
|
||||
sub cli_set_module_custom_id {
|
||||
my ($module_id, $custom_id) = @ARGV[2..3];
|
||||
|
||||
my $rs = set_agentmodule_custom_id($dbh, $module_id, $custom_id);
|
||||
|
||||
if ($rs > 0) {
|
||||
print $custom_id;
|
||||
} else {
|
||||
print "[ERROR] No changes.";
|
||||
}
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Show the group name where a given agent is
|
||||
|
@ -7491,6 +7526,14 @@ sub pandora_manage_main ($$$) {
|
|||
param_check($ltotal, 2);
|
||||
cli_get_module_id();
|
||||
}
|
||||
elsif ($param eq '--get_module_custom_id') {
|
||||
param_check($ltotal, 1);
|
||||
cli_get_module_custom_id();
|
||||
}
|
||||
elsif ($param eq '--set_module_custom_id') {
|
||||
param_check($ltotal, 2);
|
||||
cli_set_module_custom_id();
|
||||
}
|
||||
elsif ($param eq '--get_agent_group') {
|
||||
param_check($ltotal, 2, 1);
|
||||
cli_get_agent_group();
|
||||
|
|
Loading…
Reference in New Issue