support getting all the value at once in a JSON structure, support VG monitoring, and various other cleanups GLPI #47654tags/zabbix-agent-addons-0.2.142-1
parent
b95cca848c
commit
bf190465bf
2 changed files with 52 additions and 28 deletions
@ -1,49 +1,72 @@ |
|||||||
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
||||||
|
|
||||||
use Zabbix::Agent::Addons::LVM; |
use Zabbix::Agent::Addons::LVM; |
||||||
|
use Getopt::Long; |
||||||
|
use JSON; |
||||||
|
|
||||||
Zabbix::Agent::Addons::LVM->units(B); |
Zabbix::Agent::Addons::LVM->units(B); |
||||||
|
|
||||||
if (@ARGV < 2){ |
my $vg = undef; |
||||||
usage(); |
my $lv = undef; |
||||||
exit(1); |
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]; |
||||||
} |
} |
||||||
|
|
||||||
my $vol = $ARGV[0]; |
if (not defined $lv and not defined $vg){ |
||||||
my $what = $ARGV[1]; |
usage(); |
||||||
|
exit 1; |
||||||
|
} |
||||||
|
|
||||||
sub usage { |
sub usage { |
||||||
print<<"EOF"; |
print<<"EOF"; |
||||||
|
|
||||||
Usage: $0 <logical volume> [size|allocation|allocation_pool_data|allocation_metadata|status] |
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 |
EOF |
||||||
} |
} |
||||||
|
|
||||||
my %info = get_lv_info($vol); |
my $json; |
||||||
|
if (defined $vg){ |
||||||
if ($what eq 'size'){ |
%{$json} = get_volume_group_information($vg); |
||||||
print $info{size}; |
} elsif (defined $lv) { |
||||||
} |
%{$json} = get_lv_info($lv); |
||||||
elsif ($what eq 'allocation'){ |
} else{ |
||||||
my $ret = (defined $info{allocated_to_snapshot}) ? $info{allocated_to_snapshot} : "ZBX_NOTSUPPORTED"; |
usage(); |
||||||
$ret =~ s/,/\./; |
|
||||||
print $ret; |
|
||||||
} |
|
||||||
elsif ($what eq 'allocation_pool_data'){ |
|
||||||
my $ret = (defined $info{allocated_pool_data}) ? $info{allocated_pool_data} : "ZBX_NOTSUPPORTED"; |
|
||||||
$ret =~ s/,/\./; |
|
||||||
print $ret; |
|
||||||
} |
} |
||||||
elsif ($what eq 'allocation_metadata'){ |
|
||||||
my $ret = (defined $info{allocated_meta_data}) ? $info{allocated_meta_data} : "ZBX_NOTSUPPORTED"; |
# Normalize float values |
||||||
$ret =~ s/,/\./; |
foreach (qw(allocated_to_snapshot allocated_pool_data allocated_meta_data)){ |
||||||
print $ret; |
$json->{$_} =~ s/,/./g if (defined $json->{$_}); |
||||||
} |
} |
||||||
elsif ($what eq 'status'){ |
# Compat with older versions |
||||||
print $info{status}; |
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}; |
||||||
} |
} |
||||||
else{ |
|
||||||
usage(); |
if (defined $what and $what ne ''){ |
||||||
|
print ((defined $json->{$what}) ? $json->{$what} : 'ZBX_NOTSUPPOTED'); |
||||||
|
} else { |
||||||
|
print to_json($json, { pretty => $pretty }); |
||||||
} |
} |
||||||
|
|
||||||
exit(0); |
exit(0); |
||||||
|
Loading…
Reference in new issue