head	1.1;
access;
symbols;
locks
	sh1517:1.1; strict;
comment	@# @;


1.1
date	2005.12.13.02.28.50;	author sh1517;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@#!/usr/bin/perl

# $Id$

# $Log$

use strict ;

use Nagios::Report ;
use Getopt::Std ;

use vars qw($opt_t) ;

getopt 't' ;

my $usage = <<USAGE ;

$0 -t <timeperiod>

Displays those hosts with less than 100% total time up during the timeperiod.

timeperiod ::= today     | yesterday   |
	       thisweek  | lastweek    |
	       thismonth | lastmonth   |
	       thisyear  | lastyear    |
               last12hours | last24hours | last7days | last31days |
	       HHMM      | HH::MM      |
	       DD.MM.YY  | DD.MM.YYYY  | MM/DD/YY | MM/DD/YYYY    |
	       24hourtime date

eg $0 -t 07:00 01.12.2005

USAGE

die $usage
  unless $opt_t ;

die $usage
  unless $opt_t =~ m#^(?:
			today										|
			yesterday									|
			this (?:week|month|year)							|
			last (?:week|month|year|24hours|12hours|7days|31days|\d+days?|\d+hours?) 	|
			(?: \d\d :? \d\d  \s+  \d\d? [\./] \d\d? [\./] \d\d (?:\d\d)?)			|
			(?: \d\d :? \d\d)								|
			(?: \d\d? [\./] \d\d? [\./] \d\d (?:\d\d)?)
		     )$#x ;


my $x = Nagios::Report->new(q<local_cgi nms sh1517>, [ qw(24x7 DEST_Optus_SLA_hours) ], $opt_t, 1, sub { my %F = @@_; my $u = $F{PERCENT_TOTAL_TIME_OK}; $u =~ s/%//; $u < 100 })
# my $x = Nagios::Report->new(q<local_cgi nms sh1517>, [ qw(DEST_Optus_SLA_hours) ], $opt_t, 1, 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
		    SERVICE_DESCRIPTION
		    PERCENT_TOTAL_TIME_OK
		    TOTAL_TIME_CRITICAL
		    TOTAL_TIME_CRITICAL_HMS
		  )
		],

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


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

                sub {   $_ = shift @@_; my %F = @@_;
                        my $d = $F{TOTAL_TIME_CRITICAL} ;
                        push @@$_, &t2hms($d) ;
                        qw(TOTAL_TIME_CRITICAL_HMS) ;
                },
) ;


$x->debug_dump(30, 5) ;
							# 240 chars is needed for the URLs.
@
