simulated lsof
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / Host.pm
CommitLineData
afd7c030 1package System::Introspector::Probe::Host;
f473f1c2 2use Moo;
3
07a2389f 4use System::Introspector::Util qw(
5 handle_from_command
6 output_from_command
7 output_from_file
8 transform_exceptions
9);
10
f473f1c2 11sub gather {
12 my ($self) = @_;
07a2389f 13 return transform_exceptions {
14 return {
15 hostname => $self->_gather_hostname,
16 uname => $self->_gather_uname_info,
17 };
f473f1c2 18 };
19}
20
21my @UnameFields = qw(
22 kernel_name
23 kernel_release
24 kernel_version
25 nodename
26 machine
27 processor
28 hardware_platform
29 operating_system
30);
31
32sub _gather_uname_info {
33 my ($self) = @_;
34 my %uname;
35 for my $field (@UnameFields) {
36 (my $option = $field) =~ s{_}{-}g;
07a2389f 37 my $value = output_from_command [uname => "--$option"];
f473f1c2 38 chomp $value;
39 $uname{ $field } = $value;
40 }
41 return \%uname;
42}
43
44sub _gather_hostname {
45 my ($self) = @_;
07a2389f 46 my $hostname = output_from_file '/etc/hostname';
f473f1c2 47 chomp $hostname;
97d232ad 48 $hostname =~ s{(?:^\s+|\s+$)}{}g;
f473f1c2 49 return $hostname;
50}
51
521;
535e84b6 53
54__END__
55
56=head1 NAME
57
58System::Introspector::Host - Gather generic host information
59
60=head1 DESCRIPTION
61
62Gathers the hostname and information provided by C<uname>.
63
64=head1 SEE ALSO
65
66=over
67
68=item L<System::Introspector>
69
70=back
71
72=cut
73