use reusable I/O utils, more solid error handling for Nagios::CheckMkAgent probe
[scpubgit/System-Introspector.git] / lib / System / Introspector / Nagios / CheckMkAgent.pm
1 package System::Introspector::Nagios::CheckMkAgent;
2 use Moo;
3
4 use System::Introspector::Util qw(
5     lines_from_command
6     transform_exceptions
7 );
8
9 sub gather {
10     my ($self) = @_;
11     return transform_exceptions {
12         my @lines = $self->_get_check_mk_agent_output;
13         chomp @lines;
14         my %plugin;
15         my $current;
16         for my $line (@lines) {
17             if ($line =~ m{^<<<(.+)>>>$}) {
18                 $plugin{ $1 } = $current = [];
19                 next;
20             }
21             next unless $current;
22             push @$current, $line;
23         }
24         return { nagios_check_mk_agent => \%plugin };
25     };
26 }
27
28 sub _get_check_mk_agent_output {
29     return lines_from_command ['check_mk_agent'];
30 }
31
32 1;
33
34 __END__
35
36 =head1 NAME
37
38 System::Introspector::Nagios::CheckMkAgent - Gather check_mk_agent output
39
40 =head1 DESCRIPTION
41
42 Parses the output of C<check_mk_agent> to gather data available to Nagios.
43
44 =head1 SEE ALSO
45
46 =over
47
48 =item L<System::Introspector>
49
50 =back
51
52 =cut
53
54