zabbix-agent-addons/zabbix_scripts/check_drbd
Daniel Berteaud 2893a84635 Add simple scripts for monitoring DRBD resources
with auto-discovery
2015-09-14 16:41:35 +02:00

47 lines
775 B
Perl

#!/usr/bin/perl -w
use strict;
use File::Which;
use Getopt::Long;
my $what = 'cstate';
my $resource = undef;
my @supported = qw(cstate dstate role);
GetOptions(
"what=s" => \$what,
"resource=s" => \$resource
);
my $drbdadm = which('drbdadm');
unless($drbdadm){
die 'ZBX_NOTSUPPORTED';
}
sub usage(){
my $supp = join('|', @supported);
print <<"EOF";
usage: $0 --what=[$supp] --resource=<drbd resource name>
EOF
}
unless ((grep { $_ eq $what } @supported) && $resource){
usage();
exit 1;
}
open RES, '-|', $drbdadm, $what, $resource || die "Can't open pipe: $!";
my $out = join "", <RES>;
close RES || die "An error occured: $!\n";
chomp($out);
# We only want the state of the local node
if ($out =~ m{(.*)/.*}){
$out = $1;
}
print $out;
exit 0;