|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use Zabbix::Agent::Addons::LVM;
|
|
|
|
use Getopt::Long;
|
|
|
|
use JSON;
|
|
|
|
|
|
|
|
Zabbix::Agent::Addons::LVM->units(B);
|
|
|
|
|
|
|
|
my $vg = undef;
|
|
|
|
my $lv = undef;
|
|
|
|
my $what = undef;
|
|
|
|
my $pretty = 0;
|
|
|
|
|
|
|
|
GetOptions(
|
|
|
|
'vg=s' => \$vg,
|
|
|
|
'lv=s' => \$lv,
|
|
|
|
'what:s' => \$what,
|
|
|
|
"pretty" => \$pretty
|
|
|
|
);
|
|
|
|
|
|
|
|
if (not defined $lv and not defined $vg){
|
|
|
|
$lv ||= $ARGV[0];
|
|
|
|
$what ||= $ARGV[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not defined $lv and not defined $vg){
|
|
|
|
usage();
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
print<<"EOF";
|
|
|
|
|
|
|
|
Usage: $0 <logical volume> [size|allocation|allocation_pool_data|allocation_metadata|status]
|
|
|
|
$0 --lv=<logical volume>
|
|
|
|
$0 --lv=<logical volume> --what=<size|allocation|allocation_pool_data|allocation_metadata|status|etc.>
|
|
|
|
$0 --vg=<volume group>
|
|
|
|
$0 --vg=<volume group> --what=<alloc_pe_size|vg_size|etc.>
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
my $json;
|
|
|
|
if (defined $vg){
|
|
|
|
%{$json} = get_volume_group_information($vg);
|
|
|
|
} elsif (defined $lv) {
|
|
|
|
%{$json} = get_lv_info($lv);
|
|
|
|
} else{
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
# Normalize float values
|
|
|
|
foreach (qw(allocated_to_snapshot allocated_pool_data allocated_meta_data)){
|
|
|
|
$json->{$_} =~ s/,/./g if (defined $json->{$_});
|
|
|
|
}
|
|
|
|
# Compat with older versions
|
|
|
|
my $old_keys = {
|
|
|
|
allocation => 'allocated_to_snapshot',
|
|
|
|
allocation_pool_data => 'allocated_pool_data',
|
|
|
|
allocation_metadata => 'allocated_meta_data'
|
|
|
|
};
|
|
|
|
if (defined $what && defined $old_keys->{$what}){
|
|
|
|
$what = $old_keys->{$what};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $what and $what ne ''){
|
|
|
|
print ((defined $json->{$what}) ? $json->{$what} : 'ZBX_NOTSUPPOTED');
|
|
|
|
} else {
|
|
|
|
print to_json($json, { pretty => $pretty });
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|