From 420bb936b32c25667bceee363764ed2dca2856cd Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 29 May 2018 12:20:07 +0200 Subject: [PATCH] Handle situations where there's more than 1000 errors on a item in ZFS pools --- zabbix_scripts/check_zfs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/zabbix_scripts/check_zfs b/zabbix_scripts/check_zfs index 5acc5c6..356ea83 100644 --- a/zabbix_scripts/check_zfs +++ b/zabbix_scripts/check_zfs @@ -88,13 +88,29 @@ sub get_zpool_errors { chomp($line); $line =~ s/\s+/ /g; $errors->{$index->{$i-1}} .= $line; - } elsif ($line =~ m/\s+[a-zA-Z0-9_\-]+\s+[A-Z]+\s+(\d+)\s+(\d+)\s+(\d+)/){ + } 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 - $errors->{read_errors} += $1; - $errors->{write_errors} += $2; - $errors->{cksum_errors} += $3; + $errors->{read_errors} += convert_suffix($+{'read'},$+{'read_suffix'}); + $errors->{write_errors} += convert_suffix($+{'write'},$+{'write_suffix'}); + $errors->{cksum_errors} += convert_suffix($+{'cksum'},$+{'cksum_suffix'}); } $i++; } return $errors; } + +# Error counter can be suffixed. Apply this suffix to get raw error numbers +sub convert_suffix { + my $val = shift; + my $suf = shift; + if (!$suf){ + return $val; + } elsif ($suf eq 'K'){ + $val *= 1000; + } elsif ($suf eq 'M') { + $val *= 1000000; + } elsif ($suf eq 'T') { + $val *= 1000000000; + } + return $val; +}