Skip to content
Snippets Groups Projects
Commit f5eecec5 authored by Mark Harrison's avatar Mark Harrison
Browse files

Allow non-wildcard use of Core::ZpoolFree

parent 08e7243a
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,10 @@ Core::ZpoolFree - monitor free space available on ZFS pools ...@@ -19,6 +19,10 @@ Core::ZpoolFree - monitor free space available on ZFS pools
* : noop * : noop
} }
Core::ZpoolFree {
poolname : noop
}
Core::ZpoolFree { Core::ZpoolFree {
* : zfs_path => '/sbin/zfs' * : zfs_path => '/sbin/zfs'
} }
...@@ -91,6 +95,36 @@ our %units = ( ...@@ -91,6 +95,36 @@ our %units = (
'Z' => 1180591620717411303424 'Z' => 1180591620717411303424
); );
sub handler {
my $self = shift;
my $config = $self->{config}; # All configuration is in here
my $pool = $self->{check_name};
my $zfs_command = $config->{zfs_command} || "/sbin/zfs";
my $zpool_command = $config->{zpool_command} || "/sbin/zpool";
my $status = {};
# Sanity check
die "Invalid pool name: $pool" if $pool !~ /[a-zA-Z0-9_.-]+/;
my $zfs_output = run_command(
"$zfs_command list -H -o name,used,avail $pool");
my ($name, $used, $uunit, $free, $funit) = $zfs_output =~
/(\S+)\s+([0-9.]+)([BKMGTPEZ]?)\s+([0-9.]+)([BKMGTPEZ]?)/;
# Make sure we were able to match the regex
die "Unable to parse zfs command output: $zfs_output\n"
unless defined($name);
next if ($name =~ /\//); # We're only interested in the root of a pool
# Convert human readable units to bytes
$used = $used * $units{$uunit} if $uunit;
$free = $free * $units{$funit} if $funit;
my $percent_full = sprintf("%.2f", ($used / ($used + $free)) * 100);
$status->{"used_MB"} = [int($used/1048576), "i"];
$status->{"free_MB"} = [int($free/1048576), "i"];
$status->{"percent_full"} = [$percent_full, "n"];
return $status;
};
sub wildcard_handler { sub wildcard_handler {
my $self = shift; my $self = shift;
my $config = $self->{config}; # All configuration is in here my $config = $self->{config}; # All configuration is in here
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment