Merge branch 'ent-6302-proyectos-anadir-un-campo-de-numero-de-ticket-para-modulos' into 'develop'
Custom id improvements See merge request artica/pandorafms!3464
This commit is contained in:
commit
1cdb91a02d
|
@ -528,10 +528,10 @@ $table_advanced->data[0][1] = html_print_input_text(
|
|||
20,
|
||||
65,
|
||||
true,
|
||||
$disabledBecauseInPolicy,
|
||||
(($config['module_custom_id_ro'] && $__code_from != 'policies') ? true : $disabledBecauseInPolicy),
|
||||
false,
|
||||
'',
|
||||
$classdisabledBecauseInPolicy
|
||||
(($config['module_custom_id_ro'] && $__code_from != 'policies') ? 'readonly' : $classdisabledBecauseInPolicy)
|
||||
);
|
||||
|
||||
$table_advanced->data[0][3] = __('Unit');
|
||||
|
|
|
@ -114,6 +114,7 @@ $fields_available['server_name'] = __('Server Name');
|
|||
$fields_available['data'] = __('Data');
|
||||
$fields_available['module_status'] = __('Module Status');
|
||||
$fields_available['mini_severity'] = __('Severity mini');
|
||||
$fields_available['module_custom_id'] = __('Module custom ID');
|
||||
|
||||
|
||||
// Remove fields already selected.
|
||||
|
|
|
@ -1125,11 +1125,11 @@ $class = 'databox filters';
|
|||
</td>
|
||||
|
||||
<td style="font-weight:bold;">
|
||||
<?php
|
||||
<?php
|
||||
html_print_checkbox_switch(
|
||||
'current_month',
|
||||
1,
|
||||
$current_month
|
||||
'current_month',
|
||||
1,
|
||||
$current_month
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
|
@ -1145,16 +1145,16 @@ $class = 'databox filters';
|
|||
<tr>
|
||||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Monday')."<br>";
|
||||
<?php
|
||||
echo __('Monday').'<br>';
|
||||
html_print_checkbox_switch('monday', 1, $monday);
|
||||
?>
|
||||
?>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Tuesday')."<br>";
|
||||
echo __('Tuesday').'<br>';
|
||||
html_print_checkbox_switch('tuesday', 1, $tuesday);
|
||||
?>
|
||||
</p>
|
||||
|
@ -1162,7 +1162,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Wednesday')."<br>";
|
||||
echo __('Wednesday').'<br>';
|
||||
html_print_checkbox_switch('wednesday', 1, $wednesday);
|
||||
?>
|
||||
</p>
|
||||
|
@ -1170,7 +1170,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Thursday')."<br>";
|
||||
echo __('Thursday').'<br>';
|
||||
html_print_checkbox_switch('thursday', 1, $thursday);
|
||||
?>
|
||||
</p>
|
||||
|
@ -1178,7 +1178,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Friday')."<br>";
|
||||
echo __('Friday').'<br>';
|
||||
html_print_checkbox_switch('friday', 1, $friday);
|
||||
?>
|
||||
</p>
|
||||
|
@ -1186,7 +1186,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Saturday')."<br>";
|
||||
echo __('Saturday').'<br>';
|
||||
html_print_checkbox_switch('saturday', 1, $saturday);
|
||||
?>
|
||||
</p>
|
||||
|
@ -1194,7 +1194,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Sunday')."<br>";
|
||||
echo __('Sunday').'<br>';
|
||||
html_print_checkbox_switch('sunday', 1, $sunday);
|
||||
?>
|
||||
</p>
|
||||
|
@ -2117,13 +2117,14 @@ $class = 'databox filters';
|
|||
);
|
||||
?>
|
||||
</td>
|
||||
<td><?php
|
||||
html_print_checkbox_switch(
|
||||
'fullscale',
|
||||
1,
|
||||
$fullscale
|
||||
);
|
||||
?>
|
||||
<td>
|
||||
<?php
|
||||
html_print_checkbox_switch(
|
||||
'fullscale',
|
||||
1,
|
||||
$fullscale
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
@ -2194,7 +2195,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Total time')."<br>";
|
||||
echo __('Total time').'<br>';
|
||||
html_print_checkbox_switch('total_time', 1, $total_time);
|
||||
?>
|
||||
</p>
|
||||
|
@ -2202,7 +2203,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Time failed')."<br>";
|
||||
echo __('Time failed').'<br>';
|
||||
html_print_checkbox_switch('time_failed', 1, $time_failed);
|
||||
?>
|
||||
</p>
|
||||
|
@ -2210,7 +2211,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Time in OK status')."<br>";
|
||||
echo __('Time in OK status').'<br>';
|
||||
html_print_checkbox_switch('time_in_ok_status', 1, $time_in_ok_status);
|
||||
?>
|
||||
</p>
|
||||
|
@ -2218,7 +2219,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Time in unknown status')."<br>";
|
||||
echo __('Time in unknown status').'<br>';
|
||||
html_print_checkbox_switch(
|
||||
'time_in_unknown_status',
|
||||
1,
|
||||
|
@ -2230,7 +2231,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Time of not initialized module')."<br>";
|
||||
echo __('Time of not initialized module').'<br>';
|
||||
html_print_checkbox_switch(
|
||||
'time_of_not_initialized_module',
|
||||
1,
|
||||
|
@ -2242,7 +2243,7 @@ $class = 'databox filters';
|
|||
<td>
|
||||
<p style="margin-right:30px;">
|
||||
<?php
|
||||
echo __('Time of downtime')."<br>";
|
||||
echo __('Time of downtime').'<br>';
|
||||
html_print_checkbox_switch('time_of_downtime', 1, $time_of_downtime);
|
||||
?>
|
||||
</p>
|
||||
|
|
|
@ -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,8 @@ 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;
|
||||
use PandoraFMS\Enterprise\Cluster;
|
||||
|
||||
|
||||
|
@ -2517,6 +2519,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');
|
||||
}
|
||||
|
@ -1954,6 +1958,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', '');
|
||||
}
|
||||
|
|
|
@ -207,6 +207,7 @@ function events_get_all_fields()
|
|||
$columns['server_name'] = __('Server name');
|
||||
$columns['data'] = __('Data');
|
||||
$columns['module_status'] = __('Module status');
|
||||
$columns['module_custom_id'] = __('Module custom id');
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
@ -291,6 +292,9 @@ function events_get_column_name($field, $table_alias=false)
|
|||
case 'module_status':
|
||||
return __('Module Status');
|
||||
|
||||
case 'module_custom_id':
|
||||
return __('Module custom ID');
|
||||
|
||||
case 'options':
|
||||
return __('Options');
|
||||
|
||||
|
@ -4678,6 +4682,16 @@ function events_page_general($event)
|
|||
|
||||
$table_general->data[] = $data;
|
||||
|
||||
$data = [];
|
||||
$data[0] = __('Module custom ID');
|
||||
if ($event['module_custom_id'] != '') {
|
||||
$data[1] = $event['module_custom_id'];
|
||||
} else {
|
||||
$data[1] = '<i>'.__('N/A').'</i>';
|
||||
}
|
||||
|
||||
$table_general->data[] = $data;
|
||||
|
||||
$table_data = $table_general->data;
|
||||
if (is_array($table_data)) {
|
||||
$table_data_total = count($table_data);
|
||||
|
|
|
@ -292,6 +292,7 @@ if (is_ajax()) {
|
|||
if (!is_metaconsole()) {
|
||||
$fields[] = 'am.nombre as module_name';
|
||||
$fields[] = 'am.id_agente_modulo as id_agentmodule';
|
||||
$fields[] = 'am.custom_id as module_custom_id';
|
||||
$fields[] = 'ta.server_name as server_name';
|
||||
} else {
|
||||
$fields[] = 'ts.server_name as server_name';
|
||||
|
|
|
@ -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,41 @@ 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;
|
||||
} else {
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# 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 +7528,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