Skip block devices with a 0 size, and return the size for each block device

tags/zabbix-agent-addons-0.2.20-1
Daniel Berteaud 12 years ago
parent f88be7264b
commit 3ce2c063d9
  1. 10
      zabbix_scripts/disco_block_devices

@ -8,6 +8,7 @@ closedir($dh);
my $json; my $json;
foreach my $block (@blocks){ foreach my $block (@blocks){
my $removable = 0; my $removable = 0;
my $size = 1;
if ( -e "/sys/block/$block/removable"){ if ( -e "/sys/block/$block/removable"){
open REMOVABLE, "/sys/block/$block/removable"; open REMOVABLE, "/sys/block/$block/removable";
$removable = join "", <REMOVABLE>; $removable = join "", <REMOVABLE>;
@ -15,8 +16,15 @@ foreach my $block (@blocks){
chomp($removable); chomp($removable);
next if ($removable eq '1'); next if ($removable eq '1');
} }
if ( -e "/sys/block/$block/size"){
open SIZE, "/sys/block/$block/size";
$size = join "", <SIZE>;
close SIZE;
chomp($size);
next if ($size eq '0');
}
my $dev = '/dev/' . $block; my $dev = '/dev/' . $block;
push @{$json->{data}}, { "{#BLOCKDEVICE}" => $dev }; push @{$json->{data}}, { "{#BLOCKDEVICE}" => $dev, "{#BLOCKSIZE}" => $size };
} }
print to_json($json); print to_json($json);
exit(0); exit(0);

Loading…
Cancel
Save