find upgradable packages and optionally update apt index
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / Host.pm
1 package System::Introspector::Probe::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     $hostname =~ s{(?:^\s+|\s+$)}{}g;
49     return $hostname;
50 }
51
52 1;
53
54 __END__
55
56 =head1 NAME
57
58 System::Introspector::Host - Gather generic host information
59
60 =head1 DESCRIPTION
61
62 Gathers 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