| 1 | package Nagios::Report; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # $Id: Report.pm,v 1.87 2006-08-23 14:26:17+10 sh1517 Exp sh1517 $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use base 'Exporter' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Time::Local ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # use POSIX qw(mktime) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use vars qw($VERSION @EXPORT @EXPORT_OK %stime_etime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 15 | *t2hms = \&time2ddhhmmss ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 15 | *d2t = \&date2time ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | *i2t = \&interval2time ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 15 | *st_et = \%stime_etime ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 15 | @EXPORT = qw(d2t t2hms comp max_l %st_et i2t) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 15 | $VERSION = '0.003'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 15 | ▶ | use constant REQUEST_METHOD => 'GET' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Will be hacked by Makefile.PL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 15 | ▶ | use constant CGI_PATH => '' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 15 | ▶ | use constant LYNX => '' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 15 | ▶ | use constant WGET => '' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # EURO_DATE => \d\d?-\d\d?-\d\d\d\d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # will be interpreted as DD-MM-YYYY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 15 | ▶ | use constant EURO_DATE => 1 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # End scope of expected changes by Makefile.PL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # NB. I choose lynx etc over LWP because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # LWP is a big module (LWP::Simple doesn't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # fetch protected pages). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 15 | ▶ | use constant NAG_AVAIL_CGI => CGI_PATH . 'avail.cgi' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 15 | ▶ | use constant WEB_PAGE => !! (LYNX || WGET) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 15 | ▶ | use constant LOCAL_CGI => !! CGI_PATH ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 15 | ▶ | use constant USE_LYNX => !! (WEB_PAGE && LYNX) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 15 | ▶ | use constant EXCEL_FILENAME => './Nagios_Avail.xls' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 15 | ▶ | use constant QS_TEMP_HOSTREP => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 15 | q(show_log_entries=&host=all&t1=T1&t2=T2&rpttimeperiod=REPORT_PERIOD&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=no&initialassumedhoststate=3&initialassumedservicestate=6&backtrack=0&csvoutput) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 15 | ▶ | use constant QS_TEMP_SVCREP => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 15 | q(show_log_entries=&host=FOO&service=all&t1=T1&t2=T2&rpttimeperiod=REPORT_PERIOD&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=no&initialassumedservicestate=6&backtrack=0&csvoutput=) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 15 | ▶ | use constant AVAIL_URL_TEMP_HOST => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | q(http://SERVER/nagios/cgi-bin/avail.cgi?host=HOST&t1=T1&t2=T2&show_log_entries=&assumeinitialstates=yes&assumestateretention=yes&includesoftstates=no&backtrack=0) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | use constant TREND_URL_TEMP_HOST => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 15 | q(http://SERVER/nagios/cgi-bin/trends.cgi?host=HOST&t1=T1&t2=T2&assumeinitialstates=yes&assumestateretention=yes&includesoftstates=no) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 15 | ▶ | use constant AVAIL_URL_TEMP_SVC => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 15 | q(http://SERVER/nagios/cgi-bin/avail.cgi?host=HOST&service=SVC&t1=T1&t2=T2&show_log_entries=&assumeinitialstates=yes&assumestateretention=yes&includesoftstates=no&assumestatesduringnotrunning=yes&backtrack=0&initialassumedservicestate=6) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 15 | ▶ | use constant TREND_URL_TEMP_SVC => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 15 | q(http://SERVER/nagios/cgi-bin/trends.cgi?host=HOST&service=SVC&t1=T1&t2=T2&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedhoststate=0&initialassumedservicestate=0&assumestateretention=yes&includesoftstates=no) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 15 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 15 | SEC => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | MIN => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | HOUR => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | MDAY => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | MON => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | YEAR => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | WDAY => 6, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | YDAY => 7, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ISDST => 8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 15 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 15 | ▶ | use constant MONTH => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Jan => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Feb => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | Mar => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | Apr => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | May => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | Jun => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | Jul => 6, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | Aug => 7, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | Sep => 8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | Oct => 9, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | Nov => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | Dec => 11, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 15 | } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 15 | ▶ | use constant T => { w => 7*86_400, d => 86_400, h => 60*60, m => 60, s => 1 } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub Iterator (&) { $_[0] } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Iterator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 15 | my %default_sort = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | alpha => 1, # 0 implies numeric | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ascend => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | fields => [ qw(HOST_NAME) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | %stime_etime = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 25 | ▶ | last12hours => sub { my $t = defined($_[1]) ? timelocal(@{$_[1]}) : time(); ( $t - 12 * 3_600, $t) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 73 | ▶ | last24hours => sub { my $t = defined($_[1]) ? timelocal(@{$_[1]}) : time(); ( $t - 1 * 86_400, $t) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 30 | ▶ | last7days => sub { my $t = defined($_[1]) ? timelocal(@{$_[1]}) : time(); ( $t - 7 * 86_400, $t) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 62 | ▶ | last31days => sub { my $t = defined($_[1]) ? timelocal(@{$_[1]}) : time(); ( $t - 31 * 86_400, $t) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 25 | ▶ | today => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 25 | ▶ | $_[1] ||= [localtime]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 25 | my $t = timelocal( @{$_[1]} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | #( mktime(0, 0, 0, $_[1]->[MDAY], $_[1]->[MON], $_[1]->[YEAR]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 25 | $t - ( $_[1]->[SEC] + 60 *( $_[1]->[MIN] + 60*$_[1]->[HOUR] ) ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | $t | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 31 | ▶ | yesterday => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 31 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 31 | my $midnight = timelocal( @{$_[1]} ) - ( $_[1]->[SEC] + 60 *( $_[1]->[MIN] + 60*$_[1]->[HOUR] ) ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 31 | $midnight - 86_400, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | $midnight | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 6 | ▶ | last_n_mins => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | my ($mins, $t_ar) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | my $t = timelocal( @$t_ar ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | $t - $mins * 60, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | $t | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 34 | ▶ | last_n_hours => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 34 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 34 | my ($hours, $t_ar) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 34 | my $t = timelocal(@$t_ar) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 34 | $t - $hours * 3_600, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | $t | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 11 | ▶ | last_n_days => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 11 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 11 | my ($days, $t_ar) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 11 | my $t = timelocal(@$t_ar ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # XXX Fails for days > 120. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 11 | $t - $days * 86_400, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | $t, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 7 | ▶ | thisweek => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # thisweek is wrt to MONDAY. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 7 | my $t = timelocal( @{$_[1]} ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 7 | $t - ( $_[1]->[SEC] + 60*($_[1]->[MIN] + 60*$_[1]->[HOUR]) + ($_[1]->[WDAY] - 1)*86_400 ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | $t | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 10 | ▶ | lastweek => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 10 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | my $sweek = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 10 | timelocal( @{$_[1]} ) - ( $_[1]->[SEC] + 60*($_[1]->[MIN] + 60*$_[1]->[HOUR]) + ($_[1]->[WDAY]-1)*86_400 ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 10 | $sweek - 7 * 86_400, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | $sweek - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 12 | ▶ | thismonth => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 12 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | timelocal( 0, 0, 0, 1, $_[1]->[MON], $_[1]->[YEAR] ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 12 | timelocal( @{$_[1]} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 6 | ▶ | lastmonth => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 6 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 6 | my ($m, $y) = @{$_[1]}[MON, YEAR] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | timelocal( 0, 0, 0, 1, ($m - 1) % 12, $y - ($m == 0), ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | timelocal( 0, 0, 0, 1, $m , $y ) - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ▶ | thisyear => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | timelocal( 0, 0, 0, 1, 0, $_[1]->[YEAR]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | timelocal( @{$_[1]} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | lastyear => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | ▶ | $_[1] ||= [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] ||= [localtime]
MC/DC0%0/1
$_[1] ||= [localtime]
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | ( timelocal( 0, 0, 0, 1, 0, $_[1]->[YEAR] - 1 ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | timelocal( 0, 0, 0, 1, 0, $_[1]->[YEAR] ) -1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 107 | ▶ | __DEFAULT__ => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # The 'tag' or the name of the interval supplied to the constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # The tag describes the interval either absolutely (eg DD.MM.YY) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # wrt to the second arg (the right edge of the interval). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 107 | local $_= shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # Usually this arg is the upper bound of the interval. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Most often it is [localtime]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 107 | ▶ | my $t = @_ ? shift @_ : [localtime] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 107 | my @t = @$t ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | my ($t1, $t2) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | /^ last(\d+)day /x ? $stime_etime{last_n_days}->( $1, $t ) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | /^ last(\d+)hour /x ? $stime_etime{last_n_hours}->( $1, $t ) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | /^ last(\d+)min /x ? $stime_etime{last_n_mins}->( $1, $t ) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Define a time period with a string like so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # time: HHMM | HH:MM => from that time today to now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # date: DD.MM.YY | DD.MM.YYYY | MM/DD/YYYY | MM/DD/YY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # => midnight on that day to now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # time date => that time on that day to now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # The time and date formats are inspired by the at command. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | /^ (\d\d) :? (\d\d) $/x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | ? do { # HHMM | HH:MM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 4 | @t[SEC, MIN, HOUR] = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | (0, $2, $1 ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | ▶ | ( timelocal(@t), timelocal(@$t) ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | m{^ (\d\d?) [\./] (\d\d?) [\./] ( \d\d (?:\d\d)? ) $}x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ? do { # DD.MM.YY(YY)? | MM/DD/YY(YY)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | my ($dd, $mm, $yy) = ($1, $2, $3) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | ▶ | ($mm, $dd) = ($dd, $mm) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | if m{/} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 6 | @t[SEC, MIN, HOUR, MDAY, MON, YEAR] = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | (0, 0, 0, $dd, $mm - 1, $yy ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | ▶ | ( timelocal(@t), timelocal(@$t) ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | m{^ (\d\d) :? (\d\d) \s+ (\d\d?) [\./] (\d\d?) [\./] ( \d\d (?:\d\d)? ) $ }x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ? do { # HHMM | HH:MM DD.MM.YY(YY)? | MM/DD/YY(YY)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 10 | my ($h, $m, $dd, $mm, $yy) = ($1, $2, $3, $4, $5) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 10 | ▶ | ($mm, $dd) = ($dd, $mm) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | if m{/} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 10 | @t[SEC, MIN, HOUR, MDAY, MON, YEAR] = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | (0, $m, $h, $dd, $mm - 1, $yy ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 10 | ▶ | ( timelocal(@t), timelocal(@$t) ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | m{^ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \s* (\d{4})? }ix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 107 | ▶ | ? do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # I'd like to be able to use 'Mar-2006' here but I can't because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # the constructor will recognise date ranges (intervals) as strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # containing '-'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 60 | my ($mm, $yy, @t1, @t2) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 60 | $mm = MONTH->{"\u$1"} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 60 | ▶ | $yy = $2 || $t[YEAR] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$2 || $t[5]
MC/DC0%0/2
$2 || $t[5]
$2
$t[5]
Truth table33%1/3
A || B
A= $2B= $t[5]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 60 | @t1[SEC, MIN, HOUR, MDAY, MON, YEAR] = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | (0, 0, 0, 1, $mm, $yy ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 60 | @t2[SEC, MIN, HOUR, MDAY, MON, YEAR] = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | (0, 0, 0, 1, ($mm + 1) % 12, $yy + ($mm == 11) ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 60 | ( timelocal(@t1), timelocal(@t2) - 1 ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | (999_999, 999_999) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 107 | ▶ | die "\%stime_etime: non existent tag '$_' - no handler defined for this tag. Outahere." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$t1 == 999999 and $t2 == 999999
MC/DC0%0/2
$t1 == 999999 and $t2 == 999999
$t1 == 999999
$t2 == 999999
Truth table33%1/3
A and B
A= $t1 == 999999B= $t2 == 999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | if $t1 == 999_999 && $t2 == 999_999 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 107 | return ($t1, $t2) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 15 | ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | my %data_source = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # All these subroutines return a code reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # (a closure encapsulating auth data) that actually gets the data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | web_page => WEB_PAGE ? \&gen_web_page : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | sub { die 'No CLI web browser (lynx or wget) found. Use local_cgi or report bug' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | local_cgi => LOCAL_CGI ? \&gen_local_cgi : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub { die 'Nagios availability CGI not found on this host. Use web_page or report bug' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # Return a ref to the subroutine in main:: (the client code) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # that will return the CSV data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 9 | ▶ | dev_debug => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 9 | ▶ | die "dev_debug source tag must be followed by the name of a callback in main::." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | unless $_[0] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 15 | ▶ | no strict 'refs' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 9 | my $cb = 'main::' . $_[0] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 9 | return \&$cb ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | __DEFAULT__ => sub { die "Outahere: bad source tag '$_[0]'" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 15 | ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=28 SCAR=54.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | my ($class, $source_tag, $rpt_period, $tme_period, $rep_type, $pre_filter) = @_ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=28 SCAR=54.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | my @report_period = $rpt_period ? @$rpt_period : qw(24x7) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $time_period = $tme_period ? $tme_period : q(thismonth) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my $report_type = $rep_type ? q(service) : q(host) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | die 'new() called with a pre_filter parm that is _not_ a code ref. Caller ' . join(' ', caller) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition16%1/6
$pre_filter and ref $pre_filter ne "CODE"
$pre_filter and ref $pre_filter ne "CODE"
MC/DC0%0/2
$pre_filter and ref $pre_filter ne "CODE"
$pre_filter
ref $pre_filter ne "CODE"
MC/DC0%0/2
$pre_filter and ref $pre_filter ne "CODE"
$pre_filter
ref $pre_filter ne "CODE"
Truth table33%1/3
A and B
A= $pre_filterB= ref $pre_filter ne "CODE"
Truth table0%0/3
A and B
A= $pre_filterB= ref $pre_filter ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | if $pre_filter and ref($pre_filter) ne 'CODE' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | $pre_filter ||= sub { 1 } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=2.6
Condition16%1/6
$pre_filter ||= sub {
1;
}
$pre_filter ||= sub {
1;
}
MC/DC0%0/2
$pre_filter ||= sub {
1;
}
$pre_filter
sub {
1;
}
MC/DC0%0/2
$pre_filter ||= sub {
1;
}
$pre_filter
sub {
1;
}
Truth table33%1/3
A ||= B
A= $pre_filterB= sub {
1;
}
Truth table0%0/3
A ||= B
A= $pre_filterB= sub {
1;
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $me = {} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $schema = q{} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my @fieldnames= () ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my @fieldnums = () ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my %fields = () ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $me->{REPORTS}= {} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $me->{REPORT_PERIODS} = [ @report_period ] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # Date ranges: $time_period =~ start_at_date / \s* - \s*/x end_at_date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # start_at_date and end_at_dates look like time stamps. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my ($t1, $t2) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ( my ($s, $e) = $time_period =~ /^([^-]+)-([^-]+)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # XXX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $s =~ s/\s+$// ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $e =~ s/^\s+// ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ($t1, undef) = $stime_etime{__DEFAULT__}->( $s, [ localtime ] ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ($t2, undef) = $stime_etime{__DEFAULT__}->( $e, [ localtime ] ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ($t1, $t2) = exists $stime_etime{$time_period} ? $stime_etime{$time_period}->( $time_period, [localtime] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | : $stime_etime{__DEFAULT__}->( $time_period, [localtime] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $data ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | $source_tag =~ s/dev_debug/dev_debug BOGON_SERVER/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | if $source_tag =~ /^dev_debug/ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ($source_tag, $data) = split /\s+/, $source_tag, 2 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | die "new() called with either null source_tag or null parms: \$source_tag: '$source_tag' \$data: '$data'. Caller " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition16%1/6
$source_tag and $data
$source_tag and $data
MC/DC0%0/2
$source_tag and $data
$source_tag
$data
MC/DC0%0/2
$source_tag and $data
$source_tag
$data
Truth table33%1/3
A and B
A= $source_tagB= $data
Truth table0%0/3
A and B
A= $source_tagB= $data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | join(' ', caller) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | unless $source_tag && $data ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my ($server, $auth) = split /\s+/, $data, 2 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | die "new() called with a source_tag that failed to contain a non null server name. Caller " . join(' ', caller) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | unless $server ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $me->{DATA_SOURCE} = $data_source{$source_tag}->(split /\s+/, $auth) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $me->{SERVER} = $server ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $me->{SOURCE_TAG} = $source_tag ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $me->{REPORT_TYPE} = $report_type ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $me->{T1} = $t1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $me->{T2} = $t2 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | foreach my $rep_period ( @report_period ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $user_data ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | $user_data = $report_type eq 'host' ? QS_TEMP_HOSTREP : QS_TEMP_SVCREP ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $user_data =~ s/t1=T1&t2=T2/t1=$t1&t2=$t2/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $user_data =~ s/REPORT_PERIOD/$rep_period/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | $user_data = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $me->{SOURCE_TAG} eq 'web_page' ? "http://$me->{SERVER}/nagios/cgi-bin/avail.cgi?$user_data" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | $me->{SOURCE_TAG} eq 'dev_debug' ? $rep_period : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | $me->{SOURCE_TAG} eq 'local_cgi' ? $user_data : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | '__DEFAULT__' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my @avail_rep = $me->{DATA_SOURCE}->($user_data) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $schema = shift @avail_rep ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $schema .= ', AVAIL_URL, TREND_URL' ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | $me->{FIELDNAMES} ||= [ @fieldnames = split /,\s+/, $schema ] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$me->{"FIELDNAMES"} ||= [@fieldnames = split(/,\s+/, $schema, 0)]
$me->{"FIELDNAMES"} ||= [@fieldnames = split(/,\s+/, $schema, 0)]
MC/DC0%0/1
$me->{"FIELDNAMES"} ||= [@fieldnames = split(/,\s+/, $schema, 0)]
$me->{"FIELDNAMES"}
MC/DC0%0/1
$me->{"FIELDNAMES"} ||= [@fieldnames = split(/,\s+/, $schema, 0)]
$me->{"FIELDNAMES"}
Truth table50%1/2
A
A= $me->{"FIELDNAMES"}
Truth table0%0/2
A
A= $me->{"FIELDNAMES"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | @fields{@fieldnames}= (0 .. $#fieldnames) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $me->{FIELDS} ||= { %fields } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$me->{"FIELDS"} ||= {%fields}
$me->{"FIELDS"} ||= {%fields}
MC/DC0%0/1
$me->{"FIELDS"} ||= {%fields}
$me->{"FIELDS"}
MC/DC0%0/1
$me->{"FIELDS"} ||= {%fields}
$me->{"FIELDS"}
Truth table50%1/2
A
A= $me->{"FIELDS"}
Truth table0%0/2
A
A= $me->{"FIELDS"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my @avail_report = () ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | local $_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | foreach (@avail_rep) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my @vals = split /,\s+/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $host = $vals[$fields{HOST_NAME}] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $svc ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $host =~ s/"//g ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $vals[$fields{HOST_NAME}] = $host ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ( $report_type eq 'service' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $svc = $vals[$fields{SERVICE_DESCRIPTION}] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $svc =~ s/"//g ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $vals[$fields{SERVICE_DESCRIPTION}] = $svc ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | my $avail_url = $report_type eq 'host' ? AVAIL_URL_TEMP_HOST : AVAIL_URL_TEMP_SVC ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $avail_url =~ s/HOST/$host/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | $avail_url =~ s/SVC/$svc/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | if $report_type eq 'service' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $avail_url =~ s/t1=T1&t2=T2/t1=$t1&t2=$t2/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $avail_url =~ s/SERVER/$me->{SERVER}/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $vals[$fields{AVAIL_URL}] = $avail_url ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | my $trend_url = $report_type eq 'host' ? TREND_URL_TEMP_HOST : TREND_URL_TEMP_SVC ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $trend_url =~ s/HOST/$host/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | $trend_url =~ s/SVC/$svc/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | if $report_type eq 'service' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $trend_url =~ s/t1=T1&t2=T2/t1=$t1&t2=$t2/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $trend_url =~ s/SERVER/$me->{SERVER}/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $vals[$fields{TREND_URL}] = $trend_url ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my %F ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | @F{@fieldnames} = @vals ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | unless $pre_filter->(%F) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | push @avail_report, [ @vals ] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $me->{AVAIL_REPORTS}{$rep_period} = [ @avail_report ] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | bless $me, ref($class) || $class ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition16%1/6
ref $class || $class
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # Runs while object 'loads' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # Creates accessors for the callers convenience. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # XXX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # This class will _not_ use the accessors itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # since it doesn't believe it will be inherited from. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 15 | foreach my $acc (qw(FIELDS FIELDNAMES REPORT_PERIODS T1 T2 SERVER AVAIL_REPORTS REPORTS DATA_SOURCE SOURCE_TAG REPORT_TYPE)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 15 | ▶ | no strict 'refs' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | *$acc = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $me = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | $me->{$acc} = @_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | if @_ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $me->{$acc} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 165 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 4 | ▶ | sub mkreport { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mkreport: called CC=23 SCAR=37.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | my ($me, $these_fields, $select_these, $this_order, $alter, $add_downs) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # $these_fields: fields which will appear in output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # in the same order as specified (in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # the array pointed to). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # $select_these: callback specifying which records | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # to report on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # $this_order : callback for sort to order the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # records. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # $alter : callback to add fields to or other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # wise mangle a record. Should return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # the names of any added fields. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # $add_downs : duplicate the rec by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # number of outage recs, appending | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # time down, up and outage duration. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # XXX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # $these_fields should specify the names and orders | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | # of any fields added by $alter->(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 4 | my $usage =<<'USAGE' ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | mkreport( $these_fields, $select_these, $this_order, $alter, $add_downs ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | $these_fields := optional array ref enumerating the fields, and there order to appear in the report. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | $select_these := optional callback returning true if the availability record is to appear in the report. Called | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | with pairs of all fields and values for this record. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | $this_order := optional callback specifiying sort order. Called with pairs of all fieldnames and their offsets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | $alter := optional callback that munges fields (transforming field values or adding new fields). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | $add_downs := optional flag. If set, each availability record is duplicated by the number of outage records, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | and the time down, time up and duration of the outage is appended to each record. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 4 | ▶ | die $usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$these_fields and ref $these_fields ne "ARRAY"
MC/DC0%0/2
$these_fields and ref $these_fields ne "ARRAY"
$these_fields
ref $these_fields ne "ARRAY"
Truth table33%1/3
A and B
A= $these_fieldsB= ref $these_fields ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | if $these_fields and ref($these_fields) ne 'ARRAY' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | ▶ | die $usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$select_these and ref $select_these ne "CODE"
MC/DC0%0/2
$select_these and ref $select_these ne "CODE"
$select_these
ref $select_these ne "CODE"
Truth table33%1/3
A and B
A= $select_theseB= ref $select_these ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | if $select_these and ref($select_these) ne 'CODE' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 4 | ▶ | die $usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$this_order and ref $this_order ne "CODE"
MC/DC0%0/2
$this_order and ref $this_order ne "CODE"
$this_order
ref $this_order ne "CODE"
Truth table33%1/3
A and B
A= $this_orderB= ref $this_order ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | if $this_order and ref($this_order) ne 'CODE' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | ▶ | die $usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$alter and ref $alter ne "CODE"
MC/DC0%0/2
$alter and ref $alter ne "CODE"
$alter
ref $alter ne "CODE"
Truth table33%1/3
A and B
A= $alterB= ref $alter ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | if $alter and ref($alter) ne 'CODE' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 4 | ▶ | $these_fields ||= [] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$these_fields ||= []
MC/DC0%0/1
$these_fields ||= []
$these_fields
Truth table50%1/2
A
A= $these_fields
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | $select_these ||= sub { 1 } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$select_these ||= sub {
1;
}
MC/DC0%0/2
$select_these ||= sub {
1;
}
$select_these
sub {
1;
}
Truth table33%1/3
A ||= B
A= $select_theseB= sub {
1;
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | $this_order ||= sub { my %f = @_ ; $a->[$f{HOST_NAME}] cmp $b->[$f{HOST_NAME}] } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Condition33%1/3
$this_order ||= sub {
my(%f) = @_;
$$a[$f{"HOST_NAME"}] cmp $$b[$f{"HOST_NAME"}];
}
MC/DC0%0/2
$this_order ||= sub {
my(%f) = @_;
$$a[$f{"HOST_NAME"}] cmp $$b[$f{"HOST_NAME"}];
}
$this_order
sub {
my(%f) = @_;
$$a[$f{"HOST_NAME"}] cmp $$b[$f{"HOST_NAME"}];
}
Truth table33%1/3
A ||= B
A= $this_orderB= sub {
my(%f) = @_;
$$a[$f{"HOST_NAME"}] cmp $$b[$f{"HOST_NAME"}];
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | my @field_names = scalar(@$these_fields) ? @$these_fields : @{ $me->{FIELDNAMES} } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 4 | my @fieldnames = @{ $me->{FIELDNAMES} } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 4 | my %fields = %{ $me->{FIELDS} } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | $me->{REPORTS}{$_}{RECORDS} = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 4 | foreach keys %{ $me->{AVAIL_REPORTS} } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # slice | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # sort | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | # filter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # alter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # add_downs list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # Do the transforms - to add | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # fields - first, and then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # update the fieldnames so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # the new fields can be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # to select and sort. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | foreach my $rep ( keys %{ $me->{AVAIL_REPORTS} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 4 | my (%F, @r, @avail_recs, $avail_url) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 4 | @avail_recs = @{ $me->{AVAIL_REPORTS}{$rep} } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 4 | ▶ | unless @avail_recs ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 4 | @r = shift @avail_recs ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | $add_downs = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 4 | ▶ | unless $me->{SOURCE_TAG} =~ /^(?:web_page|local_cgi)/ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 4 | ▶ | if ( $add_downs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my @ofn = qw(DOWN UP OUTAGE) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | push @fieldnames, @ofn ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | # The new fields are added to the list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # of those appearing in the report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | push @field_names, @ofn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | unless grep $_ eq $ofn[0], @field_names ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | @r = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | map { get_downs($_, $me->{DATA_SOURCE}, $_->[$fields{AVAIL_URL}], $me->{T1}) } shift @r ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 4 | ▶ | if ( $alter ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 4 | my @downs = @r ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 4 | @F{@fieldnames} = @{$r[0]} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # XXX - don't modify the rec, only get the added fields. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 4 | my @afn = $alter->(\%F) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # my @afn = $alter->($r[0], \%F) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # my @afn = $alter->($r[0], %F) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 4 | push @fieldnames, @afn ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 4 | ▶ | push @field_names, @afn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | unless grep $_ eq $afn[0], @field_names ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | @r = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 4 | map { @F{@fieldnames} = @$_; $alter->(\%F); [ @F{@fieldnames} ] } @downs ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 4 | $me->{FIELDNAMES} = [ @fieldnames ] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 4 | @fields{@fieldnames}= 0 .. $#fieldnames ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 4 | $me->{FIELDS} = { %fields } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # Transform rec by adding or munging fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # NB, the one attempt I made to move the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # tests outside map actually slowed the benchmark | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # 'make tests'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | push @r, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 268 | @F{@fieldnames} = @$_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 268 | ▶ | $alter->(\%F) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | if $alter ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 268 | [ @F{@fieldnames} ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 4 | $add_downs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | ? get_downs($_, $me->{DATA_SOURCE}, $_->[$fields{AVAIL_URL}], $me->{T1}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 268 | ▶ | : $_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | @avail_recs ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # Slice | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 272 | my @rep = map [ @{$_}[@fields{@field_names}] ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # Sort | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 728 | sort { $this_order->(%fields) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # Filter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 4 | grep { @F{@{$me->{FIELDNAMES}}} = @$_; $select_these->(%F) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | @r ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 4 | $me->{REPORTS}{$rep}{RECORDS} = [ @rep ] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 4 | $me->{REPORTS}{$rep}{FIELDNAMES} = [ @field_names ] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | sub excel_dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
excel_dump: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | my ($me, $excel_filename, $chart_details) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | eval { require Spreadsheet::WriteExcel } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | die "John McNamara's _excellent_ CPAN module, Spreadsheet::WriteExcel is needed by excel_dump(). Outahere. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | if $@ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | my $workbook = Spreadsheet::WriteExcel->new($excel_filename || EXCEL_FILENAME) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$excel_filename || './Nagios_Avail.xls'
MC/DC0%0/1
$excel_filename || './Nagios_Avail.xls'
$excel_filename
Truth table0%0/2
A
A= $excel_filename
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | die "Spreadsheet::WriteExcel constructor failed, prob opening '$excel_filename': $!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | unless $workbook ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my $format = $workbook->add_format() ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $format->set_bold() ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | foreach my $rep (@{ $me->{REPORT_PERIODS} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my $down_times = $me->{REPORTS}{$rep}{RECORDS} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my $worksheet = $workbook->addworksheet($rep) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | my @max_col_width = () ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # The general syntax is write($row, $column, $token). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # Note that row and column are zero indexed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | my ($row, $col) = (0, 0) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # XXX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | # Scan all data to determine widest column. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | # The column width needs to be set before any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # cells are written. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | foreach my $c ( @{ $me->{REPORTS}{$rep}{FIELDNAMES} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | $max_col_width[$col++] = 1.5 * length($c) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # Fieldnames are bold so are wider than usual. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | foreach my $r (@$down_times) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | $col = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | foreach my $c (@$r) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | my $h ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | # XXX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | # Set col width to width of label _not_ the URL. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | my $len = (($h) = $c =~ m#^http://.+?host=([^&]+)&#) ? length($h) : length($c) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | $max_col_width[$col] = $len | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | if $len >= $max_col_width[$col] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $col++ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | $col = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | foreach my $c ( @{ $me->{REPORTS}{$rep}{FIELDNAMES} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | $worksheet->set_column($col, $col, $max_col_width[$col]) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | $worksheet->write(0, $col, $c, $format) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $col++ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | $row = 1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | foreach my $r (@$down_times) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | $col = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | foreach my $c ( @$r ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | if ( my ($h) = $c =~ m#^http://.+?host=([^&]+)&# ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | $worksheet->write_url($row, $col, $c, $h ? $h : "URL without hostname: $c") ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | $worksheet->write($row, $col, $c) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | $col++ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | $row++ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | &add_chart($workbook, $chart_details) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | if $chart_details ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | sub csv_dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
csv_dump: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | my $me = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | foreach my $rep (@{ $me->{REPORT_PERIODS} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | print "==> $rep reporting period.\n" ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | my $down_times = $me->{REPORTS}{$rep}{RECORDS} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | join(',', @{ $me->{REPORTS}{$rep}{FIELDNAMES} }), "\n" ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | foreach my $r ( @{$down_times} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | join(',', @$r), "\n" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | print "\n\n" ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 4 | ▶ | sub debug_dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug_dump: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 4 | my ($me, $field_width, $fields_per_line) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 4 | ▶ | $field_width ||= 15 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$field_width ||= 15
MC/DC0%0/1
$field_width ||= 15
$field_width
Truth table50%1/2
A
A= $field_width
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 4 | ▶ | $fields_per_line||= 7 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fields_per_line ||= 7
MC/DC0%0/1
$fields_per_line ||= 7
$fields_per_line
Truth table50%1/2
A
A= $fields_per_line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 4 | my $format = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 4 | foreach my $rep (@{ $me->{REPORT_PERIODS} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | format STDOUT_TOP = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | $rep | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 4 | $- = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 4 | my @line ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 24 | @line = map { my $x = $_ ; $x =~ s/PERCENT/%/; $x } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 4 | @{ $me->{REPORTS}{$rep}{FIELDNAMES} } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 4 | ▶ | &mkform($field_width, $fields_per_line, @line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | unless $format++ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 4 | &do_write(@line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 4 | foreach my $r ( @{ $me->{REPORTS}{$rep}{RECORDS} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 272 | @line = @$r ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 272 | &do_write(@line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 15 | my @base = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | { b => 60, u => 's' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | { b => 60, u => 'm' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | { b => 24, u => 'h' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | { b => 7, u => 'd' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | { b => 4, u => 'w' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | { b => 12, u => 'm' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 575 | ▶ | sub time2ddhhmmss { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
time2ddhhmmss: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # Rounds arg to nearest 5 minute interval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # and returns hhmmss string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 575 | my $d = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 575 | $d += 150 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 575 | $d = int($d/300) * 300 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 575 | ▶ | return ' ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | unless $d ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 126 | my ($s, $r, $i) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 126 | $s = ' ' ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 126 | ▶ | for ($i = 0; $d > 0; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 338 | $r = $d % $base[$i]{b} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 338 | ▶ | $s = "${r}$base[$i]{u} $s" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | if $r > 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 338 | $d = ($d - $r) / $base[$i]{b} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 126 | $s ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 15 | ▶ | sub mkform { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mkform: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 4 | my ($field_width, $fields_per_line) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 4 | my ($pics, $vals, $f1, $f, $form_body) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 4 | $f1 = '@' . '<' x 24 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 4 | $f = '@' . '<' x $field_width ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 4 | $pics = $f1 . " $f" x ($fields_per_line - 1) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 4 | $vals = 'shift(@_), ' x $fields_per_line ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 4 | $form_body = "format STDOUT = \n" ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 4 | $form_body .= <<EOFORM ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | $pics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | $vals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | EOFORM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 4 | my $fields_remaining = @_ - $fields_per_line ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 4 | ▶ | if ( $fields_remaining <= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | $form_body .= <<EOFORM ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | EOFORM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | eval $form_body ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 4 | my $lines_remaining = int($fields_remaining / ($fields_per_line - 1)) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 4 | my $fields_on_last_line = $fields_remaining % ($fields_per_line - 1) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 4 | my $spaces = ' ' x 25 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 4 | $pics = $spaces . " $f" x ($fields_per_line - 1) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 4 | $vals = $spaces . ' shift(@_), ' x ($fields_per_line - 1) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 4 | $form_body .= <<EOFORM x $lines_remaining ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | $pics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | $vals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | EOFORM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 4 | $pics = $spaces . " $f" x $fields_on_last_line ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 4 | $vals = $spaces . ' shift(@_), ' x $fields_on_last_line ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 4 | $form_body .= <<EOFORM ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | $pics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | $vals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | EOFORM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 4 | eval $form_body ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 276 | ▶ | sub do_write { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_write: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | # Only exists to get vals into @_ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 276 | write ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 1195 | ▶ | sub max_l { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_l: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | # my $max = shift @_ or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 1195 | ▶ | unless @_ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 1194 | my $max = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 1194 | local $_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 1194 | ▶ | while ( defined($_ = shift @_) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 1218 | ▶ | $max = $_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | if $_ >= $max | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 1194 | $max ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 4 | ▶ | sub comp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
comp: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | # Returns a comparator function to sort the avail records | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | # Call with (alpha => 0|1, ascend => 0|1, fields =. [ f1.. ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 4 | my %sort_parms = (%default_sort, @_) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # eg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | # alpha => 0, $ascend => 1, fields = [TOTAL_TIME_DOWN, TOTAL_TIME_UNREACH] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | # TIME_DOWN and TIME_UNREACH are the same to the reader of the report; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | # they should be consolidated with some consolidation function (eg max | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | # or sum of values). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 4 | my $r ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 4 | ▶ | if ( $sort_parms{alpha} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | $r = $sort_parms{ascend} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 67 | ▶ | ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 67 | my %f = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | # package Nagios::Report ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 67 | $a->[$f{HOST_NAME}] cmp $b->[$f{HOST_NAME}] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 67 | ▶ | : sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 67 | my %f = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | # package Nagios::Report ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 67 | $b->[$f{HOST_NAME}] cmp $a->[$f{HOST_NAME}] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 2 | ▶ | } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 2 | return $r ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 2 | my $fields = $sort_parms{fields} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | $r = $sort_parms{ascend} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 316 | ▶ | ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 316 | my %f = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 316 | my @field_indices = @f{@$fields} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 316 | my $a_max = &max_l( @{$a}[@field_indices] ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 316 | my $b_max = &max_l( @{$b}[@field_indices] ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 316 | $a_max <=> $b_max ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 278 | ▶ | : sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 278 | my %f = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 278 | my @field_indices = @f{@$fields} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 278 | my $a_max = &max_l( @{$a}[@field_indices] ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 278 | my $b_max = &max_l( @{$b}[@field_indices] ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 278 | $b_max <=> $a_max ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 2 | ▶ | } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 2 | return $r ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | ▶ | sub gen_local_cgi { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_local_cgi: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | my $user = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | # Generate a closure that will get an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | # availability report by running the CGI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | # from the shell. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | ▶ | die "gen_local_cgi() called without username for access to local availability CGI: \$user: '$user'. Caller " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | . join(' ', caller) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | unless $user ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 0 | $ENV{REMOTE_USER} = $user ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | $ENV{REQUEST_METHOD} = REQUEST_METHOD ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | my $url = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | # Must convert URL to query_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | my $qs ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | ($qs = $url) =~ s|http:.*?\?|| ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | $ENV{QUERY_STRING} = $qs ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 0 | my @x = `${\NAG_AVAIL_CGI}` ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | # Drop HTTP headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | splice @x, 0, 6 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | chomp @x ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 0 | ▶ | wantarray ? @x : join('', @x) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | ▶ | sub gen_web_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_web_page: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | my ($user, $pass) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 0 | ▶ | die "gen_web_page() called without username or password for web page access: \$user: '$user', \$pass: '$pass'." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$user and $pass
MC/DC0%0/2
$user and $pass
$user
$pass
Truth table0%0/3
A and B
A= $userB= $pass
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | . ' Caller ' . join(' ', caller) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | unless $user && $pass ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | # lynx -dump will render the page as text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | # regardless of its content. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | USE_LYNX ? `${\LYNX} -nolist -dump -width=1000 -auth=$user:$pass '$_[0]'` | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | : `${\WGET} --output-document=- --http-user=$user --http-passwd=$pass '$_[0]' 2>/dev/null` ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | ▶ | sub down_records { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
down_records: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | my ($data_source, $avail_url, $start_time) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | my $avail_rep = $data_source->($avail_url) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | my ($downs, @down_recs, @downs) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | ▶ | if ( $avail_rep =~ /<html>/i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | # XXX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | # Will fail if the availability CGI contains | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | # different tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | # <tr class='logEntriesEven'> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | # <td class='logEntriesEven'>01-11-2005 00:00:00</td> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | # <td class='logEntriesEven'>09-11-2005 15:09:59</td> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | # <td class='logEntriesEven'>8d 15h 9m 59s</td> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | # <td class='logEntriesUP'>HOST UP (HARD)</td> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | ($downs) = $avail_rep =~ /(<tr class='logEntriesEven'>.*)/s ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 0 | my @rows = $downs =~ m|(<tr.*?/tr>)|g ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | @down_recs = map { s/<.*?>/ /g; $_ } @rows ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | # Parsed HTML (by lynx -dump) looks like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | # 01-11-2005 00:00:00 09-11-2005 15:09:59 8d 15h 9m 59s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # HOST UP (HARD) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | ($downs) = $avail_rep =~ m|( \d+-\d+-\d+ \s+ \d+:\d+:\d+ \s+ \d+-\d+-\d+ \s+ \d+:\d+:\d+ .* \Z) |msx ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | @down_recs = split /\n/, $downs ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | local $_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | foreach (@down_recs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | =begin comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | # Must also deal with scheduled downtime. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 01-02-2006 00:00:00 01-02-2006 14:27:54 0d 14h 27m 54s HOST UP (HARD) PING OK - Packet loss = 0%, RTA = 7.26 ms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 02-02-2006 20:24:42 02-02-2006 20:24:42 0d 0h 0m 0s HOST DOWN (HARD) CRITICAL - Plugin timed out after 10 seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | VVVV This appears to be the correct entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 02-02-2006 20:24:42 02-02-2006 20:47:54 0d 0h 23m 12s HOST DOWNTIME START Start of scheduled downtime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | ^^^^ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 02-02-2006 20:47:54 02-02-2006 22:24:42 0d 1h 36m 48s HOST UP (HARD) PING OK - Packet loss = 0%, RTA = 0.66 ms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 02-02-2006 22:24:42 03-02-2006 12:54:29 0d 14h 29m 47s HOST DOWNTIME END End of scheduled downtime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | =end comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | ▶ | if /HOST UP|SERVICE OK|HOST DOWNTIME END/ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | my ($down, $up, $outage) = / | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | (\d+-\d+-\d+ \s+ \d+:\d+:\d+) \s+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | (\d+-\d+-\d+ \s+ \d+:\d+:\d+) \s+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | ( (?:\d+[wdhms] \s*)+ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | /x ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | if &before_start($down, $start_time) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | $outage =~ s/^(?:0[wdh] )*//g ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | push @downs, [$down, $up, $outage] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | ▶ | @downs = ( [ (' ') x 3 ] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | unless @downs ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | @downs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 3 | ▶ | sub before_start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
before_start: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 3 | my ($t1_str, $t2) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 3 | my $t1 = &date2time($t1_str) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 3 | ▶ | return $t1 < $t2 ? 1 : 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 3 | ▶ | sub date2time { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date2time: called CC=4 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 3 | local $_ = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 3 | my ($dd, $mm, $mon, $yyyy, $h, $m, $s) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 3 | ▶ | if ( ($dd, $mm, $yyyy, $h, $m, $s) = m< (\d+)-(\d+)-(\d+) \s+ (\d+):(\d+):(\d+) >x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | # 01-11-2005 00:00:00 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | # DD-MM-YYYY HH:MM:SS Euro style dates with day first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 3 | return EURO_DATE ? timelocal($s, $m, $h, $dd, $mm - 1, $yyyy) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | # MM-DD-YYYY HH:MM:SS US style dates with month first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | : timelocal($s, $m, $h, $mm, $dd - 1, $yyyy) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | } elsif ( ($mon, $dd, $h, $m, $s, $yyyy) = /\w{3} (\w{3})\s+(\d+) (\d+):(\d+):(\d+) \w{3} (\d{4})/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | # Tue Nov 29 20:19:17 EST 2005 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 0 | $mon = "\u\L$mon" ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | $mm = MONTH->{$mon} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | return timelocal($s, $m, $h, $dd, $mm - 1, $yyyy) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | } elsif ( /now/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | return time() + 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | sub interval2time { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interval2time: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | local $_ = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | my $t = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 0 | foreach my $x ( /(\d+[wdhms])/g ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | # XXX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | # Would be nice to do this without two matches but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | # /g only counts the first match not the pair. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | my ($u, $b) = $x =~ /(\d+)([wdhms])/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 0 | $t += T->{$b} * $u ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 0 | return $t ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | ▶ | sub get_downs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_downs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 0 | my $r = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | my @downs = &down_records(@_) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | my @r = map [ @$r, @$_ ], @downs ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | @r ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | ▶ | sub avail { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
avail: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | my ($me, $rep_period) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | ▶ | $rep_period ||= '24x7' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rep_period ||= "24x7"
MC/DC0%0/1
$rep_period ||= "24x7"
$rep_period
Truth table0%0/2
A
A= $rep_period
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | die "Non existent report period '$rep_period': choose from " . join(' ', keys %{$me->{AVAIL_REPORTS}}) . '. Outahere.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | ▶ | unless exists $me->{AVAIL_REPORTS}{$rep_period} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 0 | my @avail_recs = @{ $me->{AVAIL_REPORTS}{$rep_period} } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | ? @avail_recs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | ▶ | : Iterator { shift @avail_recs ; } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | ▶ | sub report { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | my ($me, $rep_period) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 0 | ▶ | $rep_period ||= '24x7' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rep_period ||= "24x7"
MC/DC0%0/1
$rep_period ||= "24x7"
$rep_period
Truth table0%0/2
A
A= $rep_period
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 0 | die "Non existent report period '$rep_period': choose from " . join(' ', keys %{$me->{REPORTS}}) . '. Outahere.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | ▶ | unless exists $me->{REPORTS}{$rep_period} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | my @report_recs = @{ $me->{REPORTS}{$rep_period}{RECORDS} } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | ? @report_recs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 0 | ▶ | : Iterator { shift @report_recs ; } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | ▶ | sub to_dbh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_dbh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | my $me = shift @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 0 | eval { require DBI } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | die "Jeff Zuckers's _excellent_ CPAN module, DBI is needed by to_dbh(). Outahere. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | if $@ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 0 | my @dbh = () ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | # Fruitless attempts to silence DBI - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | # this appears to be a known issue of DBD::AnyData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | # as of Mar 2006. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | # local $SIG{__WARN__} = sub {} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | foreach my $rep_period ( @{$me->REPORT_PERIODS} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | my $dbh = DBI->connect('dbi:AnyData:') ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | # my $dbh = DBI->connect('dbi:AnyData(Warn => 0, ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | # Also fails to check warnings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | $dbh->func( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | "tab_${rep_period}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 'ARRAY', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | $me->{AVAIL_REPORTS}{$rep_period}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | # [ $me->avail($rep_period) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 0 | { col_names => join(',', @{$me->FIELDNAMES}) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 'ad_import' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 0 | push @dbh, $dbh ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 0 | @dbh ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 0 | ▶ | sub add_chart { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_chart: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 0 | my ($wkbook, $chart) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 0 | ▶ | die "add_chart() called without hash ref to chart details eg { template => '/path/to/chart/template', link => .. }. Outahere." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | unless ref($chart) eq 'HASH' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | die "add_chart() called without a well formed 'template' value in \$chart_detail. Must be to a filename containing the Chart template. Outahere." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | ▶ | unless exists($chart->{template}) && $chart->{template} && -e $chart->{template} && -s $chart->{template} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
exists $chart->{"template"} and $chart->{"template"} and -e $chart->{"template"} and -s $chart->{"template"}
exists $chart->{"template"} and $chart->{"template"} and -e $chart->{"template"}
exists $chart->{"template"} and $chart->{"template"}
MC/DC0%0/4
exists $chart->{"template"} and $chart->{"template"} and -e $chart->{"template"} and -s $chart->{"template"}
exists $chart->{"template"}
$chart->{"template"}
-e $chart->{"template"}
-s $chart->{"template"}
Truth table0%0/5
A and B and C and D
A= exists $chart->{"template"}B= $chart->{"template"}C= -e $chart->{"template"}D= -s $chart->{"template"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | # Add some extra formats to cover formats used in the charts. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | $wkbook->add_format(color => 1, bold => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 0 | $wkbook->add_format(color => 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | $wkbook->add_format(color => 3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 0 | ▶ | $chart->{title} ||= 'Chart 24x7' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$chart->{"title"} ||= "Chart 24x7"
MC/DC0%0/1
$chart->{"title"} ||= "Chart 24x7"
$chart->{"title"}
Truth table0%0/2
A
A= $chart->{"title"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | ▶ | $chart->{link} ||= '=24x7!A1' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$chart->{"link"} ||= "=24x7!A1"
MC/DC0%0/1
$chart->{"link"} ||= "=24x7!A1"
$chart->{"link"}
Truth table0%0/2
A
A= $chart->{"link"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | $wkbook->add_chart_ext($chart->{template}, $chart->{title}) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | $wkbook->sheets(0)->store_formula($chart->{link}) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 15 | 1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | # ---> That's all folks <----- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | Nagios::Report - Perl class to filter and munge Nagios availability data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | use Nagios::Report ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | my $x = Nagios::Report->new(q<local_cgi nagios_web_server nagios_user>, [ '24x7' ], 'thismonth') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | or die "Can't construct Nagios::Report object." ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | my @these_fields = qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | HOST_NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | PERCENT_TOTAL_TIME_UP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | TOTAL_TIME_DOWN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | TIME_DOWN_HHMMSS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | TOTAL_TIME_UNREACHABLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | TIME_UNREACH_HHMMSS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | AVAIL_URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | TREND_URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | $x->mkreport( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | # Field selector; display these fields only (in the listed order) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | # [] means display all the fields. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | \@these_fields, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | # Record selector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | # Called with @_ loaded # with a list of field names and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | # their vals for this record. Usually copied to a hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | # so it can be used as one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | # All records | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | # sub { 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | # All records whose HOST_NAME starts with 'Alb' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | # sub { my %F = @_; my $h = $F{HOST_NAME}; $h =~ /^Alb/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | # Regrettably, this is _NOT_ the same since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | # @_ can't be used as a hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | # sub { $_{HOST_NAME} =~ /^Alb/ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | # All records with an up time percent < 98% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | sub { my %F = @_; my $u = $F{PERCENT_TOTAL_TIME_UP}; $u =~ s/%//; $u < 98 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | # Sort order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | &comp( alpha => 0, ascend => 0, fields => [ qw(TOTAL_TIME_DOWN TOTAL_TIME_UNREACHABLE) ]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | # Sorts descending by max of TOTAL_TIME_DOWN and TOTAL_TIME_UNREACHABLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | # DIY sorters remember that $a and $b _must_ be in Nagios::Report package. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | # eg by TOTAL_DOWN_TIME descending. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | # sub { my %f = @_ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | # package Nagios::Report; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | # $b->[$f{TOTAL_TIME_DOWN}] <=> $a->[$f{TOTAL_TIME_DOWN}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | # }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | # Same as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | # &comp(alpha => 0, ascend => 0, fields => ['TOTAL_TIME_DOWN']) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | # Same but harder, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | # sub { package Nagios::Report; $b->[16] <=> $a->[16] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | # Optional callback to add or mangle fields. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | # Add 2 fields for downtime vals in hours minutes and secs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | sub { $F = shift @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | $F->{TIME_DOWN_HHMMSS} = t2hms( $F->{TOTAL_TIME_DOWN} ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | $F->{TIME_UNREACH_HHMMSS}= t2hms( $F->{TOTAL_TIME_UNREACHABLE} ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | qw(TIME_DOWN_HHMMSS TIME_UNREACH_HHMMSS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | $x->debug_dump ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | # $x->csv_dump ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | Gets the Nagios (http://wwww.Nagios.ORG/) B<All Hosts or Services> availability report (getting the results in CSV format) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | and applies grep like filters, map like munging, and slice like field masks to produce a report which can be output in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | various ways. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | This class provides extra control over the content and disposition of the data produced by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | Nagios availability CGI, by writing for example a spreadsheet containing the selected data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | Since the data originates from standard Nagios availability CGI, its results are no more accurate - and should be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | exactly the same - as that CGI. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | =item * new (DATA_SOURCE, REPORT_PERIODS, TIME_PERIOD, HOST_OR_SERVICE, PRE_FILTER) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | This is the constructor of the Nagios::Report object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | C<DATA_SOURCE> is one of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 1 local_cgi - get the data by running the availability report CGI on the local host. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | Space separated values of the Nagios web server name/address and a Nagios user should follow. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 2 web_page - get the data with LYNX or WGET from the named web server with the credential. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | Space separated values of the Nagios web server name/address, a Nagios user and that users password | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | should follow. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | 3 dev_debug - get __development__ data by running a client supplied callback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | The _name_ of the callback should follow the tag, separated by spaces. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | NB the callback is assumed to be in the __main__ package. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | The callback is expected to return a string consisting of a schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | (of CSV fieldnames) followed by lines of CSV data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | C<REPORT_PERIODS> is an optional reference to a list of names of Nagios time periods (conventionally defined in timeperiods.cfg) for which the availability data will be computed (by the CGI). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | C<TIME_PERIOD> is an optional specification of the interval containing eligible availability records. It is scalar whose value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | is one of the Nagios interval names such as C<thisday>, C<thismonth>, or B<some> of the time forms used by the B<at> command. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | (These forms include HHMM, HH:MM, DD.MM.YYYY MM/DD/YYYY and 24hour-time date). It can also be a month abbreviation followed by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | any amount of white space and an optional 4 digit year. This form, like Mar 2006, selects all the days in that month. If the year | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | is missing, the month refers to this year. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | Usually the timeperiod specifies an interval from some time in the past to now from which availability data will be selected. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | However, if the argument is of the form B<start_24hour-time_date> B<-> B<end_24hour-time_date>, the availability data will be extracted from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | the corresponding interval. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | If this argument is omitted, the report is compiled for the B<thismonth> time period (ie any host availability record from the first of the current | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | month to the current time). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | C<HOST_OR_SERVICE> is an optional scalar specifying the service report instead of the host report. If not set, the host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | report is produced. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | C<PRE_FILTER> is a callback that is called with the B<%F> hash (vi) set to the values of the field names for this availability | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | record. The constructor saves the availability report for B<all> the hosts and therefore if mkreport() then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | requests the down records (vi), the availability CGI will be run for every host, whether or not the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | filter in mkreport() actually selects them. To eliminate this waste and speed up the report, supply a callback like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | sub { my %F = @_; $u = $F{PERCENT_TOTAL_TIME_UP}; $u =~ s/%//; $u < 99 } or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | sub { my %F = @_; $F{TOTAL_TIME_DOWN} >= 600 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | The constructor gets the Nagios availability data by running the all hosts or all services report (in CSV format) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | and storing it in the object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | =item * mkreport (FIELD_LIST, SELECTOR_CALLBACK, ORDER_CALLBACK, MUNGE_CALLBACK, DOWNS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | E<10> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | C<FIELD_LIST> is a reference to an array containing the field names that will appear in the report (a logical slice of the reports fields). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | The fields appear in the report in the same order they have in this list. Fields added by C<MUNGE_CALLBACK> B<must> be specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | by C<FIELD_LIST> or they will not be shown in the report B<unless> this parameter is omitted. If the C<FIELD_LIST> is omitted, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | B<all> the fields appear in the report, no matter where they come from (ie if fields are added by the C<MUNGE_CALLBACK>, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | new fields will appear in the report). If a field in C<FIELD_LIST> does not exist in the schema, it will not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | appear in the report; the caller B<must> spell the field names correctly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | C<SELECTOR_CALLBACK> is a reference to a user supplied subroutine that will return B<true> if the record is to be included in the report. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | The subroutine is called with an argument list of field names and their values for this record. This argument list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | can be copied to a hash in the callback, conventionally named B<%F>, so that the field names can be used in expressions like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | $F{HOST_NAME} =~ /^foo/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | to select eligible records. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | C<ORDER_CALLBACK> is a reference to a user supplied sort subroutine that determines the order of the records in the report. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | subroutine is called with an argument list of field names and their offsets in the records (eg (HOST_NAME, 0)). This argument list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | can be copied to a hash in the callback, conventionally named B<%f>, so that the field names can be used in expressions like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | $a->[$f{TOTAL_TIME_DOWN}] <=> $b->[$f{TOTAL_TIME_DOWN}] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | to sort the records based on the field values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | C<MUNGE_CALLBACK> is a reference to a user supplied subroutine that is used to munge (transform input to output) the records. The subroutine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | is called with a pointer to a hash of field names and their values for this record. The callback is expected to modify the record | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | by setting the values of this hash, munging fields with expressions like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | $F->{TOTAL_TIME_DOWN} = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | If the callback adds fields to the record, it should add the new field value in the same way (by setting a value for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | a new key in the hash, like for example, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | $F->{TOTAL_TIME_DOWN_HMS} = t2hms($F->{TOTAL_TIME_DOWN}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | ). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | If the callback adds no fields (modifies values only), it B<must> return an empty list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | A complete callback to set TOTAL_TIME_DOWN to zero is therefore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | my $F = shift @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | $F->{TOTAL_TIME_DOWN} = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | mkreport() takes the availability data for each time period, adds outage data (which involves duplicating the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | C<original> availability record as many times as there are outages), does any specified munging, applies the filter discarding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | records not rated as C<interesting> by the selector callback, before sorting and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | slicing the results - dropping fields unwanted fields - and storing them as a C<report> for each time period. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | mkreport() must be run before any of the output methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | C<DOWNS> is an optional scalar flag. If the flag is set the availability | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | report - the detailed report with the outage log - for B<each> host is fetched and the outage records extracted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | Then, for each of the outage records, the availability record is duplicated followed by the outage data: when the host went down, when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | it came back up, and the hours minutes seconds formatted value of the outage. These fields are named DOWN, UP, and OUTAGE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | Since the availability data is repeated for each outage record, C<DOWNS> can make the report look messy. It is best used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | with a small number of report fields (eg HOST_NAME, PERCENT_TOTAL_UP_TIME). Also, since the outage records are added B<before> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | filtering by the selector callback, you B<should> set a pre-filter in the constructor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | The callbacks are run in this order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | =item 1 DOWNS (the availability report is retrieved for B<all> hosts/services so that the selector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | can filter on the added fields, by for example, discarding all records with small outages). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | =item 2 MUNGE_CALLBACK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | =item 3 SELECTOR_CALLBACK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | =item 4 ORDER_CALLBACK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | =item 5 the field slice (ie discard all but the FIELD_LIST fields) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | =item * to_dbh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | If the DBD::AnyData module is installed, returns an array of DBI data handles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | connected to the pseudo-databases containing one table populated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | with the availability data corresponding to each of the REPORT_PERIODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | specified in the constructor call. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | Each table is named C<tab_REPORT_PERIOD>. For example, after constructing the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | Nagios::Report object with the default report period, the table is named B<tab_24x7>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | This method allows the use of SQL statements as an alternative means of filtering | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | and modifying the data. For example, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | $SQL =<<SQL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | SELECT host_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | total_time_down, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | time_down_scheduled, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | time_down_unscheduled, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | FROM tab_24x7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | WHERE total_time_down >= 300 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | SQL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | $x = Nagios::Report->new(local_cgi Nagios-server Nagios-contact) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | ($d) = $x->to_dbh ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | $s = $d->prepare($SQL) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | $s->execute ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | $s->dump_results ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | Unfortunately, the use of DBD::AnyData does not invalidate this module because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | the SQL grammar implemented by SQL::Statement (and used by DBD::AnyData) is not as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | extensive as the SQL grammar provided by an RDBMS, or as useful as the record selector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | mechanism provided by this. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | If one is determined to process with SELECT, load the data into an RDBMS of choice ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | MySQL comes to mind) and use the corresponding Perl DBD module on that. There is an example of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | a script to do so included in the distribution. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | Also, as of version 0.002, there were noisy complaints from DBI when DBD::AnyData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | processes SQL. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | =item * excel_dump (EXCEL_FILENAME, CHART_DETAIL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | excel_dump writes a Workbook in the specified filename. The workbook contains a worksheet for each report (ie one for each time period | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | specified by the constructor). excel_dump() requires the John McNamara's B<excellent> CPAN module, Spreadsheet::WriteExcel. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | E<10> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | C<EXCEL_FILENAME> is the path of the file in which the Excel workbook will be written. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | C<CHART_DETAIL> is an optional reference to a hash that specifies the details of an Excel Chart that will be linked to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | data from the report. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | The keys of his hash are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | E<10> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | template - the path to a binary file, produced by the Spreadsheet::WriteExcel chartex utility, containing the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | chart to be linked to the data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | link - an optional scalar that specifies the data to be linked to the chart. Defaults to "q<'24x7'!A1>". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | You almost certainly will need to change this. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | title - an optional scalar that specifies the name of the chart to be added to the workbook. Defaults to '24x7 Chart'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | Note that only one chart can be added to a workbook (by this module). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | =item * csv_dump | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | CSV formatted output on STDOUT. Note that this mainly useful for debugging since the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | cell data is not formatted should it be imported by Excel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | =item * dev_debug (FIELD_WIDTH, FIELDS_PER_LINE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | report formatted output on STDOUT. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | =head1 ACCESSORS/MUTATORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | Acessors and mutators are provided for most of the attributes in the object. The module makes B<no> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | use of them and, except for those below, are probably of little interest. Unless noted, the caller is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | responsible for processing the attribute type correctly; the acessor does nothing more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | than hand back a ref. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | =item * report (REPORT_PERIOD) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | Accessor that returns, in scalar context, an iterator that when kicked returns each of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | records produced by mkreport() for that report period; in array context, returns the list of those records. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | Note that the 'records' are refs to anonymous lists containing only those fields specified by the field list parameter of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | mkreport(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | =item * avail (REPORT_PERIOD) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | Accessor that returns, in scalar context, an iterator that when kicked returns each of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | records returned by the constructor; in array context, returns the list of those records. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | Note that the 'records' are refs to anonymous lists containing all of the Nagios availability report fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | augmented by the two extra fields AVAIL_URL and TREND_URL (vi). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | The iterator is a code ref that, when called, will return a ref to the next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | availability record. Without a REPORT_PERIOD, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | returns an iterator to the B<24x7> data, otherwise the availability data corresponding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | to that report period (if it exists). If the methods of this class are not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | useful, then the iterator allows the caller transform the availability data with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | B<imap> and filter it with B<igrep>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | =item * FIELDNAMES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | Ref to a list of field names eg @fields = @{$me->FIELDNAMES} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | =item * FIELDS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | Ref to a hash of field indices keyed by field name eg %f = %{$me->FIELDS}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | =item * SERVER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | Hostname of the server on which the Nagios CGIs can be found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | =item * SOURCE_TAG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | How the availability data will be fetched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | =item * REPORT_TYPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | host | service report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | =item * DATA_SOURCE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | Reference to a subroutine that will fetch the availability data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | =item * REPORTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | Ref to a hash keyed by report period containing a hash keyed by FIELDNAMES and RECORDS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | The latter key refers to a list containing the records selected and munged by mkreport(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | Note that each record contains only those fields specified by the field list parm of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | mkreport(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | See report (REPORT_PERIOD). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | =item * AVAIL_REPORTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | Ref to a hash keyed by report period containing a ref to a list containing all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | those records returned by the Nagios availability report that are accepted by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | pre-filter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | Unlike REPORTS, each record contains all the Nagios reporting fields including | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | the fields AVAIL_URL and TREND_URL whose values are hyperlinks to the Nagios | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | trend and availability reports for the host named HOST_NAME. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | See avail (REPORT_PERIOD). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | =head1 SUBROUTINES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | =item * max_l ( LIST_OF_NUMERIC_VALS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | Returns the maximum value in the list. Does not handle non-numeric values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | =item * comp ( OPTION_HASH ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | Returns a ref to a comparator function that determines the order of the records and can be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | as the B<ORDER_CALLBACK> argument of B<mkreport()>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | C<OPTION_HASH> is an B<optional> hash with keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | C<alpha> Sort by the HOST_NAME field if set, otherwise by the maximum of the fields value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | C<ascend> Sort in ascending order if set. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | C<fields> The comparator function orders the records based on the B<maximum> of the B<numeric> field values. Only applies if alpha | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | is not set. C<fields> is a reference to an array of numeric field names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | eg &comp( alpha => 1, ascend => 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | Returns a ref to function that orders the records by the HOST_NAME field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | eg &comp() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | Same as calling comp with ( alpha => 1, ascend => 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | eg &comp( alpha => 0, ascend => 1, fields => [TOTAL_TIME_DOWN, TOTAL_TIME_UNREACHABLE] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | Returns a ref to a function that orders the records by the maximum of the values of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | TOTAL_TIME_DOWN and TOTAL_TIME_UNREACHABLE fields. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | =item * t2hms (TIME_T) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | Returns the argument formatted by weeks, days, hours, minutes and seconds eg &t2hms(300) -> 5m. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | =item * d2t (time_string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | Returns the time_t value of the string formatted as either a localtime, US (MM-DD-YYYY) or EURO date (DD-MM-YYY). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | =item * i2t (interval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | Returns the time_t value of the string formatted as an interval of time ie one that matches (?:\d+[wdhms]\s*)+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | eg 3h 5m 30s (3 hours 5 minutes and 30 seconds). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | =item * $st_et{TAG}->(TAG, [ STRUCT TM ] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | A hash of code refs indexed by an interval selecting tag. The second optinal argument is a ref to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | a STRUCT TM. If this arg is missing, [localtime] is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | Returns the pair of time_ts bounding the interval named by the tag. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | upper boundary of the interval is usually the time_t value corresponding to the second argument. The lower boundary is this less | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | the tags value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | Tags include last_n_days, last_n_hours, last_n_mins, thisweek, lastweek, thismonth, lastmonth, thisyear, lastyear and variable strings like the 'at' style time stamps such as 'MMM YYYY' (eg Mar 2006) or HHMM DD.MM.YYYY. When the tag represents a fixed date or time, the interval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | returned is from 'then' to 'now'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | When called by this module, the second argument is always 'now' (ie [localtime]). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | eg join('-', map { scalar(localtime($_)) } $st_et{today}->('today') eq 'Fri Aug 18 00:00:00 2006-Fri Aug 18 10:13:00 2006' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | eg join('-', map { scalar(localtime($_)) } $st_et{today}->('today', [ 0, 0, 0, 18, 7, 106])) eq 'Fri Aug 18 00:00:00 2006-Fri Aug 18 10:13:00 2006' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | =item * Does not do much more than the standard availability CGI. The reports | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | has the same bugs as those produced by the CGI. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | =item * The B<comp()> subroutine does not behave well if called with fields whose values are non numeric. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | =item * The hand done date and time functions are poor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | =item * Anything good in this module comes from B<Higher Order Perl>; the rest comes from the author. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | =item * The module does not buy much more than rolling ones own with DBD::AnyData. Had I been more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | aware of the fundamental utility and importance of RDBMS data, this module would probably | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | not exist. OTOH, this module now provides some sort of programmatic access to Nagios availability | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | data that Nagios has not had (AFAIK) hitherto. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | perl(1). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | Nagios (http://www.Nagios.ORG/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | Stanley Hopcroft <HopcroftS@CPAN.Org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | Copyright (c) 2006 Stanley Hopcroft. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||