From: Robert 'phaylon' Sedlacek Date: Wed, 9 May 2012 19:36:47 +0000 (+0000) Subject: Puppet probe for puppet agent information X-Git-Tag: v0.001_001~108 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=660adc3aef9afc833b78040d049bfed470286ea5;p=scpubgit%2FSystem-Introspector.git Puppet probe for puppet agent information --- diff --git a/lib/System/Introspector/Puppet.pm b/lib/System/Introspector/Puppet.pm new file mode 100644 index 0000000..89c1197 --- /dev/null +++ b/lib/System/Introspector/Puppet.pm @@ -0,0 +1,46 @@ +package System::Introspector::Puppet; +use Moo; + +has classes_file => ( + is => 'ro', + default => sub { '/var/lib/puppet/state/classes.txt' }, +); + +has resources_file => ( + is => 'ro', + default => sub { '/var/lib/puppet/state/resources.txt' }, +); + +sub gather { + my ($self) = @_; + return { + classes => $self->_gather_classes, + resources => $self->_gather_resources, + }; +} + +sub _gather_resources { + my ($self) = @_; + my $file = $self->resources_file; + open my $fh, '<', $file + or return { error => "Unable to read $file: $!" }; + my @lines = <$fh>; + chomp @lines; + return [ map { + m{^(\w+)\[(.*)\]$} + ? [$1, $2] + : [error => $_]; + } @lines ]; +} + +sub _gather_classes { + my ($self) = @_; + my $file = $self->classes_file; + open my $fh, '<', $file + or return { error => "Unable to read $file: $!" }; + my @lines = <$fh>; + chomp @lines; + return \@lines; +} + +1;