diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index d393a2a1b3..3e52f3b701 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14609,3 +14609,58 @@ function api_get_users($thrash1, $thrash2, $other, $returnType) } } + +/** + * Resets module counts and alert counts in the agents + * @param $id id of the agent you want to synchronize. Add "All" to synchronize all agents + * @param $trash1 + * @param $trash2 + * @param $trash3 + * + * Example: + * api.php?op=set&op2=reset_agent_counts&apipass=1234&user=admin&pass=pandora&id=All + */ +function api_set_reset_agent_counts ($id, $thrash1, $thrash2, $thrash3) +{ + global $config; + + if (!check_acl($config['id_user'], 0, "AW")) { + returnError('forbidden', 'string'); + return; + } + + if ($id == '' || !$id) { + returnError('error_parameter', __('Error. Agent cannot be left blank.')); + return; + } + + if ($id != "All"){ + $agent = db_get_row_filter('tagente', array('id_agente' => $id)); + if (empty ($agent)){ + returnError('error_agent', __('This agent does not exist.')); + return; + }else { + $return = db_process_sql_update ('tagente', + array ('update_module_count' => 1, 'update_alert_count' => 1), + array('id_agente' => $id) + ); + } + } + else { + $return = db_process_sql_update ('tagente', + array ('update_module_count' => 1, 'update_alert_count' => 1) + ); + } + + + $data = __('Successfully updated module/alert count in id agent %d.', $id); + if ($id == "All") + $data = __('Successfully updated module/alert count in all agents'); + + if ($return === false) + returnError('error_reset_agent_counts', 'Could not be updated module/alert counts in id agent %d.', $id); + else + returnData('string', array('type' => 'string', 'data' => $data)); + + +} diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index d8566f1fdb..13823fe4e6 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -137,6 +137,7 @@ sub help_screen{ help_screen_line('--delete_cluster_item', '', 'Deleting cluster item'); help_screen_line('--get_cluster_status', '', 'Getting cluster status'); help_screen_line('--set_disabled_and_standby', ' ', 'Overwrite and disable and standby status'); + help_screen_line('--reset_agent_counts', '', 'Resets module counts and alert counts in the agents'); print "\nMODULES:\n\n" unless $param ne ''; help_screen_line('--create_data_module', " [ \n\t \n\t \n\t \n\t \n\t ]", 'Add data server module to agent'); help_screen_line('--create_web_module', " [ \n\t \n\t \n\t \n\t \n\t \n\t ].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent'); @@ -6375,6 +6376,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 3, 1); cli_set_disabled_and_standby(); } + elsif ($param eq '--reset_agent_counts') { + param_check($ltotal, 1, 0); + cli_reset_agent_counts(); + } else { print_log "[ERROR] Invalid option '$param'.\n\n"; $param = ''; @@ -6978,4 +6983,17 @@ sub cli_set_disabled_and_standby() { my $exit_code = (defined($result) && "$result" eq "1") ? "1" : "0"; print "\n$exit_code\n"; -} \ No newline at end of file +} + +############################################################################## +# Resets module counts and alert counts in the agents. +# Related option: --reset_agent_counts +############################################################################## + +sub cli_reset_agent_counts() { + my $agent_id = @ARGV[2]; + + my $result = api_call(\%conf,'set', 'reset_agent_counts', $agent_id); + print "$result \n\n "; + +}