【问题标题】:How to print out Nagios Service UP Time Percentage from Nagios-Report Perl Module如何从 Nagios-Report Perl 模块中打印出 Nagios 服务 UP 时间百分比
【发布时间】:2013-01-11 15:32:14
【问题描述】:

我可以使用以下代码从Nagios-Report Perl Module 打印出 Host UP 时间百分比:

#!/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 时间百分比?我的意思是只输出百分比值。

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

【问题讨论】:

  • 我建议您阅读您链接到的页面并搜索service。例如,以下文本提示使用:HOST_OR_SERVICE is an optional scalar specifying the service report instead of the host report. If not set, the host report is produced.
  • 谢谢,我不懂如何制作服务报告。我应该设置什么?
  • @Zim3r 也许我的 $x = Nagios::Report->new(q)
  • 感谢克雷格,这没有用,但帮助我找到了解决方案。我仍然不知道如何只检索正常运行时间值而不是完整报告。

标签: perl monitoring perl-module nagios


【解决方案1】:

这将生成服务正常运行时间报告,但我怎样才能只检索正常运行时间百分比值而不是完整报告?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多