parent
bcc92a6193
commit
f9d3f81616
3 changed files with 121 additions and 0 deletions
@ -0,0 +1,13 @@ |
|||||||
|
# Discovery of configured host |
||||||
|
# Key: backuppc.host.discovery |
||||||
|
# Macro: {#BPCSTATUS} |
||||||
|
# Filter regex: enabled => true |
||||||
|
# Other available macros: |
||||||
|
# {#BPCPERIOD}: Max age (in day) the oldest backup should be |
||||||
|
# {#BPCHOST}: name of the backup host |
||||||
|
UserParameter=backuppc.host.discovery,/usr/bin/sudo /var/lib/zabbix/bin/disco_backuppc_sudo |
||||||
|
|
||||||
|
# Item prototypes |
||||||
|
# key: backuppc.host.info[{#BPCHOST},item] |
||||||
|
# Valide item are: errors, size, duration, age |
||||||
|
UserParameter=backuppc.host.info[*],/usr/bin/sudo /var/lib/zabbix/bin/check_backuppc_sudo $1 $2 |
@ -0,0 +1,74 @@ |
|||||||
|
#!/usr/bin/perl -w |
||||||
|
|
||||||
|
use lib "/usr/share/BackupPC/lib"; |
||||||
|
use BackupPC::Lib; |
||||||
|
use BackupPC::CGI::Lib; |
||||||
|
use POSIX; |
||||||
|
use JSON; |
||||||
|
|
||||||
|
# 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 $host = $ARGV[0]; |
||||||
|
my $what = $ARGV[1]; |
||||||
|
|
||||||
|
my $bpc = BackupPC::Lib->new(); |
||||||
|
my @backups = $bpc->BackupInfoRead($host); |
||||||
|
my $fullCnt = $incrCnt = 0; |
||||||
|
my $fullAge = $incrAge = $lastAge = -1; |
||||||
|
my $lastXferErrors = 0; |
||||||
|
|
||||||
|
for ( my $i = 0 ; $i < @backups ; $i++ ) { |
||||||
|
if ( $backups[$i]{type} eq "full" ) { |
||||||
|
$fullCnt++; |
||||||
|
if ( $fullAge < 0 || $backups[$i]{startTime} > $fullAge ) { |
||||||
|
$fullAge = $backups[$i]{startTime}; |
||||||
|
$fullSize = $backups[$i]{size}; |
||||||
|
$fullDur = $backups[$i]{endTime} - $backups[$i]{startTime}; |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
$incrCnt++; |
||||||
|
if ( $incrAge < 0 || $backups[$i]{startTime} > $incrAge ) { |
||||||
|
$incrAge = $backups[$i]{startTime}; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if ( $fullAge > $incrAge && $fullAge >= 0 ) { |
||||||
|
$lastAge = $fullAge; |
||||||
|
} |
||||||
|
else { |
||||||
|
$lastAge = $incrAge; |
||||||
|
} |
||||||
|
if ( $lastAge < 0 ) { |
||||||
|
$lastAge = ""; |
||||||
|
} |
||||||
|
else { |
||||||
|
$lastAge = sprintf("%.1f", (time - $lastAge) / (24 * 3600)); |
||||||
|
} |
||||||
|
$lastXferErrors = $backups[@backups-1]{xferErrs} if ( @backups ); |
||||||
|
|
||||||
|
if ($what eq 'errors'){ |
||||||
|
print $lastXferErrors; |
||||||
|
} |
||||||
|
elsif ($what eq 'age'){ |
||||||
|
print $lastAge; |
||||||
|
} |
||||||
|
elsif ($what eq 'size'){ |
||||||
|
print $fullSize; |
||||||
|
} |
||||||
|
elsif ($what eq 'duration'){ |
||||||
|
print $fullDur; |
||||||
|
} |
||||||
|
else{ |
||||||
|
print<<"EOF"; |
||||||
|
|
||||||
|
Usage: $0 <host> [errors|age|size|duration] |
||||||
|
|
||||||
|
EOF |
||||||
|
} |
||||||
|
exit(0); |
@ -0,0 +1,34 @@ |
|||||||
|
#!/usr/bin/perl -w |
||||||
|
|
||||||
|
use lib "/usr/share/BackupPC/lib"; |
||||||
|
use BackupPC::Lib; |
||||||
|
use BackupPC::CGI::Lib; |
||||||
|
use POSIX; |
||||||
|
use JSON; |
||||||
|
|
||||||
|
# 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 $hosts = $bpc->HostInfoRead(); |
||||||
|
my $mainConf = $bpc->ConfigDataRead(); |
||||||
|
|
||||||
|
my $data; |
||||||
|
foreach my $host (keys %$hosts){ |
||||||
|
my $hostConf = $bpc->ConfigDataRead($host); |
||||||
|
my $conf = { %$mainConf, %$hostConf }; |
||||||
|
my $period = ($conf->{FullPeriod} >= $conf->{IncrPeriod}) ? $conf->{IncrPeriod} : $conf->{FullPeriod}; |
||||||
|
my $status = ($conf->{BackupsDisable} eq 1) ? 'disabled':'enabled'; |
||||||
|
push @{$data->{data}}, |
||||||
|
{ |
||||||
|
"{#BPCHOST}" => $host, |
||||||
|
"{#BPCPERIOD}" => $period, |
||||||
|
"{#BPCSTATUS}" => $status, |
||||||
|
}; |
||||||
|
} |
||||||
|
print to_json($data, {pretty => 1}); |
||||||
|
exit(0); |
Loading…
Reference in new issue