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