| 1 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # NOTE: This file under revision control using RCS | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Any changes made without RCS will be lost | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # $Source: /usr/local/cvsroot/vbtk/VBTK/Common.pm,v $ | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # $Revision: 1.14 $ | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # $Date: 2002/03/04 20:53:06 $ | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # $Author: bhenry $ | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # $Locker: $ | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # $State: Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # Purpose: A common perl library to store common subroutines used | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # by all of the vbsuite products. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # Description: This library contains common subroutines and variables used | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # globally by all processes. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # Invoked by: All VBTKSuite Modules and client processes | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # Copyright (C) 1996 - 2002 Brent Henry | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # modify it under the terms of version 2 of the GNU General Public | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # License as published by the Free Software Foundation available at: | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # http://www.gnu.org/copyleft/gpl.html | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ############################################################################# | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # REVISION HISTORY: | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # $Log: Common.pm,v $ | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # Revision 1.14 2002/03/04 20:53:06 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # *** empty log message *** | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # Revision 1.13 2002/03/04 16:49:09 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # Changed requirement back to perl 5.6.0 | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # Revision 1.12 2002/03/02 00:53:54 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # Documentation updates | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # Revision 1.11 2002/02/19 19:06:14 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # Added deltaSec function | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # Revision 1.10 2002/02/13 07:38:15 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # Moved write_pid_file functionality from Common into Controller | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # Revision 1.9 2002/02/09 08:45:00 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # Improved logic from determining Date::Manip timezone | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # Revision 1.8 2002/02/08 02:16:04 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # *** empty log message *** | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # Revision 1.7 2002/01/30 17:05:41 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # *** empty log message *** | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # Revision 1.6 2002/01/26 06:15:59 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # *** empty log message *** | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # Revision 1.5 2002/01/25 07:18:03 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # Added method to check Date::Manip timezone for errors | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # Revision 1.4 2002/01/23 18:33:35 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # Re-arranged OS determining code | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # Revision 1.3 2002/01/21 17:07:40 bhenry | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # Disabled 'uninitialized' warnings | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # These first variables need to be in the main package | ||||||||||||||||||||||||||||||||||||||||||
| 77 | package main; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | use 5.6.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | # I like using undef as a value so I'm turning off these warnings | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # These global variables can be set through environment variables, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # or will be defaulted appropriately. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | ▶ | our $VBHOME = $ENV{VBHOME} || "/usr/vbtk"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'VBHOME'} || '/usr/vbtk'
MC/DC0%0/1
$ENV{'VBHOME'} || '/usr/vbtk'
$ENV{'VBHOME'}
Truth table50%1/2
A
A= $ENV{'VBHOME'}
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | our $VBPORT = $ENV{VBPORT} || "4712"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'VBPORT'} || '4712'
MC/DC0%0/1
$ENV{'VBPORT'} || '4712'
$ENV{'VBPORT'}
Truth table50%1/2
A
A= $ENV{'VBPORT'}
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | our $VBURI = $ENV{VBURI} || "http://vbserver:$VBPORT"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'VBURI'} || "http://vbserver:$main::VBPORT"
MC/DC0%0/1
$ENV{'VBURI'} || "http://vbserver:$main::VBPORT"
$ENV{'VBURI'}
Truth table50%1/2
A
A= $ENV{'VBURI'}
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | our $VBLOGS = $ENV{VBLOGS} || "$VBHOME/logs"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'VBLOGS'} || "$main::VBHOME/logs"
MC/DC0%0/1
$ENV{'VBLOGS'} || "$main::VBHOME/logs"
$ENV{'VBLOGS'}
Truth table50%1/2
A
A= $ENV{'VBLOGS'}
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | our $VBOBJ = $ENV{VBOBJ} || "$VBHOME/vbobj"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'VBOBJ'} || "$main::VBHOME/vbobj"
MC/DC0%0/1
$ENV{'VBOBJ'} || "$main::VBHOME/vbobj"
$ENV{'VBOBJ'}
Truth table50%1/2
A
A= $ENV{'VBOBJ'}
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | our $RRDBIN = $ENV{RRDBIN} || "/usr/local/bin/rrdtool"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'RRDBIN'} || '/usr/local/bin/rrdtool'
MC/DC0%0/1
$ENV{'RRDBIN'} || '/usr/local/bin/rrdtool'
$ENV{'RRDBIN'}
Truth table50%1/2
A
A= $ENV{'RRDBIN'}
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # These we can't allow environment variable overrides, because it would make | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # it too hard during the sync, trying to figure out where to put everything. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | our $VBCONF = "$VBHOME/conf"; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | our $VBBIN = "$VBHOME/bin"; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | our $VBPSWD = $ENV{VBPSWD} || "$VBCONF/.pswd"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'VBPSWD'} || "$main::VBCONF/.pswd"
MC/DC0%0/1
$ENV{'VBPSWD'} || "$main::VBCONF/.pswd"
$ENV{'VBPSWD'}
Truth table50%1/2
A
A= $ENV{'VBPSWD'}
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | # Setup global variables | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | our $SUCCESS="Success"; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | our $WARNING="Warning"; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | our $TIMEOUT="Timeout"; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | our $FAILED="Failed"; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | our $EXPIRED="Expired"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | our $RUNNING="Running"; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | our $ERROR = 1; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | our $FINISHED = 0; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | our $NOT_FINISHED = -1; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | our %VB_STATUS_MAP = (S => $SUCCESS, "s" => $SUCCESS, | |||||||||||||||||||||||||||||||||||||||||
| 117 | W => $WARNING, w => $WARNING, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | T => $TIMEOUT, t => $TIMEOUT, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | F => $FAILED, f => $FAILED, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | E => $EXPIRED, e => $EXPIRED, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | R => $RUNNING, r => $RUNNING); | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | our %VB_STATUS_RANK = ('' => 0, | |||||||||||||||||||||||||||||||||||||||||
| 124 | $SUCCESS => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | $RUNNING => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | $EXPIRED => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | $WARNING => 4, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | $TIMEOUT => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | $FAILED => 6); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | our $OS; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | our $SL; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # Figure out what O/S we're running under | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | ▶ | unless ($OS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 3 | ▶ | unless ($OS = $^O) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | require Config; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $OS = $Config::Config{'osname'}; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # Decide what file separator to use based on the OS. | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ($OS=~/Win|os2|dos/i) { $SL = '\\'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | elsif ($OS=~/^MacOS$/i) { $SL = ':'; } | |||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | else { $SL = '/'; } | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | ▶ | use FileHandle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | STDOUT->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # Setup some static variables | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | our $REQUIRED = "$;$;::REQUIRED_PARM::$;$;"; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | our $MASTER_NODE = "::MASTER_NODE::"; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | our $VERBOSE=$ENV{VERBOSE}; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | our $HOST = hostname(); | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | # Enter the common package | ||||||||||||||||||||||||||||||||||||||||||
| 159 | package VBTK::Common; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | ▶ | use Date::Manip qw(ParseDateDelta Delta_Format); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | # Export all the common methods | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 3 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | # use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | our @EXPORT = qw(log error fatal map_status find_higher_status | |||||||||||||||||||||||||||||||||||||||||
| 171 | datestamp color_by_status testFork testAlarm | ||||||||||||||||||||||||||||||||||||||||||
| 172 | red green yellow blue bold log_datestamp validateParms set | ||||||||||||||||||||||||||||||||||||||||||
| 173 | unixdate deltaSec); | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # Setup global package variables | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | our $PID_SET = 0; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | ▶ | our $VERBOSE=$ENV{VERBOSE} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'VERBOSE'} || 0
MC/DC0%0/1
$ENV{'VERBOSE'} || 0
$ENV{'VERBOSE'}
Truth table50%1/2
A
A= $ENV{'VERBOSE'}
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # Function: validateParms | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # Description: Validate the first passed hash of parameters against the second | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # passed hash. Any keys in the first hash must exist in the | ||||||||||||||||||||||||||||||||||||||||||
| 183 | # second hash, and any values which are unset in the first hash | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # will be set to the corresponding values in the second hash. | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # Input Parms: Hash to be validate, Hash with default values | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # Output Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 187 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 188 | sub validateParms | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validateParms: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my ($parms,$defaults,$caller) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my (%keyExists,$hash); | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | # If the package name was not passed, then try to determine it. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | ($caller) = (caller(1))[3] if (! defined $caller); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | # Make sure both passed entries are hashes | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | foreach $hash ($parms, $defaults) | |||||||||||||||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | &fatal("Call to validateParms must consist of two hashes") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | if (ref($hash) =~ /^$|^SCALAR$|^ARRAY$/); | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | # Make a list of the keys in the 'defaults' hash | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | %keyExists = map { $_ => 1 } keys %{$defaults}; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | # Now check to see if there are any keys in the parms hash which are not in | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # the defaults hash | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | foreach my $key (keys %{$parms}) | |||||||||||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | unless($keyExists{$key}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | &error("Invalid parameter '$key' in call to '$caller'"); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | # If we made it this far, then let's setup defaults | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | foreach my $key (keys %{$defaults}) | |||||||||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # Check to see if it's a required value | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ((defined $defaults->{$key})&&($defaults->{$key} eq $::REQUIRED)&& | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $defaults->{$key} and $defaults->{$key} eq $main::REQUIRED and not defined $parms->{$key}
defined $defaults->{$key} and $defaults->{$key} eq $main::REQUIRED
MC/DC0%0/3
defined $defaults->{$key} and $defaults->{$key} eq $main::REQUIRED and not defined $parms->{$key}
defined $defaults->{$key}
$defaults->{$key} eq $main::REQUIRED
not defined $parms->{$key}
Truth table0%0/4
A and B and not(C)
A= defined $defaults->{$key}B= $defaults->{$key} eq $main::REQUIREDC= not defined $parms->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | (! defined $parms->{$key})) | ||||||||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | &error("Must specify '$key' in call to '$caller'"); | |||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | # Set it to the default value if it's blank | ||||||||||||||||||||||||||||||||||||||||||
| 229 | $parms->{$key} = $defaults->{$key} | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ((! defined $parms->{$key})&&(defined $defaults->{$key})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $parms->{$key} and defined $defaults->{$key}
MC/DC0%0/2
not defined $parms->{$key} and defined $defaults->{$key}
not defined $parms->{$key}
defined $defaults->{$key}
Truth table0%0/3
not(A) and B
A= not defined $parms->{$key}B= defined $defaults->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | (1); | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 236 | # Function: set | ||||||||||||||||||||||||||||||||||||||||||
| 237 | # Description: Set an attribute of the monitor object | ||||||||||||||||||||||||||||||||||||||||||
| 238 | # Input Parms: Associate array of attributes and their values | ||||||||||||||||||||||||||||||||||||||||||
| 239 | # Output Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 240 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 241 | sub set | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my ($pkg,$printVal); | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $pkg = caller; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | foreach (keys %args) | |||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if($VERBOSE > 2) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $printVal = (defined $args{$_}) ? "'$args{$_}'" : 'undef'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | &log("Setting $pkg" . "{$_} to $printVal "); | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $obj->{$_} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # Function: unixdate | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # Description: Parse the input string and convert it to the unix date integer | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # Input Parms: Date String | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # Output Parms: Unix date | ||||||||||||||||||||||||||||||||||||||||||
| 265 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 266 | sub unixdate | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unixdate: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my($timeStr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my($time); | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # If it's a known pattern, then try to do it ourselves, since the | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # Date::Manip::UnixDate routine is very slow. | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if($timeStr =~ /^(\d{4})(\d{2})(\d{2})-?(\d{2}):(\d{2}):(\d{2})\s*$/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $time = mktime($6,$5,$4,$3,($2-1),($1-1900),undef,undef,-1); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | &log("Used mktime to convert '$timeStr' to '$time'") if ($VERBOSE > 3); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | else | ||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $time = &Date::Manip::UnixDate($timeStr, "%s"); | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | &log("Used UnixDate to convert '$timeStr' to '$time'") if ($VERBOSE > 3); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $time; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # Function: checkDateManipTZ | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # Description: Run a test of DateManip and make sure that it's not going to | ||||||||||||||||||||||||||||||||||||||||||
| 290 | # crash the program if it can't find the timezone. | ||||||||||||||||||||||||||||||||||||||||||
| 291 | # Input Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 292 | # Output Parms: 1 or 0 | ||||||||||||||||||||||||||||||||||||||||||
| 293 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 294 | sub checkDateManipTZ | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkDateManipTZ: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my ($tz); | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | eval { $tz = &Date::Manip::Date_TimeZone; }; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | &log("Date::Manip timezone is $tz") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if (($@)||(! $tz)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $tz
MC/DC0%0/2
$@ or not $tz
$@
not $tz
Truth table0%0/3
A or not(B)
A= $@B= not $tz
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | &log("Date::Manip can't determine timezone, attempting to parse from \$TZ") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | if($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if($ENV{'TZ'} =~ /^([A-Z]{3,3})/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | { | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | &log("Attempting to set Date::Manip timezone to '$1'") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | &Date::Manip::Date_Init("TZ=$1"); | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | eval { $tz = &Date::Manip::Date_TimeZone; }; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if (($@)||(! $tz)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $tz
MC/DC0%0/2
$@ or not $tz
$@
not $tz
Truth table0%0/3
A or not(B)
A= $@B= not $tz
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | &log("Can't determine timezone, setting to GMT") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | &Date::Manip::Date_Init("TZ=GMT"); | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | (1); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # Function: find_higher_status | ||||||||||||||||||||||||||||||||||||||||||
| 327 | # Description: Compare two status values and return the higher one | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # Input Parms: Status 1, Status 2 | ||||||||||||||||||||||||||||||||||||||||||
| 329 | # Output Parms: Higher of the two statuses | ||||||||||||||||||||||||||||||||||||||||||
| 330 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 331 | sub find_higher_status | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_higher_status: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my ($status_1,$status_2) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $status_1 = &map_status($status_1); | |||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $status_2 = &map_status($status_2); | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if($::VB_STATUS_RANK{$status_1} > $::VB_STATUS_RANK{$status_2}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ($status_1); | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | else | ||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ($status_2); | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 349 | # Function: testFork | ||||||||||||||||||||||||||||||||||||||||||
| 350 | # Description: Check to see if this platform supports forking. | ||||||||||||||||||||||||||||||||||||||||||
| 351 | # Input Parms: | ||||||||||||||||||||||||||||||||||||||||||
| 352 | # Output Parms: | ||||||||||||||||||||||||||||||||||||||||||
| 353 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 354 | sub testFork | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
testFork: called CC=6 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | ▶ | &log("Testing fork operation") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 2 | my($pid); | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | ▶ | if($pid = fork) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | ▶ | &log("Fork was successful, enabling forking") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | elsif(defined $pid) | ||||||||||||||||||||||||||||||||||||||||||
| 366 | { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | &log("Fork failed, disabling forking") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | (0); | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 375 | # Function: testAlarm | ||||||||||||||||||||||||||||||||||||||||||
| 376 | # Description: Check to see if this platform supports alarm | ||||||||||||||||||||||||||||||||||||||||||
| 377 | # Input Parms: | ||||||||||||||||||||||||||||||||||||||||||
| 378 | # Output Parms: | ||||||||||||||||||||||||||||||||||||||||||
| 379 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 380 | sub testAlarm | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
testAlarm: called CC=4 SCAR=15.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | ▶ | &log("Testing alarm operation") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | # Test to see if alarm is supported on this platform | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | eval { alarm 0; }; | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | if ($@ eq '') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | { | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | ▶ | &log("Alarm was successful, enabling alarm") if ($VERBOSE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | return 1 | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | &log("Alarm failed, disabling alarm"); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | (0); | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # Function: map_status | ||||||||||||||||||||||||||||||||||||||||||
| 399 | # Description: Map the passed word to one of the pre-defined status values, | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # based on the first character. | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # Input Parms: Unformatted status | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # Output Parms: Pre-defined status | ||||||||||||||||||||||||||||||||||||||||||
| 403 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 404 | sub map_status | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_status: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my($in_status) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my($first_char) = substr($in_status,0,1); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my($out_status) = $::VB_STATUS_MAP{$first_char}; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | &error("Invalid status '$in_status' specified") if ($out_status eq ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ($out_status); | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 414 | # Function: log_datestamp | ||||||||||||||||||||||||||||||||||||||||||
| 415 | # Description: Return the current datestamp in YYYYMMDD-HH:MM:SS format | ||||||||||||||||||||||||||||||||||||||||||
| 416 | # Input Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 417 | # Output Parms: DateStamp | ||||||||||||||||||||||||||||||||||||||||||
| 418 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 419 | sub log_datestamp | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_datestamp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | my($sec,$min,$hour,$mday,$mon,$year) = localtime(time); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 1 | $year += 1900; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | ++$mon; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | sprintf "%04d%02d%02d-%02d:%02d:%02d",$year,$mon,$mday,$hour,$min,$sec; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 428 | # Function: deltaSec | ||||||||||||||||||||||||||||||||||||||||||
| 429 | # Description: Evaluate the passed string and return the number of seconds it | ||||||||||||||||||||||||||||||||||||||||||
| 430 | # represents. | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # Input Parms: String | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # Output Parms: Seconds | ||||||||||||||||||||||||||||||||||||||||||
| 433 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 434 | sub deltaSec | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deltaSec: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my ($str) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | my $delta = &ParseDateDelta($str) || return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
&ParseDateDelta($str) || (return undef)
MC/DC0%0/1
&ParseDateDelta($str) || (return undef)
&ParseDateDelta($str)
Truth table0%0/2
A
A= &ParseDateDelta($str)
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | my $deltaSec = &Delta_Format($delta,0,'%st') || return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
&Delta_Format($delta, 0, '%st') || (return undef)
MC/DC0%0/1
&Delta_Format($delta, 0, '%st') || (return undef)
&Delta_Format($delta, 0, '%st')
Truth table0%0/2
A
A= &Delta_Format($delta, 0, '%st')
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | int($deltaSec); | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 445 | # Function: gmtdatestamp | ||||||||||||||||||||||||||||||||||||||||||
| 446 | # Description: Return the current datestamp in YYYYMMDDHH:MM:SS format. This | ||||||||||||||||||||||||||||||||||||||||||
| 447 | # is used by internal functions to generate Date::Manip compatible | ||||||||||||||||||||||||||||||||||||||||||
| 448 | # timestamps. Do not change the format!! | ||||||||||||||||||||||||||||||||||||||||||
| 449 | # Input Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 450 | # Output Parms: Datestamp | ||||||||||||||||||||||||||||||||||||||||||
| 451 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 452 | sub gmtdatestamp | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gmtdatestamp: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | my $time = shift || time; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || time
MC/DC0%0/1
shift() || time
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my($sec,$min,$hour,$mday,$mon,$year) = gmtime($time); | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $year += 1900; | |||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ++$mon; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | sprintf "%04d%02d%02d%02d:%02d:%02d",$year,$mon,$mday,$hour,$min,$sec; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 462 | # Function: datestamp | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # Description: Return the current datestamp in YYYYMMDDHH:MM:SS format. This | ||||||||||||||||||||||||||||||||||||||||||
| 464 | # is used by internal functions to generate Date::Manip compatible | ||||||||||||||||||||||||||||||||||||||||||
| 465 | # timestamps. Do not change the format!! | ||||||||||||||||||||||||||||||||||||||||||
| 466 | # Input Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 467 | # Output Parms: Datestamp | ||||||||||||||||||||||||||||||||||||||||||
| 468 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 469 | sub datestamp | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datestamp: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | my $time = shift || time; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || time
MC/DC0%0/1
shift() || time
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my($sec,$min,$hour,$mday,$mon,$year) = localtime($time); | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $year += 1900; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ++$mon; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | sprintf "%04d%02d%02d%02d:%02d:%02d",$year,$mon,$mday,$hour,$min,$sec; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 479 | # Function: log | ||||||||||||||||||||||||||||||||||||||||||
| 480 | # Description: Print to STDOUT with a timestamp. If a reference to an array is | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # passed, the message will also be pushed onto the array. | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # Input Parms: Msg | ||||||||||||||||||||||||||||||||||||||||||
| 483 | # Output Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 484 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 485 | sub log | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: called CC=4 SCAR=15.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | my($msg,$ptr,$suppress_stdout,$suppress_messages) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | my($date) = &log_datestamp; | |||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | push(@{$ptr},"$date - $msg\n") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ptr and not defined $suppress_messages
MC/DC0%0/2
defined $ptr and not defined $suppress_messages
defined $ptr
not defined $suppress_messages
Truth table33%1/3
A and not(B)
A= defined $ptrB= not defined $suppress_messages
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | if (defined($ptr) && !defined($suppress_messages)); | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | ▶ | print STDERR "$date - $msg\n" unless defined($suppress_stdout); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | (1); | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 498 | # Function: error | ||||||||||||||||||||||||||||||||||||||||||
| 499 | # Description: Print to STDOUT with a timestamp with the message 'Error' | ||||||||||||||||||||||||||||||||||||||||||
| 500 | # Input Parms: Msg | ||||||||||||||||||||||||||||||||||||||||||
| 501 | # Output Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 502 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 503 | sub error | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my($msg,$ptr,$suppress_stdout,$suppress_messages) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | &log("Error: $msg",$ptr,$suppress_stdout,$suppress_messages); | |||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | (1); | |||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 513 | # Function: fatal | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # Description: Print to STDOUT with a timestamp with the message 'Error' and exit | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # Input Parms: Msg | ||||||||||||||||||||||||||||||||||||||||||
| 516 | # Output Parms: None | ||||||||||||||||||||||||||||||||||||||||||
| 517 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 518 | sub fatal | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | &error(@_); | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 525 | # Function: red, green, blue, bold | ||||||||||||||||||||||||||||||||||||||||||
| 526 | # Description: Return the passed string enclosed in a HTML font statement | ||||||||||||||||||||||||||||||||||||||||||
| 527 | # which will produce the color or text format of the function name. | ||||||||||||||||||||||||||||||||||||||||||
| 528 | # Input Parms: Text | ||||||||||||||||||||||||||||||||||||||||||
| 529 | # Output Parms: Formatted text | ||||||||||||||||||||||||||||||||||||||||||
| 530 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | sub red { ("<FONT COLOR='#FF0000'>" . $_[0] . "</FONT>"); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
red: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | sub green { ("<FONT COLOR='#00FF00'>" . $_[0] . "</FONT>"); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
green: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | sub blue { ("<FONT COLOR='#0000FF'>" . $_[0] . "</FONT>"); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | sub yellow { ("<FONT COLOR='#FF6633'>" . $_[0] . "</FONT>"); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
yellow: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | sub bold { ("<B>" . $_[0] . "</B>"); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bold: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 538 | # Function: color_by_status | ||||||||||||||||||||||||||||||||||||||||||
| 539 | # Description: Map the passed word to one of the pre-defined status values, | ||||||||||||||||||||||||||||||||||||||||||
| 540 | # based on the first character. | ||||||||||||||||||||||||||||||||||||||||||
| 541 | # Input Parms: status, text | ||||||||||||||||||||||||||||||||||||||||||
| 542 | # Output Parms: Html | ||||||||||||||||||||||||||||||||||||||||||
| 543 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 544 | sub color_by_status | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
color_by_status: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my($status,$text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | if($status eq $::SUCCESS) { green($text); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | elsif($status eq $::WARNING) { yellow($text); } | |||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | elsif($status eq $::FAILED) { red($text); } | |||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | else { ($text); } | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | __END__ | ||||||||||||||||||||||||||||||||||||||||||