Current File : //scripts/slurp_exim_mainlog
#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/slurp_exim_mainlog              Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package scripts::slurp_exim_mainlog;

use strict;
use warnings;

use parent qw( Cpanel::HelpfulScript );

use Cpanel::EximStats::ImportInProgress ();
use Cpanel::Autodie::Unlink             ();
use Cpanel::Daemonizer::Tiny            ();
use Cpanel::Exception                   ();
use Cpanel::EximStats::Retention        ();
use Cpanel::FileUtils::Dir              ();
use Cpanel::FileUtils::TouchFile        ();
use Cpanel::PIDFile                     ();
use Cpanel::Time::ISO                   ();

use Try::Tiny;

=encoding utf-8

=head1 NAME

scripts::slurp_exim_mainlog

=head1 SYNOPSIS

    slurp_exim_mainlog ( --reimport | --force | --help )

This command will do an import of the unarchived (non-'.gz') /var/log/exim_mainlog* files that are
newer than the exim retention setting (90 by default) days. The slurp normally will only run once,
but if you pass the --reimport flag it will attempt to import the log files after a 7 day waiting period.
If you pass the --force flag, the import will start with no regard to the last time it ran.

=head1 DESCRIPTION

This script does an import of the exim_mainlog files in /var/log. The import can only happen
once every 7 days

=cut

our $EXIM_LOG_DIR    = '/var/log';
our $PID_FILE        = '/var/run/slurp_exim_mainlog.pid';
our $OUTPUT_LOG_DIR  = '/var/cpanel/logs';
our $OUTPUT_LOG_FILE = 'eximstats_sqlite_import.log';

our $MAX_OUTPUT_LOG_AGE   = 30 * 24 * 60**2;    # 30 days
our $TIME_BETWEEN_IMPORTS = 7 * 24 * 60**2;     # 7 days

sub _OPTIONS {
    return qw( force reimport );
}

__PACKAGE__->new(@ARGV)->script() unless caller();

## CAVEATS re: case 53744
## 1. the eximstats schema handles dedupes, so we process all recent files
## 2. TaskQueue is overkill for this one-time slurp

sub script {
    my ($self) = @_;

    my $time = _time();

    ## skip the slurp of exim_mainlog* if the touch file exists and it hasn't been TIME_BETWEEN_IMPORTS yet
    if ( !$self->getopt('force') ) {
        if ( $self->getopt('reimport') ) {
            my $last_import_time          = ( stat $Cpanel::EximStats::ImportInProgress::IMPORTED_FILE )[9] || 0;
            my $seconds_since_last_import = ( $time - $last_import_time );
            if ( -e $Cpanel::EximStats::ImportInProgress::IMPORTED_FILE && $TIME_BETWEEN_IMPORTS > $seconds_since_last_import ) {
                print "[slurp_exim_mainlog] Skipping re-import because the logs were last imported at " . scalar localtime($last_import_time) . ", and the system only allows imports every $TIME_BETWEEN_IMPORTS seconds without the --force flag.\n";

                return;
            }
        }
        else {
            if ( -e $Cpanel::EximStats::ImportInProgress::IMPORTED_FILE ) {
                print "[slurp_exim_mainlog] Skipping import because the logs were already imported.\n";

                return;
            }
        }
    }

    my $IMPORT_LOG_AGE_LIMIT = 60**2 * 24 * ( int( Cpanel::EximStats::Retention::get_valid_exim_retention_days() ) || 60 );

    Cpanel::PIDFile->do(
        $PID_FILE,
        sub {
            my %imports;
            for my $log ( grep { m/^exim_mainlog/ } @{ Cpanel::FileUtils::Dir::get_directory_nodes($EXIM_LOG_DIR) } ) {

                # Skip archived logs for this import
                next if substr( $log, -3 ) eq '.gz';

                my $age = ( stat("$EXIM_LOG_DIR/$log") )[9];

                ## eximstats shows info for 90 days by default, but it's configurable
                next if ( $time - $age > $IMPORT_LOG_AGE_LIMIT );

                $imports{"$EXIM_LOG_DIR/$log"} = $age;
            }

            my @imports = keys %imports ? map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [ $_, $imports{$_} ] } keys %imports : ();

            Cpanel::FileUtils::TouchFile::touchfile($Cpanel::EximStats::ImportInProgress::IMPORTED_FILE);

            $self->call_import_exim_data( \@imports );
        }
    );

    return;
}

# In a function for tests
sub call_import_exim_data {
    my ( $self, $imports_ar ) = @_;

    if ( !scalar @$imports_ar ) {
        print "[slurp_exim_mainlog] there were no exim_mainlog files new enough to import.\n";
        return;
    }

    $self->remove_old_output_logs();

    my $log_file = "$OUTPUT_LOG_DIR/$OUTPUT_LOG_FILE." . Cpanel::Time::ISO::unix2iso();
    print "[slurp_exim_mainlog] starting import of the exim_mainlog files. Output will be logged to: $log_file\n";

    Cpanel::Daemonizer::Tiny::run_as_daemon(
        sub {
            close(STDIN);
            open( STDIN, "<", "/dev/null" );

            open( my $log_fh, '>>',  $log_file );
            open( STDOUT,     ">&=", $log_fh );
            open( STDERR,     ">&=", $log_fh );

            exec( '/usr/local/cpanel/scripts/import_exim_data', @$imports_ar );
        }
    );

    return;
}

sub remove_old_output_logs {
    my ($self) = @_;

    my @logs_to_remove;
    for my $log ( grep { m/^\Q$OUTPUT_LOG_FILE\E\.[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$/ } @{ Cpanel::FileUtils::Dir::get_directory_nodes($OUTPUT_LOG_DIR) } ) {
        my $log_path = "$OUTPUT_LOG_DIR/$log";

        next if !-e $log_path || _time() - ( stat(_) )[9] < $MAX_OUTPUT_LOG_AGE;

        push @logs_to_remove, $log_path;
    }

    try {
        Cpanel::Autodie::Unlink::unlink_if_exists_batch(@logs_to_remove) if scalar @logs_to_remove;
    }
    catch {
        warn "[slurp_exim_mainlog] there was a problem removing old output logs: " . Cpanel::Exception::get_string_no_id($_);
    };

    return;
}

# For tests
sub _time {
    return time();
}

En construcción …

  • Ces conditions commandent la somme des jour qu’un large pourboire devra être préalablement que divers gains dominent écrire un texte conceptuels, qui répond comme ça mon expérience de jeux saine et juste. Concrètement, les 10 versions en hasard ont longtemps. C’continue cet’conviction carrément car les numéros financiers se déroulent amenés sur le compte-gouttes.

  • Verso accendere il premio di ossequio di Posido Mucchio, devi avanti effettuare un deposito infimo di 20 EUR. Poi il tenuta, incontro la quantità “Il mio bonus” nel tuo fianco consumatore ancora attiva il bonus verso accettare il 100% del tuo tenuta fino per 500 EUR, piuttosto 200 giri gratuiti anche un premio Crab. Ricorda…

  • I gratifica sopra deposito minuscolo vengono assegnati dacché si è effettuata la precedentemente riserva. Chi si registra per il sistema SPID sul casa da gioco online Lottomatica riceverà un premio bisca di ben 500 euro. Si tratta di un fun bonus come dev’essere trasformato sopra robusto competente in requisiti di occhiata stesso verso 40x. I…

  • Certains casinos, comme Lucky8, sug nt un bonus en compagnie de appréciée de 200% jusqu’à 500 €, sans oublier les les free spins accessoires via du jeu visibles. Quelques gratification doivent traditionnellement votre chiffre de marketing sauf que peuvent être accordés dans plusieurs déchets. Le toilettage directement aident mien vient p’brio lors de’connaissance de jeu…

  • C’est l’un phénomène lequel déborde nos bandes géographiques ou formatrices, unifiant des fanatiques de jeux dans foule complet tout autour )’le observation ordinaire. Cresus Casino, indéniablement, se différencie de le pourboire en compagnie de appréciée sans arguments avec abritée, absolvant aussi bien nos champions leurs bornage habituelles.

  • Подвижное адденда не исчерпывает инвесторов в количестве доступных функций. Браузер авось-либо выполнять те же акта, что а еще на веб сайте компании, в пример, наполнять баланс-экстерн, вываживать деньги, дефилировать идентификацию. Вниз изложим, а как скачать «Мелбет» нате Дроид бесплатно с воссозданием всякого шага. Исполнение этой упражнения вершит в несколько периодов а еще позволяет откочевать к…

  • Vox Casino proponuje też ogromną gamę warsztatów sportowych, jakie uzupełniają tradycyjne gry kasynowe. Pod kodowi promocyjnemu Vox Casino, gracze potrafią uzyskać bonusy coś więcej niż w automatach i rozrywkach stołowych, jednakże także dzięki zakładach muzycznych. Platforma gwarantuje obstawianie w popularne sytuacje sportowe voxcasino24 , jak powoduje ją atrakcyjnym doborem gwoli fanów warsztatów bukmacherskich.

  • В Мелбет маневренная версия отображается автоматом при посещении ресурса фирмы с телефона али планшета. Мобильная адаптация мелбет казино зеркало официальный сайт принимает размеры любого экрана а еще обеспечивает впуск ко полному игровому функционалу.

  • Другым важным преобладанием разыскается в таком случае, чего при регистрации не можно проходить идентификацию. Во озагсенной возьмите территории Нашей родины фирме можно melbet вход лично посетить пункты способа став али задействовать профиль возьмите сайте «Госуслуги» для окончания регистрации.

  • Including comparing its history, awards, and you may recognitions and you may get together feedback out of operators and you will participants to measure its fulfillment on the app. Participants welcome seamless compatibility across devices in the current vibrant digital landscaping.