VBTK/RmtServer.pm untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 111 CC 6 SCAR 21.7
CC
6
Cov
0%
new
20.0
sendHeartbeat
12.0
sendAllHeartbeats
2.0
CRAP 8.8
1 #! /bin/perl
2 #############################################################################
3 #
4 # NOTE: This file under revision control using RCS
5 # Any changes made without RCS will be lost
6 #
7 # $Source: /usr/local/cvsroot/vbtk/VBTK/RmtServer.pm,v $
8 # $Revision: 1.8 $
9 # $Date: 2002/03/04 20:53:07 $
10 # $Author: bhenry $
11 # $Locker: $
12 # $State: Exp $
13 #
14 # Purpose: A perl library used to define a Remote VB server.
15 #
16 # Description:
17 #
18 # Directions:
19 #
20 # Invoked by:
21 #
22 # Depends on:
23 #
24 # Copyright (C) 1996 - 2002 Brent Henry
25 #
26 # This program is free software; you can redistribute it and/or
27 # modify it under the terms of version 2 of the GNU General Public
28 # License as published by the Free Software Foundation available at:
29 # http://www.gnu.org/copyleft/gpl.html
30 #
31 # This program is distributed in the hope that it will be useful,
32 # but WITHOUT ANY WARRANTY; without even the implied warranty of
33 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 # GNU General Public License for more details.
35 #
36 #############################################################################
37 #
38 #
39 # REVISION HISTORY:
40 #
41 # $Log: RmtServer.pm,v $
42 # Revision 1.8 2002/03/04 20:53:07 bhenry
43 # *** empty log message ***
44 #
45 # Revision 1.7 2002/03/04 16:49:09 bhenry
46 # Changed requirement back to perl 5.6.0
47 #
48 # Revision 1.6 2002/03/02 00:53:55 bhenry
49 # Documentation updates
50 #
51 # Revision 1.5 2002/02/20 19:25:18 bhenry
52 # *** empty log message ***
53 #
54 # Revision 1.4 2002/02/19 19:09:06 bhenry
55 # Added getCount method
56 #
57 # Revision 1.3 2002/02/13 07:39:44 bhenry
58 # Disabled RrdLogRecovery and removed use of @log
59 #
60 # Revision 1.2 2002/01/21 17:07:40 bhenry
61 # Disabled 'uninitialized' warnings
62 #
63 # Revision 1.1.1.1 2002/01/17 18:05:57 bhenry
64 # VBTK Project
65 #
66  
67 package VBTK::RmtServer;
68  
69 use 5.6.0;
70 use strict;
71 use warnings;
72  
73 use VBTK::Common;
74 use VBTK::Parser;
75 # I like using undef as a value so I'm turning off the uninitialized warnings
76 no warnings qw(uninitialized);
77  
78 our $VERBOSE=$ENV{'VERBOSE'};
79 our @RMTSERVERLIST;
80 our %QUICKLOOKUP;
81 our $REMOTE_GET_HTML_TIMEOUT=5;
82  
83 #-------------------------------------------------------------------------------
84 # Function: new
85 # Description: Object constructor. Allocates memory for all class members
86 # Input Parms: Configuration filename
87 # Output Parms: Pointer to class
88 #-------------------------------------------------------------------------------
89 sub new
90 {
91 my $type = shift;
92 my $self = {};
93 bless $self, $type;
94  
95 # Store all passed input name pairs in the object
96 $self->set(@_);
97  
98 # Setup some defaults
99 my $expireAfterSec = $self->{Interval} * 3;
100  
101 my $defaultParms = {
102 HeartbeatObject => ".$::HOST.hrtbt",
103 LocalHeartbeatObject => ".$::HOST.hrtbt",
104 Interval => $::REQUIRED,
105 RemoteURI => $::REQUIRED,
106 LocalURI => $::REQUIRED,
107 StatusChangeActions => undef,
108 StatusUpgradeRules => [
109 "Upgrade to Failed if Warning occurs 2 times in $expireAfterSec seconds" ],
110 ExpireAfter => "$expireAfterSec seconds",
111 Description => qq(
112 The heartbeat objects track the ability of the VBServer to talk to another
113 VBServer. This object tracks the ability of the VBServer at
114 '$self->{LocalURI}' to send a heartbeat signal to '$self->{RemoteURI}'. )
115 };
116  
117 # Validate the passed parms
118 $self->validateParms($defaultParms) || &fatal("Exiting");
119  
120 &log("Creating object for remote server '$self->{RemoteURI}'")
121 if ($VERBOSE);
122  
123  
124 # Setup parser objects to handle the local and remote heartbeat objects
125 my $commonParserParms = {
126 Interval => $self->{Interval},
127 VBHeader => [ ' time errors',
128 '------------------ ------' ],
129 VBDetail => [ '@<<<<<<<<<<<<<<<<< @>>>>>',
130 '$time,$data[0]' ],
131 LogDetail => [ '$time $data[0]' ]
132 };
133  
134 $self->{localObj} = new VBTK::Parser(
135 VBServerURI => $self->{LocalURI},
136 %{$commonParserParms}
137 );
138  
139 $self->{remoteObj} = new VBTK::Parser(
140 VBServerURI => $self->{RemoteURI},
141 %{$commonParserParms}
142 );
143  
144  
145 # Now add VB objects to the two parser objects
146 my $commonVBObjParms = {
147 TextHistoryLimit => 30,
148 ReverseText => 1,
149 Rules => { '$data[0] > 0' => 'Warning' },
150 Requirements => undef,
151 StatusHistoryLimit => 30,
152 StatusChangeActions => $self->{StatusChangeActions},
153 StatusUpgradeRules => $self->{StatusUpgradeRules},
154 ExpireAfter => $self->{ExpireAfter},
155 Description => $self->{Description},
156 RrdTimeCol => undef,
157 RrdColumns => undef,
158 RrdFilter => undef,
159 RrdMin => undef,
160 RrdMax => undef,
161 RrdXFF => undef,
162 RrdCF => undef,
163 RrdDST => undef,
164 };
165  
166 # Setup the local object and graph
167 my $localVBObj = $self->{localObj}->addVBObj(
168 VBObjName => $self->{LocalHeartbeatObject},
169 %{$commonVBObjParms}
170 );
171 &fatal("Can't setup RmtServer vbObj") unless ($localVBObj);
172  
173 # Setup the remote object and graph
174 my $remoteVBObj = $self->{remoteObj}->addVBObj(
175 VBObjName => $self->{HeartbeatObject},
176 %{$commonVBObjParms}
177 );
178 &fatal("Can't setup RmtServer vbObj") unless ($remoteVBObj);
179  
180 push(@RMTSERVERLIST,$self);
181  
182 return $self;
183 }
184  
185 #-------------------------------------------------------------------------------
186 # Function: sendHeartbeat
187 # Description: Send the heartbeat to this remote server
188 # Input Parms: None
189 # Output Parms: None
190 #-------------------------------------------------------------------------------
191 sub sendHeartbeat
192 {
193 my $self = shift;
194 my $localObj = $self->{localObj};
195 my $remoteObj = $self->{remoteObj};
196 my $RemoteURI = $self->{RemoteURI};
197 my $LocalURI = $self->{LocalURI};
198 my ($result,$msg);
199  
200 # Pass an error count of '0' to the remote parser.
201 $result = $remoteObj->parseData([[0]],$::SUCCESS);
202  
203 # If the set status fails, then set the error count to one for the local parser
204 if($result)
205 {
206 $msg = "Error sending heartbeat status to '$RemoteURI'";
207 &error($msg);
208 $result = $localObj->parseData([[1]],$::WARNING,$msg);
209 }
210 # Otherwise, pass a 'Success' status to the local parser
211 else
212 {
213 $result = $localObj->parseData([[0]],$::SUCCESS);
214 }
215  
216 # If there is any error, then send a failed status to the remote vbserver.
217 if($result)
218 {
219 $msg = "Error sending local heartbeat status to '$LocalURI'";
220 &error($msg);
221 $result = $remoteObj->parseData([[1]],$::WARNING,$msg);
222 return 1;
223 }
224  
225 (0);
226 }
227  
228 #-------------------------------------------------------------------------------
229 # Function: sendHeartbeat
230 # Description: Send the heartbeat to this remote server
231 # Input Parms: None
232 # Output Parms: None
233 #-------------------------------------------------------------------------------
234 sub sendAllHeartbeats
235 {
236 my $result = 0;
237 my $rmtServer;
238  
239 # Trigger all heartbeat objects
240 foreach $rmtServer (@RMTSERVERLIST)
241 {
242 $result += $rmtServer->sendHeartbeat;
243 }
244  
245 ($result);
246 }
247  
248 #-------------------------------------------------------------------------------
249 # Function: getCount
250 # Description: Return the total number of configured Remote Servers
251 # Input Parms: None
252 # Output Parms: Number of Remote Servers
253 #-------------------------------------------------------------------------------
254 sub getCount
255 {
256 scalar(@RMTSERVERLIST);
257 }
258  
259  
260 1;
261 __END__