From 2893a846354b666e6035e031756742334c3fe197 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 14 Sep 2015 16:41:35 +0200 Subject: [PATCH] Add simple scripts for monitoring DRBD resources with auto-discovery --- zabbix_conf/drbd.conf | 6 ++++++ zabbix_scripts/check_drbd | 46 ++++++++++++++++++++++++++++++++++++++++++++++ zabbix_scripts/disco_drbd | 26 ++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 zabbix_conf/drbd.conf create mode 100644 zabbix_scripts/check_drbd create mode 100644 zabbix_scripts/disco_drbd diff --git a/zabbix_conf/drbd.conf b/zabbix_conf/drbd.conf new file mode 100644 index 0000000..be5dc2f --- /dev/null +++ b/zabbix_conf/drbd.conf @@ -0,0 +1,6 @@ +# Discover DRBD resources +UserParameter=drbd.resource.discovery[*],/var/lib/zabbix/bin/disco_drbd + +# DRBD status +UserParameter=drbd.resource.status[*],/var/lib/zabbix/bin/check_drbd --resource=$1 --what=$2 + diff --git a/zabbix_scripts/check_drbd b/zabbix_scripts/check_drbd new file mode 100644 index 0000000..b5772f1 --- /dev/null +++ b/zabbix_scripts/check_drbd @@ -0,0 +1,46 @@ +#!/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= + +EOF +} + +unless ((grep { $_ eq $what } @supported) && $resource){ + usage(); + exit 1; +} + +open RES, '-|', $drbdadm, $what, $resource || die "Can't open pipe: $!"; +my $out = join "", ; +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; diff --git a/zabbix_scripts/disco_drbd b/zabbix_scripts/disco_drbd new file mode 100644 index 0000000..faf993c --- /dev/null +++ b/zabbix_scripts/disco_drbd @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w + +use warnings; +use strict; +use File::Which; +use JSON; + +my $json; +@{$json->{data}} = (); +my $drbdoverview = which('drbd-overview'); + +if ($drbdoverview){ + open RES, "$drbdoverview |" || die "Couldn't execute $drbdoverview"; + foreach my $l (){ + if ($l =~ m{(\d+):(\w+)/\d+}){ + push @{$json->{data}}, { + "{#DRBD_RES_ID}" => $1, + "{#DRBD_RES_NAME}" => $2 + }; + } + } + close RES; +} + +print to_json($json); +exit(0);