Subversion Repositories camp_sysinfo_client_3

Rev

Rev 197 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
251 rodolico 28
# find our location and use it for searching for libraries
55 rodolico 29
BEGIN {
251 rodolico 30
   use FindBin;
31
   use File::Spec;
32
   use lib File::Spec->catdir($FindBin::Bin);
33
   eval( 'use library;' ); die "Could not find library.pm in the code directory\n" if $@;
34
   eval( 'use Data::Dumper;' );
55 rodolico 35
}
36
 
251 rodolico 37
# check for valid OS. 
38
exit 1 unless &checkOS( { 'freebsd' => undef } );
55 rodolico 39
 
251 rodolico 40
# check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
41
# script returns a 2
42
foreach my $command ( 'sysctl' ) {
43
   exit 2 unless &validCommandOnSystem( $command );
44
}
197 rodolico 45
 
55 rodolico 46
 
56 rodolico 47
my $temp;
48
my $device;
49
my @temp;
50
my $CATEGORY = 'diskinfo';
55 rodolico 51
 
56 rodolico 52
 
251 rodolico 53
$temp = getSysctlParameter( 'sysctl', 'kern.disks' );
55 rodolico 54
my @disks =  split( /\s+/, $temp );
56 rodolico 55
foreach $device ( @disks ) {
61 rodolico 56
   next unless eval { $temp = qx( diskinfo $device ); };
55 rodolico 57
   chomp $temp;
58
   my @info =  split( /\s+/, $temp );
59
   $temp = $info[2] / 1024;
56 rodolico 60
   print "$CATEGORY\t/dev/$device\tsize\t$temp\n";
55 rodolico 61
}
62