From: Robert 'phaylon' Sedlacek Date: Thu, 3 May 2012 16:12:46 +0000 (+0000) Subject: Host probe for generic hostname/uname info X-Git-Tag: v0.001_001~134 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f473f1c2c5d7a10fa7eeef0d114df086248b7155;p=scpubgit%2FSystem-Introspector.git Host probe for generic hostname/uname info --- diff --git a/lib/System/Introspector/Host.pm b/lib/System/Introspector/Host.pm new file mode 100644 index 0000000..9b69646 --- /dev/null +++ b/lib/System/Introspector/Host.pm @@ -0,0 +1,44 @@ +package System::Introspector::Host; +use Moo; + +sub gather { + my ($self) = @_; + return { + hostname => $self->_gather_hostname, + uname => $self->_gather_uname_info, + }; +} + +my @UnameFields = qw( + kernel_name + kernel_release + kernel_version + nodename + machine + processor + hardware_platform + operating_system +); + +sub _gather_uname_info { + my ($self) = @_; + my %uname; + for my $field (@UnameFields) { + (my $option = $field) =~ s{_}{-}g; + my $value = `uname --$option`; + chomp $value; + $uname{ $field } = $value; + } + return \%uname; +} + +sub _gather_hostname { + my ($self) = @_; + open my $fh, '<', '/etc/hostname' + or die "Unable to read /etc/hostname: $!\n"; + my $hostname = <$fh>; + chomp $hostname; + return $hostname; +} + +1;