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

1

6

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.

Fuqua answered 11/1, 2013 at 15:32 Comment(4)
I suggest you read the page you linked to and search for service. For example, the following text hints at the usage: HOST_OR_SERVICE is an optional scalar specifying the service report instead of the host report. If not set, the host report is produced.Dockery
Thank you, I don't understand how to produce service report. What should I set?Fuqua
@Fuqua Perhaps my $x = Nagios::Report->new(q<local_cgi localhost nagiosadmin host_or_service>)Tetravalent
Thanks Craig, That didn't work but helped me to find the solution. I still don't know How to retrieve only the up-time value instead of full report.Fuqua
F
2

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() ;
Fuqua answered 12/1, 2013 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.