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

Loading…
Cancel
Save