Setup ViewCheck

master
Heuzef 5 years ago
parent a07427c0fc
commit 385fc2e1e9
  1. 98
      ViewCheck.pm

@ -30,24 +30,23 @@ use Getopt::Long;
use Statistics::Descriptive; use Statistics::Descriptive;
use Data::Dumper; use Data::Dumper;
my $host = undef; my $host = "localhost";
GetOptions( sub action
"host=s" => \$host {
);
# We need to switch to backuppc UID/GID # We need to switch to backuppc UID/GID
my $uid = getuid(); my $uid = getuid();
my $gid = getgid(); my $gid = getgid();
my (undef,undef,$bkpuid,$bkpgid) = getpwnam('backuppc'); my (undef,undef,$bkpuid,$bkpgid) = getpwnam('backuppc');
setuid($bkpuid) if ($uid ne $bkpuid); setuid($bkpuid) if ($uid ne $bkpuid);
setgid($bkpgid) if ($gid ne $bkpgid); setgid($bkpgid) if ($gid ne $bkpgid);
my $bpc = BackupPC::Lib->new(); my $bpc = BackupPC::Lib->new();
my $mainConf = $bpc->ConfigDataRead(); my $mainConf = $bpc->ConfigDataRead();
my $json = {}; my $json = {};
if ( $host ) { if ( $host ) {
my $hostConf = $bpc->ConfigDataRead($host); my $hostConf = $bpc->ConfigDataRead($host);
my $conf = { %$mainConf, %$hostConf }; my $conf = { %$mainConf, %$hostConf };
my $age = -1; my $age = -1;
@ -90,56 +89,59 @@ if ( $host ) {
$json->{age} = time - $bpc_info[$i]->{startTime}; $json->{age} = time - $bpc_info[$i]->{startTime};
$json->{last_age} = sprintf("%.1f", ($json->{age}) / 84600); $json->{last_age} = sprintf("%.1f", ($json->{age}) / 84600);
} }
} }
else { else {
print<<"EOF"; print<<"EOF";
Usage: $0 --host=<host> Usage: $0 --host=<host>
EOF EOF
} }
# Print results # Print results
print("\n----------------\n"); print("\n----------------\n");
print("Last Backup : $json->{last_age}"); print("Last Backup : $json->{last_age}");
print("\n"); print("\n");
print("Errors : $json->{errors}"); print("Errors : $json->{errors}");
print("\n"); print("\n");
print("Size Consistency : "); print("Size Consistency : ");
# TOO BIG ? # TOO BIG ?
my $toobig = "1"; my $toobig = "1";
if ( $json->{new_size} > ($json->{new_size_q3} + $json->{new_size_q3} - $json->{new_size_q1}) * 1.5 or $json->{new_size} > $json->{new_size_avg} * 6 ) { if ( $json->{new_size} > ($json->{new_size_q3} + $json->{new_size_q3} - $json->{new_size_q1}) * 1.5 or $json->{new_size} > $json->{new_size_avg} * 6 ) {
$toobig = "1"; $toobig = "1";
} }
else { else {
$toobig = "0"; $toobig = "0";
} }
# TOO SMALL ? # TOO SMALL ?
my $toosmall = "1"; my $toosmall = "1";
if ( $json->{new_size} < ($json->{new_size_q1} - $json->{new_size_q3} - $json->{new_size_q1}) * 1.5 or $json->{new_size} < $json->{new_size_avg} / 3 ) { if ( $json->{new_size} < ($json->{new_size_q1} - $json->{new_size_q3} - $json->{new_size_q1}) * 1.5 or $json->{new_size} < $json->{new_size_avg} / 3 ) {
$toosmall = "1"; $toosmall = "1";
} }
else { else {
$toosmall = "0"; $toosmall = "0";
} }
# Print result # Print result
if ( $toobig or $toosmall ) { if ( $toobig or $toosmall ) {
print("ANOMALOUS"); print("ANOMALOUS");
} }
else { else {
print("Normal"); print("Normal");
} }
print("\n"); print("\n");
print("Random file : "); print("Random file : ");
# Random file
# Random file print("Random file");
print("\n");
print("\n----------------\n");
print("Random file"); exit(0);
print("\n");
print("\n----------------\n");
exit(0); }
1;

Loading…
Cancel
Save