diff --git a/zabbix_conf/zfs.conf b/zabbix_conf/zfs.conf new file mode 100644 index 0000000..a347bae --- /dev/null +++ b/zabbix_conf/zfs.conf @@ -0,0 +1,13 @@ +# Discover ZFS zpools +# $1 not used for now +UserParameter=vfs.zfs.discovery[*],/var/lib/zabbix/bin/disco_zfs + +# Type: Agent or Agent (active) +# Key: vfs.zfs.zpool[pool,item] where pool is the name of the zpool to monitor +# item can be one of size, alloc, frag, cap, dedup, health +UserParameter=vfs.zfs.zpool[*],/var/lib/zabbix/bin/check_zfs --zpool=$1 --what=$2 + +# Type: Agent or Agent (active) +# You can also get all the info about a zpool at once, in JSON +UserParameter=vfs.zfs.zpool.all[*],/var/lib/zabbix/bin/check_zfs --zpool=$1 + diff --git a/zabbix_scripts/check_zfs b/zabbix_scripts/check_zfs new file mode 100644 index 0000000..791b70d --- /dev/null +++ b/zabbix_scripts/check_zfs @@ -0,0 +1,47 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use JSON; +use File::Which; +use Getopt::Long; + +my $json = {}; +my $pool = undef; +my $what = undef; + +GetOptions( + "zpool|pool=s" => \$pool, + "what=s" => \$what +); + +my $zpool = which('zpool'); + +if ($what and !$pool){ + print <<_EOF; +Usage: +$0 [--zpool=] [--what=] + + is an optional zpool name. If specified, will only output info for this zpool. + is one of size, alloc, frag, cap, dedup, health and if specified, will only output the corresponding value +If --what is specified then --zpool is mandatory. +The default (with no option) is to output all the info of all the zpool in a JSON format +_EOF + exit 1; +} + +if ($zpool){ + my $cmd = "$zpool list -H" . ( ($pool) ? " $pool" : ""); + foreach (qx($cmd)){ + #NAME SIZE ALLOC FREE EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT + #rpool 464G 7.49G 457G - 2% 1% 1.00x ONLINE - + if (m/^(?\w+)\s+(?\d+(\.\d+)?)[MGT]\s+(?\d+(\.\d+)?)[MGT]\s+.+\s+(?\d+(\.\d+)?)%\s+(?\d+(\.\d+)?)%\s+(?\d+(\.\d+)?)x\s+(?\w+)/){ + $json->{$+{pool}}->{$_} = $+{$_} foreach (grep { $_ ne 'pool' } keys %+); + } + } +} +if ($what){ + print ((defined $json->{$pool}->{$what}) ? $json->{$pool}->{$what} : 'ZBX_UNSUPORTED'); +} else{ + print to_json($json); +} diff --git a/zabbix_scripts/disco_zfs b/zabbix_scripts/disco_zfs new file mode 100644 index 0000000..f9d0ce2 --- /dev/null +++ b/zabbix_scripts/disco_zfs @@ -0,0 +1,18 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use JSON; +use File::Which; + +my $json; +@{$json->{data}} = (); +my $zpool = which('zpool'); + +if ($zpool){ + foreach (qx($zpool list -H -o name)){ + chomp; + push @{$json->{data}}, { ZPOOL => $_ }; + } +} +print to_json($json);