【问题标题】:POE::Component::Server::NRPE, return-valuePOE::Component::Server::NRPE,返回值
【发布时间】:2012-11-08 18:11:08
【问题描述】:

我尝试使用您的 CPAN 模块 POE::Compoenten::Server::NRPE。 我尝试了来自 CPAN 站点的示例,并针对 nagios-tool check_nrpe 进行了测试。

文本很好,但我无法获得正确的返回值。 您在模块描述中描述了这个 return_result,但我不知道如何使用它。

会很好,如果你能给我一个非常简短的例子,如何返回一个值 0。

非常感谢!

干杯, 克里斯托夫

use POE;
use POE::Component::Server::NRPE;

# test with: check_nrpe -H localhost -c test; echo $?

my $nrped = POE::Component::Server::NRPE->spawn (port => 5666);
$nrped->add_command (command => "test", program =>
sub { print STDOUT "test CRITICAL\n";
return 2;    # always 0???
});

$poe_kernel->run ();
return 0; 

【问题讨论】:

    标签: perl nagios poe nrpe


    【解决方案1】:

    感谢您发布此问题。我不知道这个模块,但它对我有很大帮助。

    1. 尝试在您的代码中使用严格和警告,这对您有好处
    2. 使用 POE::Component::Server::NRPE::Constants 提供的返回常量,而不是使用 0 表示 OK,1 表示 WARNING 等等
    3. 我相信唯一的问题是您在测试子中使用 return 2 而不是 exit 2 或更好的 exit NRPE_STATE_CRITICAL

    以下代码应该会产生所需的结果

    use strict;
    use warnings;
    use POE;
    use POE::Component::Server::NRPE;
    
    # it's recommended to use the NRPE return states provided by the module
    use POE::Component::Server::NRPE::Constants qw(NRPE_STATE_OK NRPE_STATE_CRITICAL);
    
    my $nrped = POE::Component::Server::NRPE->spawn (
            port => 5666
    );
    
    $nrped->add_command (command => "test", program =>
            sub {
                    print STDOUT "testing CRITICAL\n";
            # better to use NRPE_STATE_CRITICAL...
                    exit NRPE_STATE_CRITICAL;
            # ... instead of the corresponding digital value
            # but it should work
            # exit 2;
            }
    );
    
    $poe_kernel->run ();
    exit 0;
    

    谢谢

    【讨论】:

      【解决方案2】:

      看起来像模块中的一个错误。 作者在cpan上推送了一个新版本(0.16 -> 0.18)。

      【讨论】:

        猜你喜欢
        • 2014-01-16
        • 1970-01-01
        • 1970-01-01
        • 2020-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多