如何从Nagios-Report Perl模块打印Nagios服务UP时间百分比

时间:2013-01-11 15:32:14

标签: perl monitoring perl-module nagios

我可以使用以下代码从Nagios-Report Perl Module打印主机更新时间百分比:

#!/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 ;

但我怎样才能打印服务 UP时间百分比?我的意思是只输出百分比值。

我尝试了很多选项,但无法做到正确。

1 个答案:

答案 0 :(得分:2)

这将产生服务更新时间报告,但我如何只检索更新时间百分比值而不是完整报告?

#!/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() ;