Merge remote-tracking branch 'origin/develop' into ent-2441-despliegue-de-agentes-desde-pandora

This commit is contained in:
fbsanchez 2019-07-23 15:28:04 +02:00
commit 6c79bfb135
34 changed files with 248 additions and 98 deletions

View File

@ -1,5 +1,5 @@
package: pandorafms-agent-unix
Version: 7.0NG.736-190717
Version: 7.0NG.736-190723
Architecture: all
Priority: optional
Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="7.0NG.736-190717"
pandora_version="7.0NG.736-190723"
echo "Test if you has the tools for to make the packages."
whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null

View File

@ -42,7 +42,7 @@ my $Sem = undef;
my $ThreadSem = undef;
use constant AGENT_VERSION => '7.0NG.736';
use constant AGENT_BUILD => '190717';
use constant AGENT_BUILD => '190723';
# Agent log default file size maximum and instances
use constant DEFAULT_MAX_LOG_SIZE => 600000;

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_agent_unix
%define version 7.0NG.736
%define release 190717
%define release 190723
Summary: Pandora FMS Linux agent, PERL version
Name: %{name}

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_agent_unix
%define version 7.0NG.736
%define release 190717
%define release 190723
Summary: Pandora FMS Linux agent, PERL version
Name: %{name}

View File

@ -10,7 +10,7 @@
# **********************************************************************
PI_VERSION="7.0NG.736"
PI_BUILD="190717"
PI_BUILD="190723"
OS_NAME=`uname -s`
FORCE=0

View File

@ -186,7 +186,7 @@ UpgradeApplicationID
{}
Version
{190717}
{190723}
ViewReadme
{Yes}

View File

@ -30,7 +30,7 @@ using namespace Pandora;
using namespace Pandora_Strutils;
#define PATH_SIZE _MAX_PATH+1
#define PANDORA_VERSION ("7.0NG.736(Build 190717)")
#define PANDORA_VERSION ("7.0NG.736(Build 190723)")
string pandora_path;
string pandora_dir;

View File

@ -11,7 +11,7 @@ BEGIN
VALUE "LegalCopyright", "Artica ST"
VALUE "OriginalFilename", "PandoraAgent.exe"
VALUE "ProductName", "Pandora FMS Windows Agent"
VALUE "ProductVersion", "(7.0NG.736(Build 190717))"
VALUE "ProductVersion", "(7.0NG.736(Build 190723))"
VALUE "FileVersion", "1.0.0.0"
END
END

View File

@ -1,5 +1,5 @@
package: pandorafms-console
Version: 7.0NG.736-190717
Version: 7.0NG.736-190723
Architecture: all
Priority: optional
Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="7.0NG.736-190717"
pandora_version="7.0NG.736-190723"
package_pear=0
package_pandora=1

View File

@ -670,21 +670,49 @@ if ($config['menu_type'] == 'classic') {
<?php
if ($_GET['refr'] || $do_refresh === true) {
if ($_GET['sec2'] == 'operation/events/events') {
$autorefresh_draw = true;
}
?>
var autorefresh_draw = '<?php echo $autorefresh_draw; ?>';
$("#header_autorefresh").css('padding-right', '5px');
var refr_time = <?php echo (int) get_parameter('refr', $config['refr']); ?>;
var t = new Date();
t.setTime (t.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
$("#refrcounter").countdown ({
until: t,
layout: '%M%nn%M:%S%nn%S',
labels: ['', '', '', '', '', '', ''],
onExpiry: function () {
if(autorefresh_draw == true) {
var refresh_interval = parseInt('<?php echo ($config['refr'] * 1000); ?>');
var until_time='';
function events_refresh() {
until_time = new Date();
until_time.setTime (until_time.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
$("#refrcounter").countdown ({
until: until_time,
layout: '%M%nn%M:%S%nn%S',
labels: ['', '', '', '', '', '', ''],
onExpiry: function () {
dt_events.draw(false);
}
});
}
// Start the countdown when page is loaded (first time).
events_refresh();
// Repeat countdown according to refresh_interval.
setInterval(events_refresh, refresh_interval);
} else {
var refr_time = <?php echo (int) get_parameter('refr', $config['refr']); ?>;
var t = new Date();
t.setTime (t.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
$("#refrcounter").countdown ({
until: t,
layout: '%M%nn%M:%S%nn%S',
labels: ['', '', '', '', '', '', ''],
onExpiry: function () {
href = $("a.autorefresh").attr ("href");
href = href + refr_time;
$(document).attr ("location", href);
}
});
}
<?php
}
?>
@ -694,8 +722,38 @@ if ($config['menu_type'] == 'classic') {
$("#combo_refr").toggle ();
$("select#ref").change (function () {
href = $("a.autorefresh").attr ("href");
$(document).attr ("location", href + this.value);
});
if(autorefresh_draw == true){
inputs = $("#events_form :input");
values = {};
inputs.each(function() {
values[this.name] = $(this).val();
})
var newValue = btoa(JSON.stringify(values));
<?php
// Check if the url has the parameter fb64.
if ($_GET['fb64']) {
$fb64 = $_GET['fb64'];
?>
var fb64 = '<?php echo $fb64; ?>';
// Check if the filters have changed.
if(fb64 !== newValue){
href = href.replace(fb64, newValue);
}
$(document).attr("location", href+ '&refr=' + this.value);
<?php
} else {
?>
$(document).attr("location", href+'&fb64=' + newValue + '&refr=' + this.value);
<?php
}
?>
} else {
$(document).attr ("location", href + this.value);
}
});
return false;
});

View File

@ -20,7 +20,7 @@
/**
* Pandora build version and version
*/
$build_version = 'PC190717';
$build_version = 'PC190723';
$pandora_version = 'v7.0NG.736';
// Do not overwrite default timezone set if defined.

View File

@ -5413,3 +5413,27 @@ function get_help_info($section_name)
// hd($result);
return $result;
}
if (!function_exists('getallheaders')) {
/**
* Fix for php-fpm
*
* @return array
*/
function getallheaders()
{
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}

View File

@ -737,7 +737,7 @@ function servers_get_info($id_server=-1)
$server['img'] = html_print_image(
'images/syslog.png',
true,
['title' => __('Syslog server')]
['title' => __('Log server')]
);
$server['type'] = 'syslog';
$id_modulo = 0;
@ -1221,7 +1221,7 @@ function servers_get_server_string_name(int $server)
return __('Discovery server');
case SERVER_TYPE_SYSLOG:
return __('Syslog server');
return __('Log server');
case SERVER_TYPE_WUX:
return __('WUX server');

View File

@ -617,16 +617,21 @@ function users_save_login()
$user_list = json_decode($user_list_json, true);
if (empty($user_list)) {
$user_list = [];
}
if (isset($user_list[$config['id_user']])) {
$user_list[$config['id_user']]['count']++;
} else {
$user_list[$config['id_user']] = [
'name' => $user['fullname'],
'count' => 1,
];
} else if (isset($user_list[$config['id_user']])) {
$user_list[$config['id_user']] = [
'name' => $user['fullname'],
'count' => $user_list[$config['id_user']]['count'],
];
} else {
$users_count = count($user_list);
$user_list[$config['id_user']] = [
'name' => $user['fullname'],
'count' => ++$users_count,
];
}
// Clean the file
@ -704,17 +709,7 @@ function users_save_logout($user=false, $delete=false)
$user_list = [];
}
if ($delete) {
unset($user_list[$user['id_user']]);
} else {
if (isset($user_list[$config['id_user']])) {
$user_list[$config['id_user']]['count']--;
}
if ($user_list[$config['id_user']]['count'] <= 0) {
unset($user_list[$user['id_user']]);
}
}
unset($user_list[$user['id_user']]);
// Clean the file
ftruncate($fp_user_list, 0);
@ -1052,6 +1047,13 @@ function users_check_users()
'users' => '',
];
$users_with_session = db_get_all_rows_sql('SELECT tsessions_php.data FROM pandora.tsessions_php;');
$users_logged_now = [];
foreach ($users_with_session as $user_with_session) {
$tmp_id_user = explode('"', $user_with_session['data']);
array_push($users_logged_now, $tmp_id_user[1]);
}
$file_global_user_list = $config['attachment_store'].'/pandora_chat.user_list.json.txt';
// First lock the file
@ -1082,13 +1084,32 @@ function users_check_users()
$user_list = [];
}
fclose($fp_user_list);
// Compare both user list. Meanwhile the user from chat file have an active
// session, his continue in the list of active chat users
$user_name_list = [];
foreach ($user_list as $user) {
$user_name_list[] = $user['name'];
foreach ($user_list as $key => $user) {
if (in_array($key, $users_logged_now)) {
array_push($user_name_list, $user['name']);
} else {
unset($user_list[$key]);
}
}
// Clean the file
ftruncate($fp_user_list, 0);
// Update the file with the correct list of users
$status = fwrite($fp_user_list, json_encode($user_list));
/*
if ($status === false) {
fclose($fp_user_list);
return;
} */
// Closing the resource
fclose($fp_user_list);
$return['correct'] = true;
$return['users'] = implode('<br />', $user_name_list);
echo json_encode($return);

View File

@ -21,6 +21,7 @@ if (empty($config['homedir'])) {
}
require_once $config['homedir'].'/include/functions.php';
require_once $config['homedir'].'/include/graphs/functions_flot.php';
$ttl = get_parameter('ttl', 1);
$graph_type = get_parameter('graph_type', '');

View File

@ -129,7 +129,7 @@
<div style='height: 10px'>
<?php
$version = '7.0NG.736';
$build = '190717';
$build = '190723';
$banner = "v$version Build $build";
error_reporting(0);

View File

@ -1469,6 +1469,11 @@ echo "<div id='event_response_command_window' title='".__('Parameters')."'></div
// Load filter div for dialog.
echo '<div id="load-modal-filter" style="display: none"></div>';
echo '<div id="save-modal-filter" style="display: none"></div>';
if ($_GET['refr'] || $do_refresh === true) {
$autorefresh_draw = true;
}
?>
<script type="text/javascript">
var loading = 0;
@ -1548,6 +1553,21 @@ function process_datatables_callback(table, settings) {
})
}
var autorefresh_draw = '<?php echo $autorefresh_draw; ?>';
if (autorefresh_draw == true){
$("#refrcounter").countdown('change', {
until: countdown_repeat()
});
function countdown_repeat() {
var until_time = new Date();
until_time.setTime (until_time.getTime () + parseInt(<?php echo ($config['refr'] * 1000); ?>));
return until_time;
}
}
}
function process_datatables_item(item) {

View File

@ -115,16 +115,16 @@ echo "<div style='width:100%'>".html_print_button(
//Enter key.
if (e.keyCode == 13) {
send_message();
check_users();
}
});
init_webchat();
});
$(window).unload(function () {
$(window).on("beforeunload",function () {
exit_webchat();
});
function init_webchat() {
send_login_message();
long_polling_check_messages();

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_console
%define version 7.0NG.736
%define release 190717
%define release 190723
# User and Group under which Apache is running
%define httpd_name httpd

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_console
%define version 7.0NG.736
%define release 190717
%define release 190723
# User and Group under which Apache is running
%define httpd_name httpd

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_console
%define version 7.0NG.736
%define release 190717
%define release 190723
%define httpd_name httpd
# User and Group under which Apache is running
%define httpd_name apache2

View File

@ -1,5 +1,5 @@
package: pandorafms-server
Version: 7.0NG.736-190717
Version: 7.0NG.736-190723
Architecture: all
Priority: optional
Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="7.0NG.736-190717"
pandora_version="7.0NG.736-190723"
package_cpan=0
package_pandora=1

View File

@ -45,7 +45,7 @@ our @EXPORT = qw(
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "7.0NG.736";
my $pandora_build = "190717";
my $pandora_build = "190723";
our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash

View File

@ -1596,6 +1596,31 @@ sub pandora_process_module ($$$$$$$$$;$) {
my $ff_start_utimestamp = $agent_status->{'ff_start_utimestamp'};
my $mark_for_update = 0;
# tagente_estado.last_try defaults to NULL, should default to '1970-01-01 00:00:00'
$agent_status->{'last_try'} = '1970-01-01 00:00:00' unless defined ($agent_status->{'last_try'});
$agent_status->{'datos'} = "" unless defined($agent_status->{'datos'});
# Do we have to save module data?
if ($agent_status->{'last_try'} !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
logger($pa_config, "Invalid last try timestamp '" . $agent_status->{'last_try'} . "' for agent '" . $agent->{'nombre'} . "' not found while processing module '" . $module->{'nombre'} . "'.", 3);
pandora_update_module_on_error ($pa_config, $module, $dbh);
return;
}
my $last_try = ($1 == 0) ? 0 : timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
my $save = ($module->{'history_data'} == 1 && ($agent_status->{'datos'} ne $processed_data || $last_try < ($utimestamp - 86400))) ? 1 : 0;
# Received stale data. Save module data if needed and return.
if ($pa_config->{'dataserver_lifo'} == 1 && $utimestamp <= $agent_status->{'utimestamp'}) {
logger($pa_config, "Received stale data from agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 10);
# Save module data. Async and log4x modules are not compressed.
if ($module_type =~ m/(async)|(log4x)/ || $save == 1) {
save_module_data ($data_object, $module, $module_type, $utimestamp, $dbh);
}
return;
}
# Get new status
my $new_status = get_module_status ($processed_data, $module, $module_type);
@ -1744,23 +1769,6 @@ sub pandora_process_module ($$$$$$$$$;$) {
$mark_for_update = 1;
}
# tagente_estado.last_try defaults to NULL, should default to '1970-01-01 00:00:00'
$agent_status->{'last_try'} = '1970-01-01 00:00:00' unless defined ($agent_status->{'last_try'});
# Do we have to save module data?
if ($agent_status->{'last_try'} !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
logger($pa_config, "Invalid last try timestamp '" . $agent_status->{'last_try'} . "' for agent '" . $agent->{'nombre'} . "' not found while processing module '" . $module->{'nombre'} . "'.", 3);
pandora_update_module_on_error ($pa_config, $module, $dbh);
return;
}
my $last_try = ($1 == 0) ? 0 : timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
if (!defined($agent_status->{'datos'})){
$agent_status->{'datos'} = "";
}
my $save = ($module->{'history_data'} == 1 && ($agent_status->{'datos'} ne $processed_data || $last_try < ($utimestamp - 86400))) ? 1 : 0;
# Never update tagente_estado when processing out-of-order data.
if ($utimestamp >= $last_try) {

View File

@ -149,14 +149,8 @@ sub data_producer ($) {
next if ($file !~ /^(.*)[\._]\d+\.data$/);
my $agent_name = $1;
$AgentSem->down ();
if (defined ($Agents{$agent_name})) {
$AgentSem->up ();
next;
}
$Agents{$agent_name} = 1;
$AgentSem->up ();
next if (agent_lock($pa_config, $agent_name) == 0);
push (@tasks, $file);
}
@ -181,9 +175,7 @@ sub data_consumer ($$) {
# Double check that the file exists
if (! -f $file_name) {
$AgentSem->down ();
delete ($Agents{$agent_name});
$AgentSem->up ();
agent_unlock($pa_config, $agent_name);
return;
}
@ -213,9 +205,7 @@ sub data_consumer ($$) {
# Double check that the file exists
if (! -f $file_name) {
$AgentSem->down ();
delete ($Agents{$agent_name});
$AgentSem->up ();
agent_unlock($pa_config, $agent_name);
return;
}
@ -231,17 +221,13 @@ sub data_consumer ($$) {
} else {
process_xml_data ($self->getConfig (), $file_name, $xml_data, $self->getServerID (), $self->getDBH ());
}
$AgentSem->down ();
delete ($Agents{$agent_name});
$AgentSem->up ();
agent_unlock($pa_config, $agent_name);
return;
}
rename($file_name, $file_name . '_BADXML');
pandora_event ($pa_config, "Unable to process XML data file '$file_name': $xml_err", 0, 0, 0, 0, 0, 'error', 0, $dbh);
$AgentSem->down ();
delete ($Agents{$agent_name});
$AgentSem->up ();
agent_unlock($pa_config, $agent_name);
}
###############################################################################
@ -1059,5 +1045,37 @@ sub process_xml_matrix_network {
return;
}
##########################################################################
# Get a lock on the given agent. Return 1 on success, 0 otherwise.
##########################################################################
sub agent_lock {
my ($pa_config, $agent_name) = @_;
return 1 if ($pa_config->{'dataserver_lifo'} == 1);
$AgentSem->down ();
if (defined ($Agents{$agent_name})) {
$AgentSem->up ();
return 0;
}
$Agents{$agent_name} = 1;
$AgentSem->up ();
return 1;
}
##########################################################################
# Remove the lock on the given agent.
##########################################################################
sub agent_unlock {
my ($pa_config, $agent_name) = @_;
return if ($pa_config->{'dataserver_lifo'} == 1);
$AgentSem->down ();
delete ($Agents{$agent_name});
$AgentSem->up ();
}
1;
__END__

View File

@ -32,7 +32,7 @@ our @ISA = qw(Exporter);
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "7.0NG.736";
my $pandora_build = "190717";
my $pandora_build = "190723";
our $VERSION = $pandora_version." ".$pandora_build;
our %EXPORT_TAGS = ( 'all' => [ qw() ] );

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_server
%define version 7.0NG.736
%define release 190717
%define release 190723
Summary: Pandora FMS Server
Name: %{name}

View File

@ -3,7 +3,7 @@
#
%define name pandorafms_server
%define version 7.0NG.736
%define release 190717
%define release 190723
Summary: Pandora FMS Server
Name: %{name}

View File

@ -9,7 +9,7 @@
# **********************************************************************
PI_VERSION="7.0NG.736"
PI_BUILD="190717"
PI_BUILD="190723"
MODE=$1
if [ $# -gt 1 ]; then

View File

@ -34,7 +34,7 @@ use PandoraFMS::Config;
use PandoraFMS::DB;
# version: define current version
my $version = "7.0NG.736 PS190717";
my $version = "7.0NG.736 PS190723";
# Pandora server configuration
my %conf;

View File

@ -36,7 +36,7 @@ use Encode::Locale;
Encode::Locale::decode_argv;
# version: define current version
my $version = "7.0NG.736 PS190717";
my $version = "7.0NG.736 PS190723";
# save program name for logging
my $progname = basename($0);