package System::Introspector::Nagios::CheckMkAgent;
use Moo;
+use System::Introspector::Util qw(
+ lines_from_command
+ transform_exceptions
+);
+
sub gather {
my ($self) = @_;
- my @lines = $self->_get_check_mk_agent_output;
- chomp @lines;
- my %plugin;
- my $current;
- for my $line (@lines) {
- if ($line =~ m{^<<<(.+)>>>$}) {
- $plugin{ $1 } = $current = [];
- next;
+ return transform_exceptions {
+ my @lines = $self->_get_check_mk_agent_output;
+ chomp @lines;
+ my %plugin;
+ my $current;
+ for my $line (@lines) {
+ if ($line =~ m{^<<<(.+)>>>$}) {
+ $plugin{ $1 } = $current = [];
+ next;
+ }
+ next unless $current;
+ push @$current, $line;
}
- next unless $current;
- push @$current, $line;
- }
- return \%plugin;
+ return { nagios_check_mk_agent => \%plugin };
+ };
}
sub _get_check_mk_agent_output {
- return `check_mk_agent`;
+ return lines_from_command ['check_mk_agent'];
}
1;
my $data = $probe->gather;
is_deeply $data,
- { foo => [qw( bar baz )], bar => [], baz => [qw( qux )] },
+ { nagios_check_mk_agent => {
+ foo => [qw( bar baz )],
+ bar => [],
+ baz => [qw( qux )],
+ } },
'output parsing worked';
done_testing;