Merge branch 'ent-2782-ue-agente-software-en-modo-standby' into 'develop'

Ent 2782 ue agente software en modo standby

See merge request artica/pandorafms!1800
This commit is contained in:
vgilc 2018-09-28 10:04:12 +02:00
commit 6a6bae10b1
17 changed files with 153 additions and 47 deletions

View File

@ -87,6 +87,9 @@ transfer_mode tentacle
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
# remote_config 1
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# If set to 1 start Drone Agent's Proxy Mode
# proxy_mode 1

View File

@ -117,6 +117,9 @@ transfer_mode tentacle
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
#remote_config 1
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# If set to 1 start Drone Agent's Proxy Mode
# proxy_mode 1

View File

@ -130,6 +130,9 @@ transfer_mode tentacle
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
remote_config 0
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# If set to 1 start Drone Agent's Proxy Mode
#proxy_mode 1

View File

@ -89,6 +89,9 @@ transfer_mode tentacle
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
# remote_config 1
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# If set to 1 start Drone Agent's Proxy Mode
# proxy_mode 1

View File

@ -136,6 +136,9 @@ transfer_mode tentacle
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
remote_config 0
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# If set to 1 start Drone Agent's Proxy Mode
# proxy_mode 1

View File

@ -41,9 +41,9 @@ udp_server_auth_address 0.0.0.0
# Group assigned for this agent (descriptive, p.e: Servers)
#group Servers
# Group password (if defined).
#group_password
# Group password (if defined).
#group_password
# Autotime: Enforce to server to ignore timestamp coming from this
# agent, used when agents has no timer or it's inestable. 1 to enable
@ -102,6 +102,9 @@ transfer_mode tentacle
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
remote_config 0
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# Number of threads to execute modules in parallel
#agent_threads 1

View File

@ -98,6 +98,9 @@ transfer_mode tentacle
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
#remote_config 1
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# If set to 1 start Drone Agent's Proxy Mode
#proxy_mode 1

View File

@ -92,6 +92,9 @@ transfer_mode tentacle
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
#remote_config 1
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# If set to 1 start Drone Agent's Proxy Mode
#proxy_mode 1

View File

@ -186,6 +186,7 @@ my %DefaultConf = (
'xml_buffer' => 0,
'custom_id' => '',
'url_address' => '',
'standby' => 0,
);
my %Conf = %DefaultConf;
@ -1333,6 +1334,41 @@ sub check_collections () {
}
}
################################################################################
# Sleep function
################################################################################
sub sleep_agent {
my ($main_agent, $iter_base_time) = @_;
# Sleep if main agent
if ($main_agent != 0) {
foreach my $broker_pid (@BrokerPid) {
waitpid ($broker_pid, 0);
}
# Cron mode
exit (0) if ($Conf{'cron_mode'} == 1);
$iter_base_time += $Conf{'intensive_interval'};
my $now = time();
my $interval_remain = $iter_base_time - $now;
if ($interval_remain >= 0) {
sleep ($interval_remain);
} else {
# don't sleep if iteraion took more than "intensive_interval" seconds
$iter_base_time = $now; # use current time as base time
}
}
# Finish if broker agent
else {
exit (0);
}
return $iter_base_time;
}
###############################################################################
# Return the MD5 checksum of the given string as a hex string.
# Pseudocode from: http://en.wikipedia.org/wiki/MD5#Pseudocode
@ -2959,6 +2995,12 @@ while (1) {
}
}
# Do not report to server if standby mode is enabled
if ($Conf{'standby'} eq '1' && $Conf{'debug'} ne '1') {
$iter_base_time = sleep_agent($main_agent, $iter_base_time);
next;
}
my $address;
if(defined($Conf{'address'})) {
@ -3161,31 +3203,8 @@ while (1) {
$SIG{'INT'} = \&udp_server_signal;
}
# Sleep if main agent
if ($main_agent != 0) {
foreach my $broker_pid (@BrokerPid) {
waitpid ($broker_pid, 0);
}
# Cron mode
last if ($Conf{'cron_mode'} == 1);
$iter_base_time += $Conf{'intensive_interval'};
my $now = time();
my $interval_remain = $iter_base_time - $now;
if ($interval_remain >= 0) {
sleep ($interval_remain);
} else {
# don't sleep if iteraion took more than "intensive_interval" seconds
$iter_base_time = $now; # use current time as base time
}
}
# Finish if broker agent
else {
exit (0);
}
# Sleep agent function
$iter_base_time = sleep_agent($main_agent, $iter_base_time);
}
__END__

View File

@ -1,6 +1,6 @@
# Base config file for Pandora FMS Windows Agent
# (c) 2006-2017 Artica Soluciones Tecnologicas
# Version 7.0NG.727
# Version 7.0NG.727
# This program is Free Software, you can redistribute it and/or modify it
# under the terms of the GNU General Public Licence as published by the Free Software
@ -82,6 +82,9 @@ server_port 41121
# Debug mode renames XML in the temp folder and continues running
# debug 1
# Default 0, set to 1 to avoid module executions and report to server
# standby 1
# XML encoding (ISO-8859-1 by default). Most windows servers experience problems when you set to UTF-8. Other special codepages may be specified here.
#encoding ISO-8859-1

View File

@ -1869,7 +1869,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
server_addr = conf->getValue ("server_ip");
if (this->broker_modules != NULL) {
if (this->broker_modules != NULL && !(conf->getValue ("standby") == "1" && !getPandoraDebug())) {
this->broker_modules->goFirst ();
while (! this->broker_modules->isLast ()) {
@ -1937,7 +1937,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
}
}
if (data_flag == 1 || this->timestamp + this->interval_sec <= this->run_time) {
if ((data_flag == 1 || this->timestamp + this->interval_sec <= this->run_time) && !(conf->getValue ("standby") == "1" && !getPandoraDebug())) {
// Send the XML
if (!server_addr.empty ()) {
@ -1997,7 +1997,7 @@ Pandora_Windows_Service::pandora_run (int forced_run) {
execution_number++;
if (this->modules != NULL) {
if (this->modules != NULL && !(conf->getValue ("standby") == "1" && !getPandoraDebug())) {
this->modules->goFirst ();
while (! this->modules->isLast ()) {
@ -2057,7 +2057,7 @@ Pandora_Windows_Service::pandora_run (int forced_run) {
}
}
if (forced_run == 1 || data_flag == 1 || this->timestamp + this->interval_sec <= this->run_time) {
if ((forced_run == 1 || data_flag == 1 || this->timestamp + this->interval_sec <= this->run_time) && !(conf->getValue ("standby") == "1" && !getPandoraDebug())) {
// Send the XML
if (!server_addr.empty ()) {

View File

@ -479,6 +479,7 @@ $table->data[3][1] .= __('Autodisable mode') . ' ' .
// Status (Disabled / Enabled)
$table->data[4][0] = __('Status');
$table->data[4][1] = __('Disabled') . ' ' .
ui_print_help_tip(__('If the remote configuration is enabled, it will also go into standby mode when disabling it.'), true) . ' ' .
html_print_radio_button_extended ("disabled", 1, '', $disabled, false, '', 'style="margin-right: 40px;"', true);
$table->data[4][1] .= __('Enabled') . ' ' .
html_print_radio_button_extended ("disabled", 0, '', $disabled, false, '', 'style="margin-right: 40px;"', true);

View File

@ -760,7 +760,7 @@ if ($update_agent) { // if modified some agent paramenter
$quiet = (int) get_parameter("quiet", 0);
$cps = (int) get_parameter("cps", 0);
$old_interval = db_get_value('intervalo', 'tagente', 'id_agente', $id_agente);
$old_values = db_get_row('tagente', 'id_agente', $id_agente);
$fields = db_get_all_fields_in_table('tagent_custom_fields');
if ($fields === false) $fields = array();
@ -860,11 +860,21 @@ if ($update_agent) { // if modified some agent paramenter
// Update the agent from the metaconsole cache
enterprise_include_once('include/functions_agents.php');
enterprise_hook ('agent_update_from_cache', array($id_agente, $values,$server_name));
if ($old_interval != $intervalo) {
enterprise_hook('config_agents_update_config_interval', array($id_agente, $intervalo));
# Update the configuration files
if ($old_values['intervalo'] != $intervalo) {
enterprise_hook(
'config_agents_update_config_token',
array($id_agente, 'interval', $intervalo)
);
}
if ($old_values['disabled'] != $disabled) {
enterprise_hook(
'config_agents_update_config_token',
array($id_agente, 'standby', $disabled ? "1" : "0")
);
}
if($tpolicy_group_old){
foreach ($tpolicy_group_old as $key => $value) {
$tpolicy_agents_old= db_get_sql("SELECT * FROM tpolicy_agents

View File

@ -30,6 +30,7 @@ require_once ('include/functions_modules.php');
require_once ('include/functions_servers.php');
require_once ('include/functions_gis.php');
require_once ('include/functions_users.php');
enterprise_include_once('include/functions_config_agents.php');
if (is_ajax ()) {
$get_n_conf_files = (bool) get_parameter ('get_n_conf_files');
@ -136,8 +137,11 @@ if ($update_agents) {
foreach ($id_agents as $id_agent) {
if (!empty($values)) {
$group_old = false;
if($values['id_grupo']){
$group_old = db_get_sql("SELECT id_grupo FROM tagente WHERE id_agente =" .$id_agent);
$disabled_old = false;
if($values['id_grupo'] || isset($values['disabled'])){
$values_old = db_get_row_filter('tagente', array('id_agente' => $id_agent), array('id_grupo', 'disabled'));
if ($values_old['id_grupo']) $group_old = $values_old['id_grupo'];
if (isset($values['disabled'])) $disabled_old = $values_old['disabled'];
}
$result = db_process_sql_update ('tagente',
@ -149,7 +153,14 @@ if ($update_agents) {
// Force an update of the agent cache.
$result_metaconsole = agent_update_from_cache($id_agent,$values,$server_name);
}
if ($disabled_old !== false && $disabled_old != $values['disabled']) {
enterprise_hook(
'config_agents_update_config_token',
array($id_agent, 'standby', $values['disabled'])
);
}
if($group_old || $result){
if ($group_old && $group_old != null) {
$tpolicy_group_old = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups
@ -421,7 +432,9 @@ $table->data[1][1] .= __('Autodisable mode').' '.html_print_radio_button_extende
// Status (Disabled / Enabled)
$table->data[2][0] = __('Status');
$table->data[2][1] = __('No change').' '.html_print_radio_button_extended ("disabled", -1, '', $disabled, false, '', 'style="margin-right: 40px;"', true);
$table->data[2][1] .= __('Disabled').' '.html_print_radio_button_extended ("disabled", 1, '', $disabled, false, '', 'style="margin-right: 40px;"', true);
$table->data[2][1] .= __('Disabled') . ' ' .
ui_print_help_tip(__('If the remote configuration is enabled, it will also go into standby mode when disabling it.'), true) . ' ' .
html_print_radio_button_extended ("disabled", 1, '', $disabled, false, '', 'style="margin-right: 40px;"', true);
$table->data[2][1] .= __('Active').' '.html_print_radio_button_extended ("disabled", 0, '', $disabled, false, '', 'style="margin-right: 40px;"', true);
// Remote configuration

View File

@ -1175,11 +1175,14 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) {
return;
}
}
$values_old = db_get_row_filter('tagente',
array('id_agente' => $id_agent),
array('id_grupo', 'disabled')
);
$tpolicy_group_old = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups
WHERE id_group = ".$values_old['id_grupo']);
$group_old = db_get_sql("SELECT id_grupo FROM tagente WHERE id_agente =" .$id_agent);
$tpolicy_group_old = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups
WHERE id_group = ".$group_old);
$return = db_process_sql_update('tagente',
array('alias' => $alias,
'direccion' => $ip,
@ -1200,8 +1203,16 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) {
// register ip for this agent in 'taddress'
agents_add_address ($id_agent, $ip);
}
if($return){
// Update config file
if (isset($disabled) && $values_old['disabled'] != $disabled) {
enterprise_hook(
'config_agents_update_config_token',
array($id_agent, 'standby', $disabled)
);
}
if($tpolicy_group_old){
foreach ($tpolicy_group_old as $key => $value) {
$tpolicy_agents_old= db_get_sql("SELECT * FROM tpolicy_agents

View File

@ -28,6 +28,7 @@ use Socket qw(inet_ntoa inet_aton);
use Sys::Syslog;
use Scalar::Util qw(looks_like_number);
use LWP::UserAgent;
use threads;
# New in 3.2. Used to sendmail internally, without external scripts
# use Module::Loaded;

View File

@ -136,6 +136,7 @@ sub help_screen{
help_screen_line('--delete_cluster_agent', '<id_agent> <id_cluster>', 'Deleting cluster agent');
help_screen_line('--delete_cluster_item', '<id_item>', 'Deleting cluster item');
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');
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>]", '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>].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent');
@ -6125,6 +6126,10 @@ sub pandora_manage_main ($$$) {
param_check($ltotal, 1, 0);
cli_migration_agent();
}
elsif ($param eq '--set_disabled_and_standby') {
param_check($ltotal, 3, 1);
cli_set_disabled_and_standby();
}
else {
print_log "[ERROR] Invalid option '$param'.\n\n";
$param = '';
@ -6709,4 +6714,23 @@ sub cli_get_cluster_status() {
else{
print "\n0\n";
}
}
##############################################################################
# Set an agent disabled and with standby.
# Related option: --set_disabled_and_standby
##############################################################################
sub cli_set_disabled_and_standby() {
my ($id, $id_node, $value) = @ARGV[2..4];
$id_node = 0 unless defined($id_node);
$value = 1 unless defined($value); #Set to disabled by default
# Call the API.
my $result = api_call(
$conf, 'set', 'disabled_and_standby', $id, $id_node, $value
);
my $exit_code = (defined($result) && "$result" eq "1") ? "1" : "0";
print "\n$exit_code\n";
}