如何从Nagios-Report Perl模块打印Nagios服务正常运行时间百分比 [英] How to print out Nagios Service UP Time Percentage from Nagios-Report Perl Module
本文介绍了如何从Nagios-Report Perl模块打印Nagios服务正常运行时间百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以从带有以下代码的Nagios-Report Perl模块:
#!/usr/bin/perl
use strict ;
use Nagios::Report ;
my $x = Nagios::Report->new(q<local_cgi localhost nagiosadmin>)
or die "Can't construct Nagios::Report object." ;
$x->mkreport(
[ qw(HOST_NAME PERCENT_TOTAL_TIME_UP) ],
sub {
my %F = @_; my $u = $F{PERCENT_TOTAL_TIME_UP}; $u =~ s/%//;
},
0,
sub {
my $F = shift @_ ;
}
) ;
$x->debug_dump ;
但是如何只打印出服务正常运行时间百分比?我的意思是只输出百分比值.
But How can I only print out Service UP Time Percentage? I mean only output the percentage value.
我尝试了很多选择,但无法正确完成.
I tried many options but couldn't get it right.
推荐答案
这将生成服务正常运行时间"报告,但是如何仅检索正常运行时间"百分比值而不是完整报告?
This will produce Service UP Time Report, but How can I only retrieve UP Time percentage value instead of full report?
#!/usr/bin/perl
use strict ;
use Nagios::Report ;
my $x = Nagios::Report->new(
# Data source
q<local_cgi localhost nagiosadmin>,
# Report period
[ qw(24x7) ],
# Time period
'last7days',
# Service report
1,
# Pre-filter
sub { my %F = @_; my $u = $F{PERCENT_TOTAL_TIME_OK}; $u =~ s/%//; $u < 100 }
)
or die "Can't construct Nagios::Report object." ;
$x->mkreport(
[
qw(
HOST_NAME
PERCENT_TOTAL_TIME_OK
DOWN
UP
OUTAGE
)
],
sub { my %F = @_; my $u = $F{PERCENT_TOTAL_TIME_OK}; $u =~ s/%//; $u < 100 },
undef,
undef,
1,
) ;
$x->debug_dump() ;
这篇关于如何从Nagios-Report Perl模块打印Nagios服务正常运行时间百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文