App-MultiModule-Tasks-NagiosCmd

 view release on metacpan or  search on metacpan

lib/App/MultiModule/Tasks/NagiosCmd.pm  view on Meta::CPAN

            dropped_message => $nagios_commands->[0]
        );
        shift @{$nagios_commands};
    }
}

sub _write_tick {
    my $self = shift;
    my $nagios_commands = $self->{state}->{nagios_commands};
    return unless scalar @$nagios_commands; #no work
    if(my $command_file_err = _validate_command_file($self->{state}->{command_file})) {
        $self->error("App::MultiModule::Tasks::NagiosCmd::_write_tick: $command_file_err");
        return;
    }
    WHILE:
    while($nagios_commands->[0]) {
        my $cmd = $nagios_commands->[0];
        eval {
            local $SIG{ALRM} = sub { die "timed out\n"; };
            alarm 5;
            my $np = Nagios::Passive->create(

lib/App/MultiModule/Tasks/NagiosCmd.pm  view on Meta::CPAN

        if($@) {
            $self->error("App::MultiModule::Tasks::NagiosCmd::_write_tick: failed: $@", cmd => $cmd);
            print STDERR "NagiosCmd: _write_tick: \$err=$@\n";
            last WHILE;
        }
        $self->_cmd_log($cmd);
        shift @$nagios_commands;
    }
}

sub _validate_command_file {    #return false means good
                                #true return is the text of the problem
    my $command_file = shift;

    my $ret = eval {
        local $SIG{ALRM} = sub { die "timed out\n"; };
        alarm 2;
        return "command_file $command_file does not exist"
            unless -e $command_file;
        return "command_file $command_file is not writable"
            unless -w $command_file;
        return "command_file $command_file is not of file type pipe"
            unless -p $command_file;
        return 0;
    };
    alarm 0;
    return "command_file $command_file _validate_command_file exception: $@"
        if $@;
    return $ret;
}

sub _cmd_log {
    my $self = shift;
    my $config = $self->{config};
    my $cmd = shift;
    my $logfile = $config->{cmd_log} || 'nagios_cmd.log';
    eval {

lib/App/MultiModule/Tasks/NagiosCmd.pm  view on Meta::CPAN

    my $self = shift;
    my $config = shift;
    $self->{config} = $config;
    $self->{state} = {} unless $self->{state};
    $self->{state}->{nagios_commands} = []
        unless $self->{state}->{nagios_commands};
    if(not $self->{config}->{command_file}) {
        $self->error("App::MultiModule::Tasks::NagiosCmd::set_config: required config 'command_file' not found");
        return;
    }
    if(my $command_file_err = _validate_command_file($self->{config}->{command_file})) {
        $self->error("App::MultiModule::Tasks::NagiosCmd::set_config: $command_file_err");
        return;
    }
    $self->{state}->{command_file} = $self->{config}->{command_file};
    $self->named_recur(
        recur_name => 'NagiosCmd_write_tick',
        repeat_interval => 1,
        work => sub {
            $self->_write_tick();
        },



( run in 0.241 second using v1.01-cache-2.11-cpan-4d50c553e7e )