Puppet probe for puppet agent information
Robert 'phaylon' Sedlacek [Wed, 9 May 2012 19:36:47 +0000 (19:36 +0000)]
lib/System/Introspector/Puppet.pm [new file with mode: 0644]

diff --git a/lib/System/Introspector/Puppet.pm b/lib/System/Introspector/Puppet.pm
new file mode 100644 (file)
index 0000000..89c1197
--- /dev/null
@@ -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;