Fix disco_lvm_sudo when there's no VG at all

It was returning an empty string, which is not expected by Zabbix Server, so the item was marked as unsupported. It's now returning an empty JSON list
tags/zabbix-agent-addons-0.2.20-1
Daniel Berteaud 8 years ago
parent a30233bf33
commit c99874dd2d
  1. 35
      zabbix_scripts/disco_lvm_sudo

@ -10,17 +10,20 @@ open STDERR, '>/dev/null';
my $json; my $json;
@{$json->{data}} = (); @{$json->{data}} = ();
if ($what eq "volumes"){ my @vg = eval { get_volume_group_list() };
foreach my $group (get_volume_group_list()){
unless ($@){
if ($what eq "volumes"){
foreach my $group (@vg){
my %lvs = get_logical_volume_information($group); my %lvs = get_logical_volume_information($group);
foreach my $lv (keys %lvs){ foreach my $lv (keys %lvs){
$lv = ($lv =~ m!^/dev/$group!) ? $lv : "/dev/$group/$lv"; $lv = ($lv =~ m!^/dev/$group!) ? $lv : "/dev/$group/$lv";
push @{$json->{data}}, { "{#LVMVOL}" => "$lv" }; push @{$json->{data}}, { "{#LVMVOL}" => "$lv" };
} }
} }
} }
elsif ($what eq "snapshots"){ elsif ($what eq "snapshots"){
foreach my $group (get_volume_group_list()){ foreach my $group (@vg){
my %lvs = get_logical_volume_information($group); my %lvs = get_logical_volume_information($group);
foreach my $lv (keys %lvs){ foreach my $lv (keys %lvs){
if (defined $lvs{$lv}->{allocated_to_snapshot}){ if (defined $lvs{$lv}->{allocated_to_snapshot}){
@ -29,9 +32,9 @@ elsif ($what eq "snapshots"){
} }
} }
} }
} }
elsif ($what eq "thin_pools"){ elsif ($what eq "thin_pools"){
foreach my $group (get_volume_group_list()){ foreach my $group (@vg){
my %lvs = get_logical_volume_information($group); my %lvs = get_logical_volume_information($group);
foreach my $lv (keys %lvs){ foreach my $lv (keys %lvs){
if (defined $lvs{$lv}->{allocated_pool_data}){ if (defined $lvs{$lv}->{allocated_pool_data}){
@ -40,19 +43,19 @@ elsif ($what eq "thin_pools"){
} }
} }
} }
}
elsif ($what eq "groups"){
foreach my $group (get_volume_group_list()){
push @{$json->{data}}, { "{#LVMGRP}" => $group };
} }
} elsif ($what eq "groups"){
else{ foreach my $group (@vg){
push @{$json->{data}}, { "{#LVMGRP}" => $group }; }
}
else{
print <<"EOF"; print <<"EOF";
Usage: $0 [volumes|snapshots|groups] Usage: $0 [volumes|snapshots|thin_pools|groups]
EOF EOF
exit 1;
}
} }
print to_json($json); print to_json($json);
exit(0); exit(0);

Loading…
Cancel
Save