From 6c012aece01435b63284ecef0949a06b71920e6d Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 21 May 2019 11:57:45 +0200 Subject: [PATCH] Add basic scripts to monitor VDO volumes --- zabbix_conf/vdo.conf | 12 ++++++++++++ zabbix_scripts/check_vdo_sudo | 45 +++++++++++++++++++++++++++++++++++++++++++ zabbix_scripts/disco_vdo_sudo | 31 +++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 zabbix_conf/vdo.conf create mode 100644 zabbix_scripts/check_vdo_sudo create mode 100644 zabbix_scripts/disco_vdo_sudo diff --git a/zabbix_conf/vdo.conf b/zabbix_conf/vdo.conf new file mode 100644 index 0000000..b3ab9e1 --- /dev/null +++ b/zabbix_conf/vdo.conf @@ -0,0 +1,12 @@ +# Discover VDO volumes +# $1 not used for now +UserParameter=vfs.vdo.vol.discovery[*],/var/lib/zabbix/bin/disco_zfs --what=volumes + +# Type: Agent or Agent (active) +# Key: vfs.vdo.vol[volume,item] where volume is the name of the volume to monitor +# item can be one of the valid keys (run manually without --value arg to see available keys) +UserParameter=vfs.vdo.vol[*],/var/lib/zabbix/bin/check_vdo_sudo --volume=$1 --value=$2 + +# Type: Agent or Agent (active) +# You can also get all the info about a vdo volume at once, in JSON +UserParameter=vfs.vdo.vol.all[*],/var/lib/zabbix/bin/check_vdo_sudo --volume=$1 diff --git a/zabbix_scripts/check_vdo_sudo b/zabbix_scripts/check_vdo_sudo new file mode 100644 index 0000000..3f09ef4 --- /dev/null +++ b/zabbix_scripts/check_vdo_sudo @@ -0,0 +1,45 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use JSON; +use Getopt::Long; +use File::Which; + +my $vdostats = which('vdostats'); +my $json = {}; +my $pretty = 0; +my $volume = undef; +my $val = undef; + +GetOptions( + 'volume=s' => \$volume, + 'value=s' => \$val, + 'pretty' => \$pretty +); + +if ($volume) { + if ($volume !~ m/^\w+$/){ + die "Invalide volume name\n"; + } + foreach my $line (qx($vdostats --all $volume)){ + if ($line =~ m/^\s+([^:]+)\s+:\s+([\d\w]+)/){ + my ($key,$val) = ($1,$2); + # Cleanup key + $key =~ s/\s+$//; + $key =~ s/\s+/_/g; + $key =~ s/\(|\)//g; + $key =~ s/%/pct/g; + $json->{lc $key} = $val; + } + } +} else { + print 'ZBX_NOTSUPPORTED'; + exit 0; +} +if (defined $val) { + print $json->{$val} || 'ZBX_NOTSUPPORTED'; +} else { + print to_json($json, { pretty => $pretty }); +} +print "\n"; diff --git a/zabbix_scripts/disco_vdo_sudo b/zabbix_scripts/disco_vdo_sudo new file mode 100644 index 0000000..f94ab60 --- /dev/null +++ b/zabbix_scripts/disco_vdo_sudo @@ -0,0 +1,31 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use JSON; +use File::Which; +use Getopt::Long; + +my $json; +@{$json->{data}} = (); + +my $what = 'volumes'; +my $pretty = 0; + +GetOptions( + 'what=s' => \$what, + 'pretty' => \$pretty +); + +my $vdostats = which('vdostats'); + +if (defined $vdostats) { + foreach my $line (qx($vdostats)) { + if ($line =~ m|^/dev/mapper/([^\s]+)|) { + push @{$json->{data}}, { + '{#VDO_VOL}' => $1 + }; + } + } +} +print to_json($json, { pretty => $pretty }) . "\n";