Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 检查GEARMAN临界-功能';大量电子邮件';未在服务器中注册_Linux_Bash_Nagios_Gearman - Fatal编程技术网

Linux 检查GEARMAN临界-功能';大量电子邮件';未在服务器中注册

Linux 检查GEARMAN临界-功能';大量电子邮件';未在服务器中注册,linux,bash,nagios,gearman,Linux,Bash,Nagios,Gearman,我正在使用nagios监控gearman,并收到错误“关键-功能'xxx'未在服务器中注册” nagios为检查gearman而执行的脚本如下 #!/usr/bin/env perl # taken from: gearmand-0.24/libgearman-server/server.c:974 # function->function_name, function->job_total, # function->job_running, function->

我正在使用nagios监控gearman,并收到错误“关键-功能'xxx'未在服务器中注册”

nagios为检查gearman而执行的脚本如下

    #!/usr/bin/env perl

# taken from: gearmand-0.24/libgearman-server/server.c:974
# function->function_name, function->job_total,
# function->job_running, function->worker_count);
#
# this code give following result with gearadmin --status
#
# FunctionName                job_total job_running  worker_count
# AdsUpdateCountersFunction       0           0           4

use strict;
use warnings;

use Nagios::Plugin;

my $VERSION="0.2.1";
my $np;

$np = Nagios::Plugin->new(usage => "Usage: %s -f|--flist <func1[:threshold1],..,funcN[:thresholdN]> [--host|-H <host>] [--port|-p <port>] [ -c|--critworkers=<threshold> ] [ -w|--warnworkers=<threshold>] [-?|--usage] [-V|--version] [-h|--help] [-v|--verbose] [-t|--timeout=<timeout>]",
                          version => $VERSION,
                          blurb => 'This plugin checks a gearman job server, expecting that every function in function-list arg is registered by at least one worker, and expecting that job_total is not too much high.',
                          license => "Brought to you AS IS, WITHOUT WARRANTY, under GPL. (C) Remi Paulmier <remi.paulmier\@gmail.com>",
                          shortname => "CHECK_GEARMAN",
                         );

$np->add_arg(spec => 'flist|f=s',
             help => q(Check for the functions listed in STRING, separated by comma. If optional threshold is given (separated by :), check that waiting jobs for this particular function are not exceeding that value),
             required => 1,
            );
$np->add_arg(spec => 'host|H=s',
             help => q(Check the host indicated in STRING),
             required => 0,
             default => 'localhost',
            );

$np->add_arg(spec => 'port|p=i',
             help => q(Use the TCP port indicated in INTEGER),
             required => 0,
             default => 4730,
            );

$np->add_arg(spec => 'critworkers|c=i',
             help => q(Exit with CRITICAL status if fewer than INTEGER workers have registered a particular function),
             required => 0,
             default => 1,
            );

$np->add_arg(spec => 'warnworkers|w=i',
             help => q(Exit with WARNING status if fewer than INTEGER workers have registered a particular function),
             required => 0,
             default => 4,
            );

$np->getopts;
my $ng = $np->opts;

# manage timeout
alarm $ng->timeout;

my $runtime = {'status' => OK,
               'message' => "Everything OK",
              };

# host & port
my $host = $ng->get('host');
my $port = $ng->get('port');

# verbosity
my $verbose = $ng->get('verbose');# look for gearadmin, use nc if not found
my @paths = grep { -x "$_/gearadmin" } split /:/, $ENV{PATH};
my $cmd = "gearadmin --status -h $host -p $port";
if (@paths == 0) {
        print STDERR "gearadmin not found, using nc\n" if ($verbose != 0);
#       $cmd = "echo status | nc -w 1 $host $port";
        $cmd = "echo status | nc -i 1 -w 1 $host $port";
}

foreach (`$cmd 2>/dev/null | grep -v '^\\.'`) {
        chomp;

        my ($fname, $job_total, $job_running, $worker_count) =
          split /[[:space:]]+/;

        $runtime->{'funcs'}{"$fname"} = {job_total => $job_total,
                                         job_running => $job_running,
                                         worker_count => $worker_count };
        # print "$fname : $runtime->{'funcs'}{\"$fname\"}{'worker_count'}\n";
}

# get function list
my @flist = split /,/, $ng->get('flist');

foreach (@flist) {

        my ($fname, $fthreshold);

        if (/\:/) {
                ($fname, $fthreshold) = split /:/;
        } else {
                ($fname, $fthreshold) = ($_, -1);
        }

#       print "defined for $fname: $runtime->{'funcs'}{\"$fname\"}{'worker_count'}\n";

#       if (defined($runtime->{'funcs'}{"$fname"})) {
#               print "$fname is defined\n";
#       } else {
#               print "$fname is NOT defined\n";
#       }

        if (!defined($runtime->{'funcs'}{"$fname"}) &&
            $runtime->{'status'} <= CRITICAL) {

                ($runtime->{'status'}, $runtime->{'message'}) =
                  (CRITICAL, "function '$fname' is not registered in the server");
        } else {
                if ($runtime->{'funcs'}{"$fname"}{'worker_count'} <
                    $ng->get('critworkers') && $runtime->{'status'} <= CRITICAL) {

                        ($runtime->{'status'}, $runtime->{'message'}) =
                          (CRITICAL,
                           "less than " .$ng->get('critworkers').
                           " workers were found having function '$fname' registered.");
                }

                if ($runtime->{'funcs'}{"$fname"}{'worker_count'} <
                    $ng->get('warnworkers') && $runtime->{'status'} <= WARNING) {

                        ($runtime->{'status'}, $runtime->{'message'}) =
                          (WARNING,
                           "less than " .$ng->get('warnworkers').
                           " workers were found having function '$fname' registered.");
                }

                if ($runtime->{'funcs'}{"$fname"}{'job_total'} > $fthreshold
                    && $fthreshold != -1 && $runtime->{'status'}<=WARNING) {

                        ($runtime->{'status'}, $runtime->{'message'}) =
                          (WARNING,
                           $runtime->{'funcs'}{"$fname"}{'job_total'}.
                           " jobs for $fname exceeds threshold $fthreshold");
                }
        }
}

$np->nagios_exit($runtime->{'status'}, $runtime->{'message'});
#/usr/bin/env perl
#摘自:gearmand-0.24/libgearman-server/server.c:974
#功能->功能名称,功能->作业总数,
#功能->作业运行,功能->工人计数);
#
#此代码给出了gearadmin--status的以下结果
#
#FunctionName作业\u总作业\u运行工人\u计数
#AdsUpdateCounters函数0 0 4
严格使用;
使用警告;
使用Nagios::Plugin;
我的$VERSION=“0.2.1”;
我的$np;
$np=Nagios::Plugin->new(用法=>“用法:%s-f |--flist[--host |--H][--port |--p][-c |--critworkers=][-w |--warnworkers=][-?|--用法]-[V |--version][H |--help][-V |--verbose][-t |--timeout=],
版本=>$version,
blurb=>“此插件检查gearman作业服务器,希望函数列表arg中的每个函数都至少有一个worker注册,并希望作业总数不会太高。”,
license=>“按照GPL(C)Remi Paulmier)的规定按原样提供给您,无需保修”,
shortname=>“检查GEARMAN”,
);
$np->add_arg(spec=>“flist | f=s”,
help=>q(检查字符串中列出的函数,用逗号分隔。如果给定了可选阈值(用:)分隔),请检查此特定函数的等待作业是否未超过该值),
必需=>1,
);
$np->add_arg(spec=>“host | H=s”,
help=>q(检查字符串中指示的主机),
必需=>0,
默认值=>'localhost',
);
$np->add_arg(spec=>“port | p=i”,
help=>q(使用整数表示的TCP端口),
必需=>0,
默认值=>4730,
);
$np->add_arg(spec=>“critworkers | c=i”,
help=>q(如果注册特定函数的工作进程少于整数,则以临界状态退出),
必需=>0,
默认值=>1,
);
$np->add_arg(spec=>“warnworkers | w=i”,
help=>q(如果注册特定函数的整数工作进程少于整数,则以警告状态退出),
必需=>0,
默认值=>4,
);
$np->getopts;
my$ng=$np->opts;
#管理超时
报警$ng->超时;
我的$runtime={'status'=>OK,
'消息'=>“一切正常”,
};
#主机和端口
my$host=$ng->get('host');
my$port=$ng->get('port');
#冗长
my$verbose=$ng->get('verbose');#查找gearadmin,如果未找到,请使用nc
my@paths=grep{-x“$\/gearadmin”}split/:/,$ENV{PATH};
my$cmd=“gearadmin——状态-h$host-p$port”;
如果(@path==0){
如果($verbose!=0),则打印STDERR“未找到gearadmin,使用nc\n”;
#$cmd=“echo status | nc-w 1$host$port”;
$cmd=“echo status | nc-i 1-w 1$host$port”;
}
foreach(`$cmd 2>/dev/null | grep-v'^\\\\''`){
咀嚼;
我的($fname、$job\u total、$job\u running、$worker\u count)=
拆分/[:空格:]+/;
$runtime->{'funcs'}{“$fname”}={job_total=>$job_total,
job\u running=>$job\u running,
worker\u count=>$worker\u count};
#打印“$fname:$runtime->{'funcs'}{\'$fname\'}{'worker\u count'}\n”;
}
#获取函数列表
我的@flist=split/,/,$ng->get('flist');
foreach(@flist){
我的($fname,$fthreshold);
如果(/\:/){
($fname,$fthreshold)=拆分/:/;
}否则{
($fname,$fthreshold)=($)-1;
}
#打印“为$fname定义:$runtime->{'funcs'}{\“$fname\”}{'worker\u count'}\n”;
#if(已定义($runtime->{'funcs'}{$fname})){
#打印“$fname已定义\n”;
#}其他{
#打印“$fname未定义\n”;
#       }
如果(!已定义($runtime->{'funcs'}{“$fname”})&&
$runtime->{'status'}{'status'},$runtime->{'message'})=
(关键,“未在服务器中注册函数“$fname”);
}否则{
如果($runtime->{'funcs'}{$fname'}{'worker_count'}<
$ng->get('critworkers')&&&$runtime->{'status'}{'status'},$runtime->{'message'})=
(至关重要,
小于“$ng->get('critworkers')。
“发现工人注册了功能'$fname'”);
}
如果($runtime->{'funcs'}{$fname'}{'worker_count'}<
$ng->get('warnworkers')&&&$runtime->{'status'}{'status'},$runtime->{'message'})=
(警告,
小于“$ng->get('warnworkers')。
“发现工人注册了功能'$fname'”);
}
如果($runtime->{'funcs'}{'fname'}{'job_total'}>$fthreshold
&&$fthreshold!=-1&&$runtime->{'status'}{'status'},$runtime->{'message'})=
(警告,
$runtime->{'funcs'}{'fname'}{'job_total'}。
“$fname的作业超过阈值$fthreshold”);
}
}
}
$np->nagios_exit($runtime->{'status'},$runtime->{'message'});
当脚本仅通过命令行执行时,它会显示“一切正常”

但在nagios中,它显示错误“关键功能‘xxx’未在服务器中注册”


提前感谢

说起来不容易,但这可能与您的脚本不可执行有关

在脚本开头尝试使用
#nagios:-epn

#!/usr/bin/env perl

# nagios: -epn

use strict;
use warnings;
花了很长时间后,一定要检查

部分中的所有提示