blib/lib/Nagios/Passive/CommandFile.pm

filter: Statementstmt 52.9% 18 / 34 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 3 totaltotal 41.0% 23 / 56 CC 7 SCAR 25.8
CC
7
Cov
39%
submit
30.0
to_string
6.0
BUILD
2.9
CRAP 13.2
↑ Summary blib/lib/Nagios/Passive/BulkResult.pm »
1 package Nagios::Passive::CommandFile;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 extends 'Nagios::Passive::Base';
8  
9 1 has 'command_file'=>(
10 is => 'ro',
11 isa => 'Str',
12 predicate=>'has_command_file'
13 );
14  
15 sub BUILD {
16 1 ▶ my $self = shift;
Subroutine BUILD: called CC=2 SCAR=10.5
Pod undocumented
17 1 my $cf = $self->command_file;
18 0 ▶ croak("$cf is not a named pipe") unless (-p $cf);
Branch: 1 branch
BranchTrueFalseTotal
unless -p $cf 0 0 0
19 };
20  
21 sub to_string {
22 0 ▶ my $s = shift;
Subroutine to_string: not called CC=2 SCAR=17.9
Pod undocumented
23 0 my $output;
24 0 ▶ if(defined $s->service_description) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->service_description) { } 0 0 0
25 0 $output = sprintf "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s %s - %s\n",
26 $s->time, $s->host_name, $s->service_description, $s->return_code,
27 $s->check_name, $s->_status_code, $s->_quoted_output;
28 } else {
29 0 $output = sprintf "[%d] PROCESS_HOST_CHECK_RESULT;%s;%d;%s %s - %s\n",
30 $s->time, $s->host_name, $s->return_code,
31 $s->check_name, $s->_status_code, $s->_quoted_output;
32 }
33 0 return $output;
34 }
35  
36 sub submit {
37 0 ▶ my $s = shift;
Subroutine submit: not called CC=5 SCAR=34.0
Pod undocumented
38 0 ▶ croak("no external_command_file given") unless $s->has_command_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $s->has_command_file 0 0 0
39 0 my $cf = $s->command_file;
40 0 my $output = $s->to_string;
41  
42 # I hope this is the correct way to deal with named pipes
43 0 local $SIG{PIPE} = 'IGNORE';
44 0 ▶ open(my $f, ">>", $cf) or croak("cannot open $cf: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $f, ">>", $cf or croak("cannot open ${cf}: $!") 0 0 0
45 0 ▶ print $f $output or croak("cannot write to pipe: $!");
Branch: 1 branch
BranchTrueFalseTotal
print $f $output or croak("cannot write to pipe: $!") 0 0 0
46 0 ▶ close($f) or croak("cannot close $cf");
Branch: 1 branch
BranchTrueFalseTotal
close $f or croak("cannot close $cf") 0 0 0
47 0 return length($output);
48 }
49  
50 2 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 __PACKAGE__->meta->make_immutable;
52 1 1;
53 __END__
54  
55 =head1 NAME
56  
57 Nagios::Passive::CommandFile - drop check results into Nagios' check_result_path.
58  
59 =head1 SYNOPSIS
60  
61 my $nw = Nagios::Passive->create(
62 command_file => $checkresultsdir,
63 service_description => $service_description,
64 check_name => $check_name,
65 host_name => $hostname,
66 return_code => 0, # 1 2 3
67 output => 'looks (good|bad|horrible) | performancedata'
68 );
69 $nw->submit;
70  
71 =head1 DESCRIPTION
72  
73 This module gives you the ability to drop checkresults into
74 Nagios' external_command_file.
75  
76 The usage is described in L<Nagios::Passive>
77  
78 =cut
↑ Summary blib/lib/Nagios/Passive/BulkResult.pm »