Merge branch 'ent-5693-9848-actualizar-campos-personalizados-agente-mediante-cli' into 'develop'
add agent_update_custom_fields on cli See merge request artica/pandorafms!4281
This commit is contained in:
commit
1cdef62ceb
|
@ -241,6 +241,9 @@ our @EXPORT = qw(
|
||||||
pandora_update_agent_alert_count
|
pandora_update_agent_alert_count
|
||||||
pandora_update_agent_module_count
|
pandora_update_agent_module_count
|
||||||
pandora_update_config_token
|
pandora_update_config_token
|
||||||
|
pandora_update_agent_custom_field
|
||||||
|
pandora_select_id_custom_field
|
||||||
|
pandora_select_combo_custom_field
|
||||||
pandora_update_gis_data
|
pandora_update_gis_data
|
||||||
pandora_update_module_on_error
|
pandora_update_module_on_error
|
||||||
pandora_update_module_from_hash
|
pandora_update_module_from_hash
|
||||||
|
@ -3413,6 +3416,41 @@ sub pandora_update_config_token ($$$) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
## Select custom field id by name tagent_custom_field
|
||||||
|
##########################################################################
|
||||||
|
sub pandora_select_id_custom_field ($$) {
|
||||||
|
my ($dbh, $field) = @_;
|
||||||
|
my $result = undef;
|
||||||
|
|
||||||
|
$result = get_db_single_row ($dbh, 'SELECT id_field FROM tagent_custom_fields WHERE name = ? ', safe_input($field));
|
||||||
|
|
||||||
|
return $result->{'id_field'};
|
||||||
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
## Select custom field id by name tagent_custom_field
|
||||||
|
##########################################################################
|
||||||
|
sub pandora_select_combo_custom_field ($$) {
|
||||||
|
my ($dbh, $field) = @_;
|
||||||
|
my $result = undef;
|
||||||
|
|
||||||
|
$result = get_db_single_row ($dbh, 'SELECT combo_values FROM tagent_custom_fields WHERE id_field = ? ', $field);
|
||||||
|
|
||||||
|
return $result->{'combo_values'};
|
||||||
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
## Update a custom field from agent of tagent_custom_data
|
||||||
|
##########################################################################
|
||||||
|
sub pandora_update_agent_custom_field ($$$$) {
|
||||||
|
my ($dbh, $token, $field, $id_agent) = @_;
|
||||||
|
my $result = undef;
|
||||||
|
$result = db_update ($dbh, 'UPDATE tagent_custom_data SET description = ? WHERE id_field = ? AND id_agent = ?', safe_input($token), $field, $id_agent);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
## Get value of a token of tconfig table
|
## Get value of a token of tconfig table
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -142,6 +142,8 @@ sub help_screen{
|
||||||
help_screen_line('--get_cluster_status', '<id_cluster>', 'Getting cluster status');
|
help_screen_line('--get_cluster_status', '<id_cluster>', 'Getting cluster status');
|
||||||
help_screen_line('--set_disabled_and_standby', '<id_agent> <id_node> <value>', 'Overwrite and disable and standby status');
|
help_screen_line('--set_disabled_and_standby', '<id_agent> <id_node> <value>', 'Overwrite and disable and standby status');
|
||||||
help_screen_line('--reset_agent_counts', '<id_agent>', 'Resets module counts and alert counts in the agents');
|
help_screen_line('--reset_agent_counts', '<id_agent>', 'Resets module counts and alert counts in the agents');
|
||||||
|
help_screen_line('--update_agent_custom_fields', '<id_agent> <type_field> <field_to_change> <new_value>', "Update an agent custom field. The fields can be \n\t the following: Serial number, Department ... and types can be 0 text and 1 combo ");
|
||||||
|
|
||||||
print "\nMODULES:\n\n" unless $param ne '';
|
print "\nMODULES:\n\n" unless $param ne '';
|
||||||
help_screen_line('--create_data_module', "<module_name> <module_type> <agent_name> [<description> <module_group> \n\t <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> \n\t <history_data> <definition_file> <warning_str> <critical_str>\n\t <unknown_events> <ff_threshold> <each_ff> <ff_threshold_normal>\n\t <ff_threshold_warning> <ff_threshold_critical> <ff_timeout> <warning_inverse> <critical_inverse>\n\t <critical_instructions> <warning_instructions> <unknown_instructions> <use_alias>]", 'Add data server module to agent');
|
help_screen_line('--create_data_module', "<module_name> <module_type> <agent_name> [<description> <module_group> \n\t <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> \n\t <history_data> <definition_file> <warning_str> <critical_str>\n\t <unknown_events> <ff_threshold> <each_ff> <ff_threshold_normal>\n\t <ff_threshold_warning> <ff_threshold_critical> <ff_timeout> <warning_inverse> <critical_inverse>\n\t <critical_instructions> <warning_instructions> <unknown_instructions> <use_alias>]", 'Add data server module to agent');
|
||||||
help_screen_line('--create_web_module', "<module_name> <module_type> <agent_name> [<description> <module_group> \n\t <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> \n\t <history_data> <retries> <requests> <agent_browser_id> <auth_server> <auth_realm> <definition_file>\n\t <proxy_url> <proxy_auth_login> <proxy_auth_password> <warning_str> <critical_str>\n\t <unknown_events> <ff_threshold> <each_ff> <ff_threshold_normal>\n\t <ff_threshold_warning> <ff_threshold_critical> <ff_timeout> <warning_inverse> <critical_inverse>\n\t <critical_instructions> <warning_instructions> <unknown_instructions> <use_alias>].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent');
|
help_screen_line('--create_web_module', "<module_name> <module_type> <agent_name> [<description> <module_group> \n\t <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> \n\t <history_data> <retries> <requests> <agent_browser_id> <auth_server> <auth_realm> <definition_file>\n\t <proxy_url> <proxy_auth_login> <proxy_auth_password> <warning_str> <critical_str>\n\t <unknown_events> <ff_threshold> <each_ff> <ff_threshold_normal>\n\t <ff_threshold_warning> <ff_threshold_critical> <ff_timeout> <warning_inverse> <critical_inverse>\n\t <critical_instructions> <warning_instructions> <unknown_instructions> <use_alias>].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent');
|
||||||
|
@ -3042,6 +3044,64 @@ sub cli_user_update() {
|
||||||
pandora_update_user_from_hash ($update, 'id_user', safe_input($user_id), $dbh);
|
pandora_update_user_from_hash ($update, 'id_user', safe_input($user_id), $dbh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Update an agent customs field.
|
||||||
|
# Related option: --update_agent_custom_fields
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
sub cli_agent_update_custom_fields() {
|
||||||
|
my ($id_agent,$type,$field,$new_value) = @ARGV[2..5];
|
||||||
|
|
||||||
|
my $agent_name = get_agent_name($dbh, $id_agent);
|
||||||
|
|
||||||
|
my $id_field;
|
||||||
|
|
||||||
|
my $found = 0;
|
||||||
|
|
||||||
|
if($agent_name eq '') {
|
||||||
|
print_log "[ERROR] Agent '$id_agent' doesnt exist\n\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Department, Serial number ...
|
||||||
|
my $custom_field = pandora_select_id_custom_field ($dbh, $field);
|
||||||
|
|
||||||
|
|
||||||
|
if($custom_field eq '') {
|
||||||
|
print_log "[ERROR] Field '$field' doesnt exist\n\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($type == 1) {
|
||||||
|
my $exist_option = pandora_select_combo_custom_field ($dbh, $custom_field);
|
||||||
|
|
||||||
|
my @fields = split(',',$exist_option);
|
||||||
|
foreach my $combo (@fields) {
|
||||||
|
if($combo eq safe_input($new_value)) {
|
||||||
|
$found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($found == 0) {
|
||||||
|
print_log "\n[ERROR] Field '$new_value' doesn't match with combo option values\n\n";
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print_log "\n[INFO] Updating field '$field' in agent with ID '$id_agent'\n\n";
|
||||||
|
|
||||||
|
my $result = pandora_update_agent_custom_field ($dbh, $new_value, $custom_field, $id_agent);
|
||||||
|
|
||||||
|
if($result == "0E0"){
|
||||||
|
print_log "[ERROR] Error updating field '$field'\n\n";
|
||||||
|
} else {
|
||||||
|
print_log "[INFO] Field '$field' updated succesfully!\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
exit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Update an agent field.
|
# Update an agent field.
|
||||||
# Related option: --update_agent
|
# Related option: --update_agent
|
||||||
|
@ -7866,6 +7926,9 @@ sub pandora_manage_main ($$$) {
|
||||||
}elsif ($param eq '--event_in_progress') {
|
}elsif ($param eq '--event_in_progress') {
|
||||||
param_check($ltotal, 1, 0);
|
param_check($ltotal, 1, 0);
|
||||||
cli_event_in_progress();
|
cli_event_in_progress();
|
||||||
|
} elsif ($param eq '--agent_update_custom_fields') {
|
||||||
|
param_check($ltotal, 4, 5);
|
||||||
|
cli_agent_update_custom_fields();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print_log "[ERROR] Invalid option '$param'.\n\n";
|
print_log "[ERROR] Invalid option '$param'.\n\n";
|
||||||
|
|
Loading…
Reference in New Issue