top level resolv_conf/error value
[scpubgit/System-Introspector.git] / lib / System / Introspector / Host.pm
1 package System::Introspector::Host;
2 use Moo;
3
4 use System::Introspector::Util qw(
5     handle_from_command
6     output_from_command
7     output_from_file
8     transform_exceptions
9 );
10
11 sub gather {
12     my ($self) = @_;
13     return transform_exceptions {
14         return {
15             hostname => $self->_gather_hostname,
16             uname    => $self->_gather_uname_info,
17         };
18     };
19 }
20
21 my @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
32 sub _gather_uname_info {
33     my ($self) = @_;
34     my %uname;
35     for my $field (@UnameFields) {
36         (my $option = $field) =~ s{_}{-}g;
37         my $value = output_from_command [uname => "--$option"];
38         chomp $value;
39         $uname{ $field } = $value;
40     }
41     return \%uname;
42 }
43
44 sub _gather_hostname {
45     my ($self) = @_;
46     my $hostname = output_from_file '/etc/hostname';
47     chomp $hostname;
48     return $hostname;
49 }
50
51 1;
52
53 __END__
54
55 =head1 NAME
56
57 System::Introspector::Host - Gather generic host information
58
59 =head1 DESCRIPTION
60
61 Gathers the hostname and information provided by C<uname>.
62
63 =head1 SEE ALSO
64
65 =over
66
67 =item L<System::Introspector>
68
69 =back
70
71 =cut
72