Merge branch 'develop' into ent-12288-varios-bugs-en-netflow
This commit is contained in:
commit
0baeee66e0
|
@ -1,5 +1,5 @@
|
|||
package: pandorafms-agent-unix
|
||||
Version: 7.0NG.773.3-231023
|
||||
Version: 7.0NG.773.3-231024
|
||||
Architecture: all
|
||||
Priority: optional
|
||||
Section: admin
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
pandora_version="7.0NG.773.3-231023"
|
||||
pandora_version="7.0NG.773.3-231024"
|
||||
|
||||
echo "Test if you has the tools for to make the packages."
|
||||
whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null
|
||||
|
|
|
@ -313,6 +313,6 @@ module_plugin autodiscover --default
|
|||
|
||||
#Hardening plugin for security compliance analysis. Enable to use it.
|
||||
#module_begin
|
||||
#module_plugin /usr/share/pandora_agent/plugins/pandora_sca
|
||||
#module_plugin /usr/share/pandora_agent/plugins/pandora_sca -t 150
|
||||
#module_absoluteinterval 7d
|
||||
#module_end
|
||||
#module_end
|
||||
|
|
|
@ -1031,7 +1031,7 @@ my $Sem = undef;
|
|||
my $ThreadSem = undef;
|
||||
|
||||
use constant AGENT_VERSION => '7.0NG.773.3';
|
||||
use constant AGENT_BUILD => '231023';
|
||||
use constant AGENT_BUILD => '231024';
|
||||
|
||||
# Agent log default file size maximum and instances
|
||||
use constant DEFAULT_MAX_LOG_SIZE => 600000;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
%global __os_install_post %{nil}
|
||||
%define name pandorafms_agent_linux
|
||||
%define version 7.0NG.773.3
|
||||
%define release 231023
|
||||
%define release 231024
|
||||
|
||||
Summary: Pandora FMS Linux agent, PERL version
|
||||
Name: %{name}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
%define name pandorafms_agent_linux_bin
|
||||
%define source_name pandorafms_agent_linux
|
||||
%define version 7.0NG.773.3
|
||||
%define release 231023
|
||||
%define release 231024
|
||||
|
||||
Summary: Pandora FMS Linux agent, binary version
|
||||
Name: %{name}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
%global __os_install_post %{nil}
|
||||
%define name pandorafms_agent_linux
|
||||
%define version 7.0NG.773.3
|
||||
%define release 231023
|
||||
%define release 231024
|
||||
|
||||
Summary: Pandora FMS Linux agent, PERL version
|
||||
Name: %{name}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
# **********************************************************************
|
||||
|
||||
PI_VERSION="7.0NG.773.3"
|
||||
PI_BUILD="231023"
|
||||
PI_BUILD="231024"
|
||||
OS_NAME=`uname -s`
|
||||
|
||||
FORCE=0
|
||||
|
|
|
@ -526,7 +526,7 @@ module_plugin "%PROGRAMFILES%\Pandora_Agent\util\autodiscover.exe" --default
|
|||
|
||||
# Hardening plugin for security compliance analysis.
|
||||
#module_begin
|
||||
#module_plugin "%PROGRAMFILES%\Pandora_Agent\util\pandora_sca.exe"
|
||||
#module_plugin "%PROGRAMFILES%\Pandora_Agent\util\pandora_sca.exe -t 150"
|
||||
#module_absoluteinterval 7d
|
||||
#module_end
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6d93bd9d56c938063045fa2093198d324746f84df2b74567648f3baebd635657
|
||||
size 5248006
|
||||
oid sha256:db207ef67053764be7e9b42cd04ea5509cc2a023548aab1c037745ca277b68a3
|
||||
size 4858753
|
||||
|
|
|
@ -186,7 +186,7 @@ UpgradeApplicationID
|
|||
{}
|
||||
|
||||
Version
|
||||
{231023}
|
||||
{231024}
|
||||
|
||||
ViewReadme
|
||||
{Yes}
|
||||
|
|
|
@ -30,7 +30,7 @@ using namespace Pandora;
|
|||
using namespace Pandora_Strutils;
|
||||
|
||||
#define PATH_SIZE _MAX_PATH+1
|
||||
#define PANDORA_VERSION ("7.0NG.773.3 Build 231023")
|
||||
#define PANDORA_VERSION ("7.0NG.773.3 Build 231024")
|
||||
|
||||
string pandora_path;
|
||||
string pandora_dir;
|
||||
|
|
|
@ -11,7 +11,7 @@ BEGIN
|
|||
VALUE "LegalCopyright", "Pandora FMS"
|
||||
VALUE "OriginalFilename", "PandoraAgent.exe"
|
||||
VALUE "ProductName", "Pandora FMS Windows Agent"
|
||||
VALUE "ProductVersion", "(7.0NG.773.3(Build 231023))"
|
||||
VALUE "ProductVersion", "(7.0NG.773.3(Build 231024))"
|
||||
VALUE "FileVersion", "1.0.0.0"
|
||||
END
|
||||
END
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package: pandorafms-console
|
||||
Version: 7.0NG.773.3-231023
|
||||
Version: 7.0NG.773.3-231024
|
||||
Architecture: all
|
||||
Priority: optional
|
||||
Section: admin
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
pandora_version="7.0NG.773.3-231023"
|
||||
pandora_version="7.0NG.773.3-231024"
|
||||
|
||||
package_pear=0
|
||||
package_pandora=1
|
||||
|
|
|
@ -359,6 +359,9 @@ SET @id_os = 9;
|
|||
INSERT INTO tmodule_inventory (`id_os`, `name`, `description`, `interpreter`, `data_format`, `code`, `block_mode`,`script_mode`)
|
||||
SELECT * FROM (SELECT @id_os id_os, @tmodule_name name, @tmodule_description description, '' interpreter, 'ID:STATUS' data_format, '' code, '0' block_mode, 2 script_mode) AS tmp
|
||||
WHERE NOT EXISTS (SELECT name, description FROM tmodule_inventory WHERE name = @tmodule_name and description = @tmodule_description and id_os = @id_os);
|
||||
INSERT INTO tmodule_group (name) SELECT ('Security') WHERE NOT EXISTS (SELECT name FROM tmodule_group WHERE LOWER(name) = 'security');
|
||||
|
||||
ALTER TABLE tagente_modulo ADD COLUMN `last_compact` TIMESTAMP NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE `tevent_alert` ea INNER JOIN `tevent_rule` er ON ea.id = er.id_event_alert SET disabled=1 WHERE er.log_agent IS NOT NULL OR er.log_content IS NOT NULL OR er.log_source IS NOT NULL;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
/**
|
||||
* Pandora build version and version
|
||||
*/
|
||||
$build_version = 'PC231023';
|
||||
$build_version = 'PC231024';
|
||||
$pandora_version = 'v7.0NG.773.3';
|
||||
|
||||
// Do not overwrite default timezone set if defined.
|
||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -131,7 +131,7 @@
|
|||
<div style='padding-bottom: 50px'>
|
||||
<?php
|
||||
$version = '7.0NG.773.3';
|
||||
$build = '231023';
|
||||
$build = '231024';
|
||||
$banner = "v$version Build $build";
|
||||
error_reporting(0);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
%define debug_package %{nil}
|
||||
%define name pandorafms_console
|
||||
%define version 7.0NG.773.3
|
||||
%define release 231023
|
||||
%define release 231024
|
||||
|
||||
# User and Group under which Apache is running
|
||||
%define httpd_name httpd
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
%define debug_package %{nil}
|
||||
%define name pandorafms_console
|
||||
%define version 7.0NG.773.3
|
||||
%define release 231023
|
||||
%define release 231024
|
||||
|
||||
# User and Group under which Apache is running
|
||||
%define httpd_name httpd
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#
|
||||
%define name pandorafms_console
|
||||
%define version 7.0NG.773.3
|
||||
%define release 231023
|
||||
%define release 231024
|
||||
%define httpd_name httpd
|
||||
# User and Group under which Apache is running
|
||||
%define httpd_name apache2
|
||||
|
|
|
@ -276,6 +276,7 @@ CREATE TABLE IF NOT EXISTS `tagente_modulo` (
|
|||
`warning_time` INT UNSIGNED DEFAULT 0,
|
||||
`quiet_by_downtime` TINYINT NOT NULL DEFAULT 0,
|
||||
`disabled_by_downtime` TINYINT NOT NULL DEFAULT 0,
|
||||
`last_compact` TIMESTAMP NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id_agente_modulo`),
|
||||
KEY `main_idx` (`id_agente_modulo`,`id_agente`),
|
||||
KEY `tam_agente` (`id_agente`),
|
||||
|
|
|
@ -120,10 +120,10 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
|
|||
('custom_report_front_logo', 'images/pandora_logo_white.jpg'),
|
||||
('custom_report_front_header', ''),
|
||||
('custom_report_front_footer', ''),
|
||||
('MR', 65),
|
||||
('MR', 66),
|
||||
('identification_reminder', 1),
|
||||
('identification_reminder_timestamp', 0),
|
||||
('current_package', 773),
|
||||
('current_package', 774),
|
||||
('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.00097656250000":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'),
|
||||
('custom_docs_logo', 'default_docs.png'),
|
||||
('custom_support_logo', 'default_support.png'),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package: pandorafms-server
|
||||
Version: 7.0NG.773.3-231023
|
||||
Version: 7.0NG.773.3-231024
|
||||
Architecture: all
|
||||
Priority: optional
|
||||
Section: admin
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
pandora_version="7.0NG.773.3-231023"
|
||||
pandora_version="7.0NG.773.3-231024"
|
||||
|
||||
package_cpan=0
|
||||
package_pandora=1
|
||||
|
|
|
@ -46,7 +46,7 @@ our @EXPORT = qw(
|
|||
|
||||
# version: Defines actual version of Pandora Server for this module only
|
||||
my $pandora_version = "7.0NG.773.3";
|
||||
my $pandora_build = "231023";
|
||||
my $pandora_build = "231024";
|
||||
our $VERSION = $pandora_version." ".$pandora_build;
|
||||
|
||||
# Setup hash
|
||||
|
|
|
@ -34,7 +34,7 @@ our @ISA = qw(Exporter);
|
|||
|
||||
# version: Defines actual version of Pandora Server for this module only
|
||||
my $pandora_version = "7.0NG.773.3";
|
||||
my $pandora_build = "231023";
|
||||
my $pandora_build = "231024";
|
||||
our $VERSION = $pandora_version." ".$pandora_build;
|
||||
|
||||
our %EXPORT_TAGS = ( 'all' => [ qw() ] );
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
%define debug_package %{nil}
|
||||
%define name pandorafms_server
|
||||
%define version 7.0NG.773.3
|
||||
%define release 231023
|
||||
%define release 231024
|
||||
|
||||
Summary: Pandora FMS Server
|
||||
Name: %{name}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
%global __os_install_post %{nil}
|
||||
%define name pandorafms_server
|
||||
%define version 7.0NG.773.3
|
||||
%define release 231023
|
||||
%define release 231024
|
||||
|
||||
Summary: Pandora FMS Server
|
||||
Name: %{name}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
# **********************************************************************
|
||||
|
||||
PI_VERSION="7.0NG.773.3"
|
||||
PI_BUILD="231023"
|
||||
PI_BUILD="231024"
|
||||
|
||||
MODE=$1
|
||||
if [ $# -gt 1 ]; then
|
||||
|
|
|
@ -26,6 +26,9 @@ use POSIX qw(strftime);
|
|||
use File::Path qw(rmtree);
|
||||
use Time::HiRes qw(usleep);
|
||||
|
||||
use List::Util qw(min);
|
||||
use List::Util qw(sum);
|
||||
|
||||
# Default lib dir for RPM and DEB packages
|
||||
BEGIN { push @INC, '/usr/lib/perl5'; }
|
||||
|
||||
|
@ -35,7 +38,7 @@ use PandoraFMS::Config;
|
|||
use PandoraFMS::DB;
|
||||
|
||||
# version: define current version
|
||||
my $version = "7.0NG.773.3 Build 231023";
|
||||
my $version = "7.0NG.773.3 Build 231024";
|
||||
|
||||
# Pandora server configuration
|
||||
my %conf;
|
||||
|
@ -443,116 +446,187 @@ sub pandora_purgedb ($$$) {
|
|||
###############################################################################
|
||||
# Compact agent data.
|
||||
###############################################################################
|
||||
sub pandora_compactdb ($$$) {
|
||||
my ($conf, $dbh, $dbh_conf) = @_;
|
||||
sub pandora_compactdb {
|
||||
my ($conf, $dbh, $dbh_conf) = @_;
|
||||
|
||||
my $total_modules = get_db_value($dbh, "SELECT COUNT(id_agente_modulo) FROM tagente_modulo");
|
||||
|
||||
# Interval in hours to compact.
|
||||
my $compaction_interval = 24;
|
||||
my $compaction_factor = (3600 * $compaction_interval) / 300;
|
||||
|
||||
# Number of agents to be proceced on this execution
|
||||
my $agents_limit = int($total_modules / $compaction_factor);
|
||||
|
||||
my $last_compact_offset = pandora_get_config_value($dbh, "last_compact_offset");
|
||||
|
||||
unless ($last_compact_offset) {
|
||||
db_do($dbh, "INSERT INTO tconfig (token, value) VALUES ('last_compact_offset', '0')");
|
||||
$last_compact_offset = 0;
|
||||
}
|
||||
|
||||
# Obtain a group of modules to compact.
|
||||
my @module_groups = get_db_rows(
|
||||
$dbh,
|
||||
'SELECT id_agente_modulo, id_tipo_modulo, UNIX_TIMESTAMP(last_compact) as last_compact FROM tagente_modulo WHERE id_agente_modulo > ? LIMIT ?',
|
||||
$last_compact_offset,
|
||||
$agents_limit
|
||||
);
|
||||
|
||||
# Compact the group of modules.
|
||||
my $starting_time = time();
|
||||
pandora_compact_modules($dbh, $conf, @module_groups);
|
||||
my $ending_time = time();
|
||||
log_message('COMPACT', "Time taken: " . ($ending_time - $starting_time) . " seconds.");
|
||||
|
||||
# Add the offset.
|
||||
$last_compact_offset += $agents_limit;
|
||||
|
||||
# If the offset is higher than the max module start again
|
||||
$last_compact_offset = 0 if ($last_compact_offset >= $total_modules);
|
||||
|
||||
# Save the new offset
|
||||
db_do($dbh, "UPDATE tconfig SET value = ? WHERE token = 'last_compact_offset'", $last_compact_offset);
|
||||
}
|
||||
|
||||
sub pandora_compact_modules {
|
||||
my ($dbh, $conf, @module_groups) = @_;
|
||||
|
||||
# Obtain the minimun last compact from the block
|
||||
my $min_compact = min(map { $_->{"last_compact"} } @module_groups);
|
||||
|
||||
# if the min has not been setted
|
||||
if($min_compact == 0){
|
||||
$min_compact = get_db_value(
|
||||
$dbh,
|
||||
'SELECT MIN(td.utimestamp)
|
||||
FROM tagente_datos td, tagente_modulo tm
|
||||
WHERE td.id_agente_modulo = tm.id_agente_modulo
|
||||
AND tm.id_tipo_modulo not in (2, 6, 9, 18, 21, 31, 35, 100)
|
||||
AND td.id_agente_modulo BETWEEN ? AND ?',
|
||||
$module_groups[0]->{"id_agente_modulo"}, $module_groups[-1]->{"id_agente_modulo"}
|
||||
);
|
||||
}
|
||||
|
||||
# One week of data of data as max from the last min compact.
|
||||
my $max_compact = $min_compact + (60 * 60 * 24 * 7);
|
||||
|
||||
# If the last compact is on the future set the current time as max.
|
||||
$max_compact = time() if($max_compact > time());
|
||||
|
||||
log_message('COMPACT', "Compacting data of agents agents $module_groups[0]->{'id_agente_modulo'} to $module_groups[-1]->{'id_agente_modulo'}, data between " . strftime('%Y-%m-%d %H:%M:%S', localtime($min_compact)) . " and " . strftime('%Y-%m-%d %H:%M:%S', localtime($max_compact)));
|
||||
|
||||
# Obtain all the data from the interval to avoid multiple requests
|
||||
# Avoid pull data from modules that should be skipped.
|
||||
my @data = get_db_rows (
|
||||
$dbh,
|
||||
'SELECT td.id_agente_modulo, td.datos, td.utimestamp
|
||||
FROM tagente_datos td, tagente_modulo tm
|
||||
WHERE td.id_agente_modulo = tm.id_agente_modulo
|
||||
AND tm.id_tipo_modulo not in (2, 6, 9, 18, 21, 31, 35, 100)
|
||||
AND td.utimestamp < ? AND td.utimestamp >= ?
|
||||
AND td.id_agente_modulo BETWEEN ? AND ?
|
||||
',
|
||||
$max_compact, $min_compact, $module_groups[0]->{"id_agente_modulo"}, $module_groups[-1]->{"id_agente_modulo"}
|
||||
);
|
||||
|
||||
my $total_data = scalar(@data);
|
||||
my $proceced_total_data = 0;
|
||||
my $progress = 0;
|
||||
my $compactations = 0;
|
||||
|
||||
my %count_hash;
|
||||
my %id_agent_hash;
|
||||
my %value_hash;
|
||||
my %module_proc_hash;
|
||||
|
||||
return if ($conf->{'_days_compact'} == 0 || $conf->{'_step_compact'} < 1);
|
||||
|
||||
# Convert compact interval length from hours to seconds
|
||||
my $step = $conf->{'_step_compact'} * 3600;
|
||||
|
||||
# The oldest timestamp will be the lower limit
|
||||
my $limit_utime = get_db_value ($dbh, 'SELECT min(utimestamp) as min FROM tagente_datos');
|
||||
return unless (defined ($limit_utime) && $limit_utime > 0);
|
||||
# Max. 168 steps or 7 days in one hour steps.
|
||||
# This avoids blocking of old modules without last compact
|
||||
my $step_limit = 24 * 7;
|
||||
|
||||
# Calculate the start date
|
||||
my $start_utime = time() - $conf->{'_days_compact'} * 24 * 60 * 60;
|
||||
my $last_compact = $start_utime;
|
||||
my $stop_utime;
|
||||
# Compact the modules in this block
|
||||
foreach my $module (@module_groups) {
|
||||
$progress = $total_data == 0 ? 0 : ($proceced_total_data / $total_data) * 100;
|
||||
printf(strftime("\r" . "%H:%M:%S", localtime()) . ' [COMPACT] ' . "Progress: %.2f%%", $progress);
|
||||
|
||||
my $id = $module->{"id_agente_modulo"};
|
||||
my $module_type = $module->{"id_tipo_modulo"};
|
||||
|
||||
# Do not compact the same data twice!
|
||||
if (defined ($conf->{'_last_compact'}) && $conf->{'_last_compact'} > $limit_utime) {
|
||||
$limit_utime = $conf->{'_last_compact'};
|
||||
}
|
||||
|
||||
if ($start_utime <= $limit_utime || ( defined ($conf->{'_last_compact'}) && (($conf->{'_last_compact'} + 24 * 60 * 60) > $start_utime))) {
|
||||
log_message ('COMPACT', "Data already compacted.");
|
||||
return;
|
||||
}
|
||||
|
||||
log_message ('COMPACT', "Compacting data from " . strftime ("%Y-%m-%d %H:%M:%S", localtime($limit_utime)) . " to " . strftime ("%Y-%m-%d %H:%M:%S", localtime($start_utime)) . '.', '');
|
||||
next unless defined ($module_type);
|
||||
next if ($module_type == 2 || $module_type == 6 || $module_type == 9 || $module_type == 18 || $module_type == 21 || $module_type == 31 || $module_type == 35 || $module_type == 100);
|
||||
|
||||
# Prepare the query to retrieve data from an interval
|
||||
while (1) {
|
||||
# Obtain the data just for this module
|
||||
my @module_data = grep { $_->{"id_agente_modulo"} == $id } @data;
|
||||
my $total_elements = scalar(@module_data);
|
||||
|
||||
# Calculate the stop date for the interval
|
||||
$stop_utime = $start_utime - $step;
|
||||
# No data for this module.
|
||||
next if ($total_elements == 0);
|
||||
|
||||
# Out of limits
|
||||
last if ($start_utime < $limit_utime);
|
||||
# Obtain the last compact of this module to avoid compact something previously compacted
|
||||
my $last_compact = $module ->{"last_compact"};
|
||||
|
||||
# Mark the progress
|
||||
log_message ('', ".");
|
||||
# In case that the last compact has not been defined take the minimun data as last compact
|
||||
$last_compact = min(map { $_->{"utimestamp"} } @module_data)-1 if($last_compact == 0);
|
||||
|
||||
# Create an array to store INSERT commands
|
||||
my @insert_commands;
|
||||
my $insert_command = 'INSERT INTO tagente_datos (id_agente_modulo, datos, utimestamp) VALUES (?, ?, ?)';
|
||||
|
||||
my $step_number = 0;
|
||||
my $first_compact = $last_compact;
|
||||
|
||||
# Compact using the steps
|
||||
while($step_number < $step_limit){
|
||||
|
||||
my $next_compact = $last_compact + $step;
|
||||
|
||||
my @data = get_db_rows ($dbh, 'SELECT * FROM tagente_datos WHERE utimestamp < ? AND utimestamp >= ?', $start_utime, $stop_utime);
|
||||
# No data, move to the next interval
|
||||
if ($#data == 0) {
|
||||
$start_utime = $stop_utime;
|
||||
last if($next_compact > time());
|
||||
|
||||
# Obtain the data between the last compact and the next step.
|
||||
my @data_in_range = grep { $_->{"utimestamp"} > $last_compact && $_->{"utimestamp"} <= $next_compact } @module_data;
|
||||
|
||||
my $total_range_elements = scalar(@data_in_range);
|
||||
|
||||
# Nothing to compress, skip this step.
|
||||
if($total_range_elements == 0){
|
||||
$last_compact = $next_compact;
|
||||
next;
|
||||
}
|
||||
|
||||
# Get interval data
|
||||
foreach my $data (@data) {
|
||||
my $id_module = $data->{'id_agente_modulo'};
|
||||
if (! defined($module_proc_hash{$id_module})) {
|
||||
my $module_type = get_db_value ($dbh, 'SELECT id_tipo_modulo FROM tagente_modulo WHERE id_agente_modulo = ?', $id_module);
|
||||
next unless defined ($module_type);
|
||||
my $total_data = sum(map { $_->{"datos"} } @data_in_range);
|
||||
|
||||
# Mark proc modules.
|
||||
if ($module_type == 2 || $module_type == 6 || $module_type == 9 || $module_type == 18 || $module_type == 21 || $module_type == 31 || $module_type == 35 || $module_type == 100) {
|
||||
$module_proc_hash{$id_module} = 1;
|
||||
}
|
||||
else {
|
||||
$module_proc_hash{$id_module} = 0;
|
||||
}
|
||||
}
|
||||
my $avg = $total_data / $total_range_elements;
|
||||
|
||||
# Skip proc modules!
|
||||
next if ($module_proc_hash{$id_module} == 1);
|
||||
$proceced_total_data += $total_range_elements;
|
||||
|
||||
push @insert_commands, [$insert_command, $id, $avg, int($last_compact + ($step / 2))];
|
||||
|
||||
if (! defined($value_hash{$id_module})) {
|
||||
$value_hash{$id_module} = 0;
|
||||
$count_hash{$id_module} = 0;
|
||||
$last_compact = $next_compact;
|
||||
|
||||
$step_number +=1;
|
||||
# Small sleep to don't burn the DB
|
||||
usleep (1000);
|
||||
|
||||
}
|
||||
|
||||
if (! defined($id_agent_hash{$id_module})) {
|
||||
$id_agent_hash{$id_module} = $data->{'id_agente'};
|
||||
}
|
||||
}
|
||||
$dbh->begin_work;
|
||||
|
||||
$value_hash{$id_module} += $data->{'datos'};
|
||||
$count_hash{$id_module}++;
|
||||
}
|
||||
db_do ($dbh, 'DELETE FROM tagente_datos WHERE utimestamp > ? AND utimestamp <= ? AND id_agente_modulo = ?', $first_compact, $last_compact, $id);
|
||||
|
||||
# Delete interval from the database
|
||||
db_do ($dbh, 'DELETE ad FROM tagente_datos ad
|
||||
INNER JOIN tagente_modulo am ON ad.id_agente_modulo = am.id_agente_modulo AND am.id_tipo_modulo NOT IN (2,6,9,18,21,31,35,100)
|
||||
WHERE ad.utimestamp < ? AND ad.utimestamp >= ?', $start_utime, $stop_utime);
|
||||
# Execute the INSERT commands
|
||||
foreach my $command (@insert_commands) {
|
||||
my ($sql, @params) = @$command;
|
||||
db_do($dbh, $sql, @params);
|
||||
}
|
||||
|
||||
# Insert interval average value
|
||||
foreach my $key (keys(%value_hash)) {
|
||||
$value_hash{$key} /= $count_hash{$key};
|
||||
db_do ($dbh, 'INSERT INTO tagente_datos (id_agente_modulo, datos, utimestamp) VALUES (?, ?, ?)', $key, $value_hash{$key}, $stop_utime);
|
||||
delete($value_hash{$key});
|
||||
delete($count_hash{$key});
|
||||
}
|
||||
|
||||
usleep (1000); # Very small usleep, just to don't burn the DB
|
||||
# Move to the next interval
|
||||
$start_utime = $stop_utime;
|
||||
$dbh->commit;
|
||||
# Update the last compacted timestamp.
|
||||
db_do($dbh, "UPDATE tagente_modulo SET last_compact = FROM_UNIXTIME(?) WHERE id_agente_modulo = ?", $last_compact, $module ->{"id_agente_modulo"});
|
||||
$compactations += $step_number;
|
||||
}
|
||||
log_message ('', "\n");
|
||||
|
||||
# Mark the last compact date
|
||||
if (defined ($conf->{'_last_compact'})) {
|
||||
db_do ($dbh_conf, 'UPDATE tconfig SET value=? WHERE token=?', $last_compact, 'last_compact');
|
||||
} else {
|
||||
db_do ($dbh_conf, 'INSERT INTO tconfig (value, token) VALUES (?, ?)', $last_compact, 'last_compact');
|
||||
}
|
||||
printf(strftime("\r" . "%H:%M:%S", localtime()) . ' [COMPACT] ' . "Progress: %.2f%%", 100);
|
||||
print("\n");
|
||||
log_message('COMPACT', "A total of $proceced_total_data elements has been compacted into $compactations elements");
|
||||
|
||||
}
|
||||
|
||||
########################################################################
|
||||
|
@ -1234,9 +1308,8 @@ sub pandoradb_main {
|
|||
# Only active database should be compacted. Disabled for historical database.
|
||||
# Compact on if enable and DaysCompact are below DaysPurge
|
||||
if (($conf->{'_onlypurge'} == 0)
|
||||
&& ($conf->{'_days_compact'} < $conf->{'_days_purge'})
|
||||
) {
|
||||
pandora_compactdb ($conf, defined ($history_dbh) ? $history_dbh : $dbh, $dbh);
|
||||
pandora_compactdb ($conf, $dbh, $dbh);
|
||||
}
|
||||
|
||||
# Update tconfig with last time of database maintance time (now)
|
||||
|
|
|
@ -36,7 +36,7 @@ use Encode::Locale;
|
|||
Encode::Locale::decode_argv;
|
||||
|
||||
# version: define current version
|
||||
my $version = "7.0NG.773.3 Build 231023";
|
||||
my $version = "7.0NG.773.3 Build 231024";
|
||||
|
||||
# save program name for logging
|
||||
my $progname = basename($0);
|
||||
|
|
Loading…
Reference in New Issue