diff --git a/zabbix_conf/zfs.conf b/zabbix_conf/zfs.conf index ffa3836..6e7074a 100644 --- a/zabbix_conf/zfs.conf +++ b/zabbix_conf/zfs.conf @@ -9,3 +9,7 @@ UserParameter=vfs.zfs.zpool.info[*],/var/lib/zabbix/bin/check_zfs --zpool=$1 # Type: Agent or Agent (active) # FS, Zvol or Snap info in JSON UserParameter=vfs.zfs.dataset.info[*],/var/lib/zabbix/bin/check_zfs --dataset=$1 + +# Type: Agent or Agent (active) +# Sanoïd snapshot monitoring +UserParameter=vfs.zfs.sanoid.check[*],/var/lib/zabbix/bin/check_zfs --sanoid=$1 diff --git a/zabbix_scripts/check_zfs b/zabbix_scripts/check_zfs index 6e7b2df..071bfee 100644 --- a/zabbix_scripts/check_zfs +++ b/zabbix_scripts/check_zfs @@ -9,13 +9,13 @@ use Getopt::Long; my $json = {}; my $pool = undef; my $dataset = undef; -my $sanoidsnap = undef; +my $sanoidmon = undef; my $pretty = 0; GetOptions( "zpool|pool=s" => \$pool, "dataset=s" => \$dataset, - "sanoidsnap" => \$sanoidsnap, + "sanoid=s" => \$sanoidmon, "pretty" => \$pretty ); @@ -27,14 +27,17 @@ if (not $zpool or not $zfs){ print 'ZBX_NOTSUPPOTED'; exit 0; } -if ($sanoidsnap and not $sanoid){ +if ($sanoidmon and not $sanoid){ + die 'ZBX_NOTSUPPOTED'; +} +if (not grep { $_ eq $sanoidmon } qw(snapshot capacity health)){ die 'ZBX_NOTSUPPOTED'; } -if (not $pool and not $dataset and not $sanoidsnap){ +if (not $pool and not $dataset and not $sanoidmon){ print <<_EOF; Usage: -$0 [--zpool=|--dataset=|--sanoidsnap] +$0 [--zpool=|--dataset=|--sanoid=] _EOF exit 1; } @@ -68,9 +71,9 @@ if ($pool){ $json->{$parse[1]} =~ s/x$//; } } -} elsif ($sanoidsnap){ - print qx($sanoid --monitor-snapshot); - exit 0; +} elsif ($sanoidmon){ + print qx($sanoid --monitor-$sanoidmon); + exit $?; } print to_json($json, { pretty => $pretty }) . "\n"; @@ -116,6 +119,8 @@ sub get_zpool_errors { $errors->{$index->{$i-1}} .= $line; } elsif ($line =~ m/\s+[a-zA-Z0-9_\-]+\s+[A-Z]+\s+(?\d+(\.\d+)?)(?[KMT])?\s+(?\d+(\.\d+)?)(?[KMT])?\s+(?\d+(\.\d+)?)(?[KMT])?/){ # And here, we count the number of read, write and checksum errors + # Note that on ZoL 0.8.0 we could use zpool status -p to get rid of the suffixes + # But -p is not supported on 0.7 and earlier, so, we just convert them manually $errors->{read_errors} += convert_suffix($+{'read'},$+{'read_suffix'}); $errors->{write_errors} += convert_suffix($+{'write'},$+{'write_suffix'}); $errors->{cksum_errors} += convert_suffix($+{'write'},$+{'write_suffix'}); diff --git a/zabbix_scripts/disco_zfs b/zabbix_scripts/disco_zfs index 3685b10..7d9819c 100644 --- a/zabbix_scripts/disco_zfs +++ b/zabbix_scripts/disco_zfs @@ -21,7 +21,7 @@ my $pools = 1; my $fs = 0; my $zvol = 0; my $snap = 0; -my $sanoidsnap = 0; +my $sanoidmon = 0; my $pretty = 0; GetOptions( @@ -29,17 +29,17 @@ GetOptions( "fs|filesystems" => \$fs, "zvols|volumes" => \$zvol, "snapshots" => \$snap, - "sanoidsnap" => \$sanoidsnap, + "sanoid" => \$sanoidmon, "pretty" => \$pretty ); if ($fs or $zvol or $snap or $sanoidsnap){ $pools = 0; } -if ($pools + $fs + $zvol + $snap + $sanoidsnap != 1){ +if ($pools + $fs + $zvol + $snap + $sanoidmon != 1){ die "One and only one type of discovery should be provided\n"; } -if ($sanoidsnap and not $sanoid){ +if ($sanoidmon and not $sanoid){ print to_json($json); exit 0; } @@ -67,7 +67,7 @@ if ($pools){ $_ =~ s/\@/%40/g; push @{$json->{data}}, { '{#ZFS_SNAP}' => $_ }; } -} elsif ($sanoidsnap){ - push @{$json->{data}}, { '{#ZFS_SANOID}' => 1 }; +} elsif ($sanoidmon){ + push @{$json->{data}}, { '{#ZFS_SANOID}' => $_ } foreach (qw(snapshot capacity health)); } print to_json($json, { pretty => $pretty });