����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/self/root/proc/self/root/proc/1630575/root/usr/lib64/nagios/plugins/extra/ |
Upload File : |
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use experimental qw(smartmatch);
use File::Slurp qw(read_file);
use POSIX qw(strftime);
use Carp;
use DBI;
use Time::Piece;
use PT::Client;
my @incidents;
my $exit_code = 0;
my $today_date = localtime->dmy;
my $today_hour = strftime "%H", localtime;
if ( $today_hour <= '7' ) {
say 'Backup did not start yet';
exit;
}
my $bkp_wl = '/etc/icinga2/plinc/backupwhitelist';
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} //= 19;
$conf->{critical_h} //= 22;
my $db_config = '/root/.backup';
croak 'DB config does not exist' if !-f $db_config;
my %db_conf = map { chomp; split /\s*=\s*/ } read_file($db_config)
if -r $db_config;
my $dsn = "DBI:mysql:panel:$db_conf{'hostname'}";
my $dbh = DBI->connect( $dsn, $db_conf{'username'}, $db_conf{'password'} ) or croak 'Cannot connect to MySQL server!';
my $pt_cli = PT::Client->new();
my @containers = `/bin/docker ps --format '{{.Names}}'`;
my $prefix = '/var/lib/pterodactyl';
my $backup_dir = $prefix . '/backups';
my @servers_info = $pt_cli->get('/application/servers?per_page=99999')->{data}->@*;
# check if backup is still in progress
my $process = `ps aux | grep "handle_ptero_backups.pl --action create" | grep -v grep`;
if ($process) {
$exit_code = 1 if $today_hour > $conf->{warning_h};
$exit_code = 2 if $today_hour > $conf->{critical_h};
if ($exit_code) {
say "Backup is still running. Maybe something goes wrong.\n Check it, or adjust {warning,critical}_h in /etc/backup.conf";
exit $exit_code;
}
else {
say 'Backup is running';
exit;
}
}
for my $container (@containers) {
next if ( $container =~ /installer$/ || $container ~~ @wl );
chomp $container;
my @server_info =
map { $_ } grep { $_->{attributes}->{uuid} eq $container } @servers_info;
my $server_info = $server_info[0]->{attributes};
my $container_created = eval
{
Time::Piece->strptime(
$server_info->{created_at},
"%Y-%m-%dT%H:%M:%S+%R"
)->epoch
};
if (!$container_created) {
$exit_code = 2;
push @incidents, "Cannot determine creation date for $container";
next;
}
my $cur_time = localtime->epoch;
next if ( $cur_time - $container_created < '86400' );
my $sth = $dbh->prepare('SELECT * FROM backups WHERE server_id=?;');
$sth->execute( $server_info->{id} );
my $backups_info = $sth->fetchall_hashref('name');
if ( !keys %$backups_info) {
$exit_code = 2;
push @incidents, "No backups available for $server_info->{name}!";
next;
}
my $today_info = $backups_info->{$today_date};
if ( !$backups_info->{$today_date} || !$today_info->{is_successful} || ! -f "$backup_dir/$today_info->{uuid}.tar.gz" ) {
push @incidents, "Today's backup not found for $server_info->{name}!";
$exit_code = 2;
}
}
say join( "\n", @incidents ) if @incidents;
exit $exit_code;