Additional scripts for Zabbix agent on Linux to discover and monitor several services
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

58 lines
1.5 KiB

#!/usr/bin/perl
use lib "/usr/share/BackupPC/lib";
use BackupPC::Lib;
use BackupPC::CGI::Lib;
use POSIX;
use JSON;
use Getopt::Long;
my $hosts = 1;
my $entities = 0;
GetOptions(
"hosts" => \$hosts,
"entities" => \$entities
);
# 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 $json;
@{$json->{data}} = ();
if ($entities) {
my %entities = ();
foreach my $host ( keys %$hosts ){
if ( $host =~ m/^(?:vm_)?([^_]+)_.*/ and $1 ne 'vm' ) {
$entities{$1}= 1;
}
}
push @{$json->{data}}, { '{#BPC_ENTITY}' => $_ } foreach ( keys %entities );
} elsif ($hosts){
foreach my $host ( keys %$hosts ){
my $hostConf = $bpc->ConfigDataRead($host);
my $conf = { %$mainConf, %$hostConf };
my $warning = $conf->{EMailNotifyOldBackupDays};
my $errors = ( defined $conf->{MaxXferError} ) ? $conf->{MaxXferError}: '0';
my $monitoring = $conf->{ZabbixMonitoring} || 1;
my $status = ( $conf->{BackupsDisable} gt 0 or $monitoring eq '0' ) ? '0' : '1';
push @{$json->{data}},
{
"{#BPCHOST}" => $host,
"{#BPCNOBACKUPWARNING}" => $warning,
"{#BPCMAXERROR}" => $errors,
"{#BPCSTATUS}" => $status,
};
}
}
print to_json($json);
exit(0);