| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 45 | 0 | ▶ | print $f $output or croak("cannot write to pipe: $!"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | ▶ | close($f) or croak("cannot close $cf"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ||||||||||