How to print out Nagios Service UP Time Percentage?

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
kunus
Posts: 2
Joined: Fri Jan 11, 2013 10:53 am

How to print out Nagios Service UP Time Percentage?

Post by kunus »

Hi,
How to print out Nagios Service UP Time Percentage from Nagios-Report Perl Module?
I can print out Host UP Time percentage from Nagios-Report Perl Module with following code:

Code: Select all

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

Thanks

Edit: This will produce Service UP Time Report, but How can I only retrieve UP Time percentage value instead of full report?

Code: Select all

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

Edit 2: Any Ideas? or any other way to retrieve UP Time percentage? e.g. PHP Class, Command Line Tools or ..
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: How to print out Nagios Service UP Time Percentage?

Post by slansing »

So I guess I don't understand, are you attempting to add a Service's up time to another report? Because the first question you asked does not match the second one it looks like you want to create a separate service report, are you confusing this with check results? Lets just clear that up first.
kunus
Posts: 2
Joined: Fri Jan 11, 2013 10:53 am

Re: How to print out Nagios Service UP Time Percentage?

Post by kunus »

Hi again and Thank you. Yes I'm trying to generate another service report. and I'm looking for someway to retrieve a service uptime. any ideas?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: How to print out Nagios Service UP Time Percentage?

Post by abrist »

In the availability reporting component, if you specify a host, you will get percentages for all the service for the given time period.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked