Stanley Hopcroft > Nagios-Report-0.003 > Nagios::Report

Download:
Nagios-Report-0.003.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 0.003   Source  

NAME ^

Nagios::Report - Perl class to filter and munge Nagios availability data

SYNOPSIS ^

  use Nagios::Report ;

  my $x = Nagios::Report->new(q<local_cgi nagios_web_server nagios_user>, [ '24x7' ], 'thismonth')
    or die "Can't construct Nagios::Report object." ;

  my @these_fields = qw(
    HOST_NAME
    PERCENT_TOTAL_TIME_UP
    TOTAL_TIME_DOWN
    TIME_DOWN_HHMMSS
    TOTAL_TIME_UNREACHABLE
    TIME_UNREACH_HHMMSS
    AVAIL_URL
    TREND_URL
  ) ;

  $x->mkreport(
                            # Field selector; display these fields only (in the listed order)

                            # [] means display all the fields.

        \@these_fields,
                            # Record selector

                            # Called with @_ loaded # with a list of field names and
                            # their vals for this record. Usually copied to a hash
                            # so it can be used as one.

                            # All records
                            #   sub { 1 },
                            # All records whose HOST_NAME starts with 'Alb'
                            #   sub { my %F = @_; my $h = $F{HOST_NAME}; $h =~ /^Alb/ },
                            # Regrettably, this is _NOT_ the same since
                            # @_ can't be used as a hash.
                            #   sub { $_{HOST_NAME} =~ /^Alb/ }
                            # All records with an up time percent < 98%

        sub { my %F = @_; my $u = $F{PERCENT_TOTAL_TIME_UP}; $u =~ s/%//; $u < 98 },

                            # Sort order

        &comp( alpha => 0, ascend => 0, fields => [ qw(TOTAL_TIME_DOWN TOTAL_TIME_UNREACHABLE) ]),

                            # Sorts descending by max of TOTAL_TIME_DOWN and TOTAL_TIME_UNREACHABLE

                            # DIY sorters remember that $a and $b _must_ be in Nagios::Report package.
                            # eg by TOTAL_DOWN_TIME descending.
                            #   sub { my %f = @_ ;
                            #         package Nagios::Report;
                            #         $b->[$f{TOTAL_TIME_DOWN}] <=> $a->[$f{TOTAL_TIME_DOWN}]
                            #        },
                            # Same as
                            #  &comp(alpha => 0, ascend => 0, fields => ['TOTAL_TIME_DOWN'])
                            # Same but harder,
                            #  sub { package Nagios::Report; $b->[16] <=> $a->[16] },

                            # Optional callback to add or mangle fields.

                            # Add 2 fields for downtime vals in hours minutes and secs.

        sub {    $F = shift @_;
            $F->{TIME_DOWN_HHMMSS}    =    t2hms( $F->{TOTAL_TIME_DOWN} ),
            $F->{TIME_UNREACH_HHMMSS}=    t2hms( $F->{TOTAL_TIME_UNREACHABLE} ) ;
            qw(TIME_DOWN_HHMMSS TIME_UNREACH_HHMMSS)
            }

  ) ;

  $x->debug_dump ;
                            # $x->csv_dump ;

DESCRIPTION ^

Gets the Nagios (http://wwww.Nagios.ORG/) All Hosts or Services availability report (getting the results in CSV format) and applies grep like filters, map like munging, and slice like field masks to produce a report which can be output in various ways.

This class provides extra control over the content and disposition of the data produced by the Nagios availability CGI, by writing for example a spreadsheet containing the selected data.

Since the data originates from standard Nagios availability CGI, its results are no more accurate - and should be exactly the same - as that CGI.

METHODS ^

ACCESSORS/MUTATORS ^

Acessors and mutators are provided for most of the attributes in the object. The module makes no use of them and, except for those below, are probably of little interest. Unless noted, the caller is responsible for processing the attribute type correctly; the acessor does nothing more than hand back a ref.

SUBROUTINES ^

BUGS ^

SEE ALSO ^

perl(1).

Nagios (http://www.Nagios.ORG/)

AUTHOR ^

Stanley Hopcroft <HopcroftS@CPAN.Org>

COPYRIGHT ^

Copyright (c) 2006 Stanley Hopcroft. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.