added base pod to all probes
[scpubgit/System-Introspector.git] / lib / System / Introspector / Host.pm
CommitLineData
f473f1c2 1package System::Introspector::Host;
2use Moo;
3
4sub gather {
5 my ($self) = @_;
6 return {
7 hostname => $self->_gather_hostname,
8 uname => $self->_gather_uname_info,
9 };
10}
11
12my @UnameFields = qw(
13 kernel_name
14 kernel_release
15 kernel_version
16 nodename
17 machine
18 processor
19 hardware_platform
20 operating_system
21);
22
23sub _gather_uname_info {
24 my ($self) = @_;
25 my %uname;
26 for my $field (@UnameFields) {
27 (my $option = $field) =~ s{_}{-}g;
28 my $value = `uname --$option`;
29 chomp $value;
30 $uname{ $field } = $value;
31 }
32 return \%uname;
33}
34
35sub _gather_hostname {
36 my ($self) = @_;
37 open my $fh, '<', '/etc/hostname'
38 or die "Unable to read /etc/hostname: $!\n";
39 my $hostname = <$fh>;
40 chomp $hostname;
41 return $hostname;
42}
43
441;
535e84b6 45
46__END__
47
48=head1 NAME
49
50System::Introspector::Host - Gather generic host information
51
52=head1 DESCRIPTION
53
54Gathers the hostname and information provided by C<uname>.
55
56=head1 SEE ALSO
57
58=over
59
60=item L<System::Introspector>
61
62=back
63
64=cut
65