update agent custom fields
This commit is contained in:
parent
4e25442813
commit
d54af52baf
|
@ -243,6 +243,7 @@ our @EXPORT = qw(
|
|||
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_module_on_error
|
||||
pandora_update_module_from_hash
|
||||
|
@ -3420,6 +3421,18 @@ sub pandora_select_id_custom_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
|
||||
##########################################################################
|
||||
|
|
|
@ -142,7 +142,7 @@ sub help_screen{
|
|||
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('--reset_agent_counts', '<id_agent>', 'Resets module counts and alert counts in the agents');
|
||||
help_screen_line('--update_agent_custom_fields', '<id_agent> <field_to_change> <new_value>', "Update an agent custom field. The fields can be \n\t the following: Serial number, Department ...");
|
||||
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 '';
|
||||
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');
|
||||
|
@ -3051,12 +3051,14 @@ sub cli_user_update() {
|
|||
##############################################################################
|
||||
|
||||
sub cli_agent_update_custom_fields() {
|
||||
my ($id_agent,$field,$new_value) = @ARGV[2..4];
|
||||
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;
|
||||
|
@ -3065,17 +3067,33 @@ sub cli_agent_update_custom_fields() {
|
|||
# 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;
|
||||
}
|
||||
|
||||
print_log "[INFO] Updating field '$field' in agent with ID '$id_agent'\n\n";
|
||||
if($type == 1) {
|
||||
my $exist_option = pandora_select_combo_custom_field ($dbh, $custom_field);
|
||||
|
||||
my $result = pandora_update_agent_custom_field ($dbh, $new_value, $custom_field, $id_agent);
|
||||
my @fields = split(',',$exist_option);
|
||||
foreach my $combo (@fields) {
|
||||
if($combo eq $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";
|
||||
print_log "[ERROR] Error updating field '$field'\n\n";
|
||||
} else {
|
||||
print_log "[INFO] Field '$field' updated succesfully!\n\n";
|
||||
}
|
||||
|
@ -7909,7 +7927,7 @@ sub pandora_manage_main ($$$) {
|
|||
param_check($ltotal, 1, 0);
|
||||
cli_event_in_progress();
|
||||
} elsif ($param eq '--agent_update_custom_fields') {
|
||||
param_check($ltotal, 3, 4);
|
||||
param_check($ltotal, 4, 5);
|
||||
cli_agent_update_custom_fields();
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue