����JFIF��x�x����'
| Server IP : 78.140.185.180 / Your IP : 216.73.216.170 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 : /proc/1630575/root/proc/1630575/root/proc/self/root/usr/lib64/nagios/plugins/extra/ |
Upload File : |
#!/usr/bin/env perl
use extreme;
use File::Slurp;
use POSIX qw(strftime);
use Net::FTP;
use DBI;
use MIME::Base64;
my @incidents;
my $exit_code = 0;
my $bkp_log = '/usr/local/mgr5/var/backup2.log';
my $bkp_ok = '/var/tmp/backup_ok';
my $bkp_bl = '/var/tmp/backup_bl';
my $bkp_wl = '/etc/icinga2/plinc/backupwhitelist';
my $isp_db = '/usr/local/mgr5/etc/ispmgrnode.db';
my $bkp_log_mdtm = ( stat($bkp_log) )[9];
my $today_date = strftime "%F", localtime;
my $today_hour = strftime "%H", localtime;
my $bkp_log_date = strftime "%F", localtime($bkp_log_mdtm);
my $bkp_log_last_line = last_line($bkp_log);
unlink $bkp_ok, $bkp_bl if $today_hour <= 1;
if ( -f $bkp_ok ) {
say "backup OK";
exit $exit_code;
}
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;
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;
if ( $bkp_log_date ne $today_date || $bkp_log_last_line !~ m/finished/i ) {
$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 $dbh = create_dbh($isp_db);
my $users = $dbh->selectall_arrayref(
"SELECT name FROM users WHERE active = 'on' AND create_time NOT LIKE ?;",
undef, "$today_date%"
);
push @bl, ( 'root', 'ispmaster', 'fozzy' );
my ( $ftp_host, $ftp_user, $ftp_pass, $ftp_path ) = get_ftp_credentials();
my $ftp = Net::FTP->new($ftp_host);
$ftp->login( $ftp_user, $ftp_pass );
for my $user ( $users->@* ) {
next if ( $user->[0] ~~ @bl || $user->[0] ~~ @wl );
$ftp->cwd("$ftp_path/$user->[0]/$today_date");
my ($archive) = grep /^$today_date.*mainweb\.tgz$/, $ftp->ls;
if ( !$archive ) {
push @incidents, "Last backup for user '$user->[0]' not found";
$exit_code = 2;
}
}
if (@incidents) {
say join( "\n", @incidents );
exit $exit_code;
}
unlink $bkp_bl;
open( my $FH, '>', $bkp_ok );
say "backup OK";
# SUBS
sub last_line {
my $file = shift;
my $line;
open my $FH, '<', $file;
while (<$FH>) { $line = $_ if eof }
chomp $line;
return $line;
}
sub create_dbh {
my $db = shift;
return DBI->connect( "DBI:SQLite:dbname=$db", '', '',
{ RaiseError => 1 } );
}
sub get_ftp_credentials {
my $bkp_conf_file = '/usr/local/mgr5/etc/ispmgr.conf';
my $ftp_conf;
my $conf_line;
open my $FH, $bkp_conf_file or die "Could not open $bkp_conf_file: $!";
while ( my $line = <$FH> ) {
$conf_line = $line if $line =~ m/^BackupToken/;
}
close $FH;
my ( $pass, $path, $host, $user )
= $conf_line
=~ m/password=(.*);path=(.*?);.*url=ftp:\/\/(.*).*;username=(.*)/;
$pass = decode_base64($pass);
return ( $host, $user, $pass, $path );
}