diff --git a/conf/backuppc.conf b/conf/backuppc.conf new file mode 100644 index 0000000..8f323a6 --- /dev/null +++ b/conf/backuppc.conf @@ -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 diff --git a/scripts/check_backuppc_sudo b/scripts/check_backuppc_sudo new file mode 100644 index 0000000..99a42dc --- /dev/null +++ b/scripts/check_backuppc_sudo @@ -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 [errors|age|size|duration] + +EOF +} +exit(0); diff --git a/scripts/disco_backuppc_sudo b/scripts/disco_backuppc_sudo new file mode 100644 index 0000000..c3fceb2 --- /dev/null +++ b/scripts/disco_backuppc_sudo @@ -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);