Puppet probe base pod
[scpubgit/System-Introspector.git] / lib / System / Introspector / Puppet.pm
1 package System::Introspector::Puppet;
2 use Moo;
3
4 has classes_file => (
5     is      => 'ro',
6     default => sub { '/var/lib/puppet/state/classes.txt' },
7 );
8
9 has resources_file => (
10     is      => 'ro',
11     default => sub { '/var/lib/puppet/state/resources.txt' },
12 );
13
14 sub gather {
15     my ($self) = @_;
16     return {
17         classes     => $self->_gather_classes,
18         resources   => $self->_gather_resources,
19     };
20 }
21
22 sub _gather_resources {
23     my ($self) = @_;
24     my $file = $self->resources_file;
25     open my $fh, '<', $file
26         or return { error => "Unable to read $file: $!" };
27     my @lines = <$fh>;
28     chomp @lines;
29     return [ map {
30         m{^(\w+)\[(.*)\]$}
31             ? [$1, $2]
32             : [error => $_];
33     } @lines ];
34 }
35
36 sub _gather_classes {
37     my ($self) = @_;
38     my $file = $self->classes_file;
39     open my $fh, '<', $file
40         or return { error => "Unable to read $file: $!" };
41     my @lines = <$fh>;
42     chomp @lines;
43     return \@lines;
44 }
45
46 1;
47
48 __END__
49
50 =head1 NAME
51
52 System::Introspector::Puppet - Gather puppet agent information
53
54 =head1 DESCRIPTION
55
56 Reads the C<classes.txt> and C<resources.txt> provided by puppet.
57
58 =head1 ATTRIBUTES
59
60 =head2 classes_file
61
62 The path to the C<classes.txt> puppet file.
63 Defaults to C</var/lib/puppet/state/classes.txt>.
64
65 =head2 resources_file
66
67 The path to the C<resources.txt> puppet file.
68 Defaults to C</var/lib/puppet/state/resources.txt>.
69
70 =head1 SEE ALSO
71
72 =over
73
74 =item L<System::Introspector>
75
76 =back
77
78 =cut