How to print out Nagios Service UP Time Percentage from Nagios-Report Perl Module

时光毁灭记忆、已成空白 提交于 2019-12-09 17:56:11

问题


I can print out Host UP Time percentage from Nagios-Report Perl Module with following code:

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


回答1:


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() ;


来源:https://stackoverflow.com/questions/14281396/how-to-print-out-nagios-service-up-time-percentage-from-nagios-report-perl-modul

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!