Rev 26 | Rev 37 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#!/usr/bin/env perl
use warnings;
use strict;
our $VERSION = '1.1';
# Linux disks module for sysinfo client
# Author: R. W. Rodolico
# Date: 2016-04-08
# gets information on disks and partitions. Returns them as a hash
# uses standard df -kT and parses the output
# skips anything that does not have a device with /dev in it
# assumes the structure of the output is:
# device fstype size usedSpace availableSpace percentSpace mountPoint
# however, the output can sometimes wrap to multi lines, especially if the
# device is long. So, we will replace all newlines with spaces, then
# remove space duplications, then split on spaces and process each item in
# turn.
# NOTE: this will totally break if you have spaces in your mount point
BEGIN {
push @INC, shift;
}
use library;
my $command = &validCommandOnSystem('df');
exit 1 unless $command;
my $CATEGORY = 'diskinfo';
# process physical partitions
my $temp = qx/df -kT/; # execute the system command df, returned values in kilobytes, showing file system types
my @temp = split("\n", $temp ); # get array of lines
shift @temp; # get rid of the first line . . . it is nothing but header info
$temp = join( ' ', @temp ); # rejoin everything back with spaces
$temp =~ s/ +/ /gi; # remove all duplicate spaces
@temp = split( ' ', $temp ); # turn it back into an array of space separated values
while (@temp) {
my $device = shift @temp; # get the device name
my $output = '';
$output .= "$CATEGORY\t$device\tfstype\t" . (shift @temp) . "\n"; # next is fs type
$output .= "$CATEGORY\t$device\tsize\t" . (shift @temp) . "\n"; # total partition size, in k
$output .= "$CATEGORY\t$device\tused\t" . (shift @temp) . "\n"; # disk usage, in k
shift @temp; # $available, not recorded
shift @temp; # $percent, not recorded
$output .= "$CATEGORY\t$device\tmount\t" . (shift @temp) . "\n"; # mount point
# now, if it is a /dev device, we add it to the diskInfo hash
print $output if $device =~ m/\/dev/;
}