Better sanoïd monitoring integration
This commit is contained in:
parent
cd9ee20c02
commit
dc8bef75ed
|
@ -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
|
||||
|
|
|
@ -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=<name>|--dataset=<fs zvol or snap>|--sanoidsnap]
|
||||
$0 [--zpool=<name>|--dataset=<fs zvol or snap>|--sanoid=<snapshot|capacity|health>]
|
||||
_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+(?<read>\d+(\.\d+)?)(?<read_suffix>[KMT])?\s+(?<write>\d+(\.\d+)?)(?<write_suffix>[KMT])?\s+(?<cksum>\d+(\.\d+)?)(?<cksum_suffix>[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'});
|
||||
|
|
|
@ -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 });
|
||||
|
|
Loading…
Reference in New Issue