added base pod to all probes
[scpubgit/System-Introspector.git] / lib / System / Introspector / MountPoints.pm
1 package System::Introspector::MountPoints;
2 use Moo;
3
4 sub gather {
5     my ($self) = @_;
6     return {
7         mtab  => $self->_parse_tab_fh($self->_open_fh('/etc/mtab')),
8         fstab => $self->_parse_tab_fh($self->_open_fh('/etc/fstab')),
9     };
10 }
11
12 sub _open_fh {
13     my ($self, $file) = @_;
14     open my $fh, '<', $file
15         or die "Unable to open $file: $!\n";
16     return $fh;
17 }
18
19 sub _parse_tab_fh {
20     my ($self, $fh) = @_;
21     my @mounts;
22     while (defined( my $line = <$fh> )) {
23         chomp $line;
24         next if $line =~ m{^\s*$}
25              or $line =~ m{^\s*#};
26         my ($device, $point, $type, $opt, $dump, $pass)
27             = split m{\s+}, $line;
28         push @mounts, {
29             device_name => $device,
30             mount_point => $point,
31             fs_type     => $type,
32             dump_freq   => $dump,
33             pass_num    => $pass,
34             options     => {
35                 map {
36                     my ($name, $value) = split m{=}, $_, 2;
37                     $value = 1
38                         unless defined $value;
39                     ($name => $value);
40                 } split m{,}, $opt,
41             },
42         };
43     }
44     return \@mounts;
45 }
46
47 1;
48
49 __END__
50
51 =head1 NAME
52
53 System::Introspector::MountPoints - Gather moint point information
54
55 =head1 DESCRIPTION
56
57 Reads C<fstab> and C<mtab> files to provide mount point information.
58
59 =head1 SEE ALSO
60
61 =over
62
63 =item L<System::Introspector>
64
65 =back
66
67 =cut
68