| 55 |
rodolico |
1 |
#!/usr/bin/env perl
|
|
|
2 |
use warnings;
|
|
|
3 |
use strict;
|
|
|
4 |
|
|
|
5 |
# Description: Disk usage for BSD Unix systems
|
|
|
6 |
|
| 61 |
rodolico |
7 |
our $VERSION = '1.3';
|
| 55 |
rodolico |
8 |
|
|
|
9 |
# BSD disks module for sysinfo client
|
|
|
10 |
# Author: R. W. Rodolico
|
|
|
11 |
# Date: 2017-11-24
|
|
|
12 |
|
| 56 |
rodolico |
13 |
# gets information on disks. Returns them as a hash
|
| 55 |
rodolico |
14 |
# uses standard df -kT and parses the output
|
|
|
15 |
# skips anything that does not have a device with /dev in it
|
|
|
16 |
# assumes the structure of the output is:
|
|
|
17 |
# device fstype size usedSpace availableSpace percentSpace mountPoint
|
|
|
18 |
# however, the output can sometimes wrap to multi lines, especially if the
|
|
|
19 |
# device is long. So, we will replace all newlines with spaces, then
|
|
|
20 |
# remove space duplications, then split on spaces and process each item in
|
|
|
21 |
# turn.
|
|
|
22 |
# NOTE: this will totally break if you have spaces in your mount point
|
| 61 |
rodolico |
23 |
#
|
|
|
24 |
# v1.3 20180424 RWR
|
|
|
25 |
# Fixed bug when diskinfo generates an error. Will still send error
|
|
|
26 |
# to STDERR, but will not break program.
|
| 55 |
rodolico |
27 |
|
|
|
28 |
BEGIN {
|
|
|
29 |
push @INC, shift;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
use library;
|
|
|
33 |
|
| 197 |
rodolico |
34 |
exit 1 unless &getOperatingSystem() =~ m/bsd/i;
|
|
|
35 |
|
| 55 |
rodolico |
36 |
# the commands this script will use
|
|
|
37 |
my %commands = (
|
|
|
38 |
'sysctl' => ''
|
|
|
39 |
);
|
|
|
40 |
|
|
|
41 |
# check the commands for validity
|
|
|
42 |
foreach my $command ( keys %commands ) {
|
|
|
43 |
$commands{$command} = &validCommandOnSystem( $command );
|
|
|
44 |
}
|
|
|
45 |
|
| 57 |
rodolico |
46 |
exit 1 unless $commands{'sysctl'};
|
| 56 |
rodolico |
47 |
|
|
|
48 |
my $temp;
|
|
|
49 |
my $device;
|
|
|
50 |
my @temp;
|
|
|
51 |
my $CATEGORY = 'diskinfo';
|
| 55 |
rodolico |
52 |
|
| 56 |
rodolico |
53 |
|
| 55 |
rodolico |
54 |
$temp = getSysctlParameter( $commands{ 'sysctl' }, 'kern.disks' );
|
|
|
55 |
my @disks = split( /\s+/, $temp );
|
| 56 |
rodolico |
56 |
foreach $device ( @disks ) {
|
| 61 |
rodolico |
57 |
next unless eval { $temp = qx( diskinfo $device ); };
|
| 55 |
rodolico |
58 |
chomp $temp;
|
|
|
59 |
my @info = split( /\s+/, $temp );
|
|
|
60 |
$temp = $info[2] / 1024;
|
| 56 |
rodolico |
61 |
print "$CATEGORY\t/dev/$device\tsize\t$temp\n";
|
| 55 |
rodolico |
62 |
}
|
|
|
63 |
|