Merge branch '125-Gestión-recolección-y-correlación-de-logs-dev' into 'develop'
Added preproc header pandora_migrate_logs Closes #125 See merge request !791
This commit is contained in:
commit
6e1a201e2a
|
@ -1,14 +1,32 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
#
|
||||||
|
# Pandora FMS log migration tool
|
||||||
|
#
|
||||||
|
# Artica ST 2017
|
||||||
|
# 2017/09/07 v1 (c) Fco de Borja Sanchez <fborja.sanchez@artica.es>
|
||||||
|
#
|
||||||
|
########################################################################
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use lib '/usr/lib/perl5';
|
|
||||||
|
|
||||||
use PandoraFMS::Config;
|
|
||||||
use PandoraFMS::DB;
|
|
||||||
use JSON;
|
use JSON;
|
||||||
use IO::Socket::INET;
|
use IO::Socket::INET;
|
||||||
use File::Copy;
|
use File::Copy;
|
||||||
|
|
||||||
|
use lib '/usr/lib/perl5';
|
||||||
|
|
||||||
|
use PandoraFMS::Config;
|
||||||
|
use PandoraFMS::Tools;
|
||||||
|
use PandoraFMS::DB;
|
||||||
|
|
||||||
|
my $HELP=<<EO_HELP;
|
||||||
|
|
||||||
|
Pandora FMS log migration tool (c) Artica ST
|
||||||
|
|
||||||
|
Usage $0 /etc/pandora/pandora_server.conf
|
||||||
|
|
||||||
|
|
||||||
|
EO_HELP
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# Migrate log data
|
# Migrate log data
|
||||||
|
@ -79,9 +97,9 @@ sub recursive_file_apply {
|
||||||
my $dh;
|
my $dh;
|
||||||
opendir($dh,$item) or die ("Cannot open directory [$item]");
|
opendir($dh,$item) or die ("Cannot open directory [$item]");
|
||||||
|
|
||||||
my @sorted_dirs = sort {(stat $a)[10] <=> (stat $b)[10]} readdir($dh);
|
my @dirs = readdir($dh); # no need to sort them, the timestamp is in the file name.
|
||||||
|
|
||||||
foreach my $object (@sorted_dirs) {
|
foreach my $object (@dirs) {
|
||||||
next if ($object =~ /^\./);
|
next if ($object =~ /^\./);
|
||||||
recursive_file_apply($pa_config, $dbh, $psub, $item . "/" . $object)
|
recursive_file_apply($pa_config, $dbh, $psub, $item . "/" . $object)
|
||||||
}
|
}
|
||||||
|
@ -103,12 +121,15 @@ sub recursive_file_apply {
|
||||||
|
|
||||||
my %pa_config;
|
my %pa_config;
|
||||||
|
|
||||||
|
if ($#ARGV < 0) {
|
||||||
|
print STDERR $HELP;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
print STDERR "Starting migration process\n";
|
||||||
|
|
||||||
pandora_init(\%pa_config, 'Pandora FMS log migration tool');
|
pandora_init(\%pa_config, 'Pandora FMS log migration tool');
|
||||||
pandora_load_config (\%pa_config);
|
pandora_load_config (\%pa_config);
|
||||||
|
|
||||||
# Start logging
|
|
||||||
pandora_start_log (\%pa_config);
|
|
||||||
|
|
||||||
# Connect to the DB
|
# Connect to the DB
|
||||||
my $dbh = db_connect ($pa_config{'dbengine'}, $pa_config{'dbname'}, $pa_config{'dbhost'}, $pa_config{'dbport'},
|
my $dbh = db_connect ($pa_config{'dbengine'}, $pa_config{'dbname'}, $pa_config{'dbhost'}, $pa_config{'dbport'},
|
||||||
$pa_config{'dbuser'}, $pa_config{'dbpass'});
|
$pa_config{'dbuser'}, $pa_config{'dbpass'});
|
||||||
|
@ -142,5 +163,5 @@ if ( (defined($pa_config{'logstash_host'}) && $pa_config{'logstash_host'} ne ''
|
||||||
$dbh->disconnect();
|
$dbh->disconnect();
|
||||||
|
|
||||||
logger(\%pa_config,"Migration completed", 1);
|
logger(\%pa_config,"Migration completed", 1);
|
||||||
|
print STDERR "Migration complete\n";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue