VBTK/Objects.pm untested

filter: Statementstmt 0.0% 0 / 608 Branchbran 0.0% 0 / 246 Conditioncond 0.0% 0 / 73 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 0.0% 0 / 72 Podpod 0.0% 0 / 57 totaltotal 0.0% 0 / 1099 CC 124 SCAR 46.6
CC
124
Cov
0%
recurseSetStatus
506.0
setStatus
182.0
deleteObject
182.0
CRAP 106.1
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/Objects.pm,v $
8 # $Author: bhenry $
9 # $Locker: $
10 # $State: Exp $
11 #
12 # Purpose: A common perl library used to define a hierarchy of
13 # objects which have an associated status and which trigger
14 # actions based on that status.
15 #
16 # Description: This perl library contains subroutines which simplify the
17 # creation of a hierarchy of objects to which a status can
18 # be assigned and to which actions can be assigned based on
19 # that status. The objects support the handling of templates,
20 # expiration times, actions, status upgrades based on the
21 # re-occurance of specified actions, etc. It also supports
22 # the generation of html to show graphical descriptions of the
23 # statuses of the objects grouped by name and supports a drill
24 # down approach to viewing objects which have more than 3
25 # segments in their name.
26 #
27 # Directions:
28 #
29 # Invoked by: vbserver
30 #
31 # Depends on: VBTK::Common.pm, VBTK::Actions.pm, VBTK::Template.pm, Date::Manip.pm
32 #
33 # Copyright (C) 1996 - 2002 Brent Henry
34 #
35 # This program is free software; you can redistribute it and/or
36 # modify it under the terms of version 2 of the GNU General Public
37 # License as published by the Free Software Foundation available at:
38 # http://www.gnu.org/copyleft/gpl.html
39 #
40 # This program is distributed in the hope that it will be useful,
41 # but WITHOUT ANY WARRANTY; without even the implied warranty of
42 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 # GNU General Public License for more details.
44 #
45 #############################################################################
46 #
47 #
48 # REVISION HISTORY:
49 #
50 # $Log: Objects.pm,v $
51 # Revision 1.10 2002/03/04 20:53:07 bhenry
52 # *** empty log message ***
53 #
54 # Revision 1.9 2002/03/04 16:49:09 bhenry
55 # Changed requirement back to perl 5.6.0
56 #
57 # Revision 1.8 2002/03/02 00:53:55 bhenry
58 # Documentation updates
59 #
60 # Revision 1.7 2002/02/19 19:03:58 bhenry
61 # Changed to accept 'SetBaselineFlag' when setting status
62 #
63 # Revision 1.6 2002/01/28 22:28:45 bhenry
64 # *** empty log message ***
65 #
66 # Revision 1.5 2002/01/25 16:42:06 bhenry
67 # Changed to serialized filename to end in '.ser'
68 #
69 # Revision 1.4 2002/01/25 07:16:33 bhenry
70 # Changed to use Storable instead of Serialize
71 #
72 # Revision 1.3 2002/01/21 17:07:40 bhenry
73 # Disabled 'uninitialized' warnings
74 #
75 # Revision 1.2 2002/01/18 19:24:50 bhenry
76 # Warning Fixes
77 #
78 # Revision 1.1.1.1 2002/01/17 18:05:57 bhenry
79 # VBTK Project
80 #
81 #
82  
83 package VBTK::Objects;
84  
85 use 5.6.0;
86 use strict;
87 use warnings;
88 # I like using undef as a value so I'm turning off the uninitialized warnings
89 no warnings qw(uninitialized);
90  
91 use VBTK::Common;
92 use VBTK::Actions;
93 use VBTK::Templates;
94 use VBTK::RmtServer;
95 use VBTK::File;
96 use VBTK::Objects::History;
97 use VBTK::Objects::Rrd;
98 use File::Basename;
99 use Date::Manip;
100 use POSIX;
101 use Storable qw (freeze thaw);
102  
103 our $VERBOSE=$ENV{'VERBOSE'};
104 our $CHANGED=0;
105 our $NO_CHANGE=1;
106 our $DELETED=2;
107 our $ERROR=-1;
108  
109 our $VB_OBJ_FILE_DIR;
110 our @VB_TEMPLATE_LIST;
111 our $VB_IMPORTING_OBJECTS_FLG = 0;
112 our $VBVIEW_EXT_URL;
113 our $DEFAULT_PREFIX;
114 our $FORK_RRD_UPDATE;
115  
116 our %NAME_CACHE;
117 our @PERSISTENT_PARMS = ('StatusHistoryLimit','Description','ChangeActionObjList',
118 'ExpireAfter','UpgradeRuleObjList','GraphGroupList','BaselineDiffStatus',
119 'RunningFrom','ScriptName','LogFile','Interval');
120 our %PERSISTENT_PARMS_HASH = map { $_ => 1 } @PERSISTENT_PARMS;
121  
122 #-------------------------------------------------------------------------------
123 # Function: new
124 # Description: Object constructor. Allocates memory for all class members
125 # Input Parms: Configuration filename
126 # Output Parms: Pointer to class
127 #-------------------------------------------------------------------------------
128 sub new
129 {
130 my $type = shift;
131 my $self = {};
132 bless $self, $type;
133  
134 # Load in the passed parms
135 $self->set(@_);
136  
137 my $defaultParms = {
138 Name => $::REQUIRED,
139 SegmentName => $::REQUIRED,
140 ObjectDir => undef,
141 ExternalURL => undef,
142 DefaultPrefix => undef,
143 ForkRrdUpdate => undef,
144 };
145  
146 # Validate passed parms
147 $self->validateParms($defaultParms) || return undef;
148  
149 # Set global variables based on passed parms
150 $VB_OBJ_FILE_DIR = $self->{ObjectDir} if ($self->{ObjectDir});
151 $VBVIEW_EXT_URL = $self->{ExternalURL} if ($self->{ExternalURL});
152 $DEFAULT_PREFIX = $self->{DefaultPrefix} if ($self->{DefaultPrefix});
153 $FORK_RRD_UPDATE = $self->{ForkRrdUpdate} if ($self->{ForkRrdUpdate});
154  
155 my $name = $self->{Name};
156  
157 # If the object name starts with a '.' then prepend the default prefix
158 $self->{Name} = $name = $DEFAULT_PREFIX . $name if ($name =~ /^\./);
159  
160 &log("Creating new object '$name'") if ($VERBOSE > 1);
161  
162 # Setup some internal lists and hashes
163 $self->{historyObjList} = [];
164 $self->{historyObjIndex} = {};
165 $self->{childObjList} = {};
166 $self->{grandchildObjectNames} = {};
167 $self->{Status} = '';
168 $self->{type} = '';
169  
170 # Choose the template for this object. Template values are used if
171 # corresponding values were not directly set by the process setting the
172 # status.
173 $self->selectTemplate();
174  
175 # Load our name into the NAME_CACHE hash
176 $NAME_CACHE{$name} = $self;
177  
178 # Setup a place to store object data which needs to be persistent and then
179 # try to load in data from that file if it exists.
180 my $metaFileName = "$VB_OBJ_FILE_DIR/$name/Object.ser";
181 $self->{metaFileObj} = new VBTK::File($metaFileName);
182 $self->loadMetaData;
183  
184 # Setup a place to store the baseline text.
185 my $baselineFileName = "$VB_OBJ_FILE_DIR/$name/Baseline.txt";
186 $self->{baselineFileObj} = new VBTK::File($baselineFileName);
187  
188 # Load up any history which may exist for the object
189 $self->loadAllHistory;
190  
191 # Initialize an Rrd object for us
192 $self->{rrdObj} = new VBTK::Rrd(
193 RrdDbPath => "$VB_OBJ_FILE_DIR/$name");
194  
195 return $self;
196 }
197  
198 #-------------------------------------------------------------------------------
199 # Function: setStatus
200 # Description: Do a quick-lookup of the specified object. If it already exists
201 # then check it's status. If it's status isn't different than
202 # the specified status, then there is no need to recurse through
203 # the tree, and so we can jump directly to the object.
204 # Input Parms: Object Name, Status, Status File Text, Recursion Depth
205 # Output Parms:
206 #-------------------------------------------------------------------------------
207 sub setStatus
208 {
209 my $self = shift;
210 my %args = @_;
211 my ($key,$value);
212  
213 # If the ObjStruct parm was passed, then unload it into the args hash and
214 # then delete it from the hash.
215 if(defined $args{ObjStruct})
216 {
217 &log("Attempting to thaw obj struct") if ($VERBOSE > 2);
218 my $objStruct = &thaw($args{ObjStruct});
219 while(($key,$value) = each(%{$objStruct}))
220 {
221 &log("Unloading '$key=$value' from ObjStruct") if ($VERBOSE > 3);
222 $args{$key} = $value if (! defined $args{$key});
223 }
224 }
225 delete $args{ObjStruct};
226  
227 # Now setup the list of allowed parms
228 my $defaultParms = {
229 Name => $::REQUIRED,
230 Status => $::REQUIRED,
231 Text => undef,
232 HeaderMsg => undef,
233 FooterMsg => undef,
234 GraphStruct => undef,
235 StatusHistoryLimit => undef,
236 ChangeActionObjList => undef,
237 UpgradeRuleObjList => undef,
238 ExpireAfter => undef,
239 Description => undef,
240 GraphGroupList => undef,
241 BaselineDiffStatus => undef,
242 RunningFrom => undef,
243 ScriptName => undef,
244 LogFile => undef,
245 Interval => undef,
246 SetBaselineFlag => undef,
247 };
248  
249 # Validate the passed paramters
250 &validateParms(\%args,$defaultParms) || return $ERROR;
251  
252 my $time = time;
253 my $newStatus = &map_status($args{Status});
254 my $name = $args{Name};
255  
256 # Return with an error if we can't map the status passed
257 return $ERROR if ($newStatus eq '');
258  
259 # Store the mapped status
260 $args{Status} = $newStatus;
261  
262 # If the object name starts with a '.' then prepend the default prefix
263 if ($name =~ /^\./)
264 {
265 $name = $DEFAULT_PREFIX . $name;
266 $args{Name} = $name;
267 }
268  
269 # Make sure no invalid characters were passed in
270 if ($name =~ /[^\w\@\.-]/)
271 {
272 &error("Invalid object name '$name', ignoring");
273 return $ERROR;
274 }
275  
276 # Lookup the passed object name
277 my $destObj = $NAME_CACHE{$name};
278 my ($destTemplate,$ruleList,$retval);
279  
280 # Lookup the status upgrade rules for this object as well. If there are
281 # any upgrade rules for this object which correspond to the new status, then
282 # we can't use the quick-set, because the status might get upgraded, which
283 # would require a re-build of the status tree. At this point, determining
284 # this has become complicated enough that I'm not sure it's really helping
285 # performance, but it's working so I'll leave it in.
286 if ($destObj)
287 {
288 $ruleList = $destObj->getUpgradeRuleObjList($newStatus);
289 }
290  
291 # If we found the target object, it's status isn't going to change,
292 # there aren't any current upgrade rules, and we're not adding any,
293 # then jump directly to it.
294 if (($destObj ne '')&&($newStatus eq $destObj->{Status})&&
295 (@{$ruleList} == 0)&&(! defined $args{UpgradeRuleObjList}))
296 {
297 &log("No status change, using quick-set") if ($VERBOSE > 2);
298 $retval = $destObj->recurseSetStatus(%args, Time=>$time, Depth=>0);
299 }
300 # Otherwise, we have to drill down from the top, so that we can recurse back
301 # up, setting group statuses as we go.
302 else
303 {
304 $retval = $self->recurseSetStatus(%args, Time=>$time, Depth=>0);
305 }
306  
307 # Now that we're sure the object has been created, look it up again and pass
308 # any graphing data to it.
309 $destObj = $NAME_CACHE{$name} if (! defined $destObj);
310 $destObj->addGraphDbData($args{GraphStruct}) if (defined $args{GraphStruct});
311  
312 ($retval);
313 }
314  
315 #-------------------------------------------------------------------------------
316 # Function: recurseSetStatus
317 # Description: Set the status of the passed object to the value specified and store
318 # the text. This subroutine is called starting at the head node of
319 # the tree and it recurses down it's child nodes until it find the
320 # actual object specified.
321 # Input Parms: Object Name, Status, Status File Text, Recursion Depth
322 # Output Parms:
323 #-------------------------------------------------------------------------------
324 sub recurseSetStatus
325 {
326 my $self = shift;
327 my %args = @_;
328  
329 # Unload some of the values from the passed structure
330 my $name = $args{Name};
331 my $status = $args{Status};
332 my $time = $args{Time};
333 my $depth = $args{Depth} || 0;
334 my $text = $args{Text};
335  
336 # Unload some object values
337 my $currName = $self->{Name};
338 my $currStatus = $self->{Status};
339 my $type = $self->{type};
340 my $historyObjList = $self->{historyObjList};
341 my $historyObjIndex = $self->{historyObjIndex};
342  
343 my ($retval,$newStatus,$first_char,$ptr,$temp_time,$histObj,$subName);
344 my ($histFileName);
345  
346 &log("recurseSetStatus - Entering object '$currName'") if ($VERBOSE > 2);
347  
348 # If this is the lowest level object, then set the status and return.
349 if ($name eq $currName)
350 {
351 # Can't directly set the status of a object which has sub-objects
352 if((defined $type)&&($type eq 'group'))
353 {
354 &error("Cannot directly set the status of a group object - '$name'");
355 return $ERROR;
356 }
357  
358 # If no status was passed then we must be doing the initial import, so
359 # return the NO_CHANGE value so we don't bother re-calculating group
360 # statuses, etc.
361 return $NO_CHANGE if(! defined $status);
362  
363 &log("Setting status of '$currName' to '$status'") if ($VERBOSE > 1);
364  
365 # Map the status based on the first character of the passed status
366 $newStatus = &map_status($status);
367 return $ERROR if($newStatus eq '');
368  
369 &log("Storing text\n$text") if (($text ne '')&&($VERBOSE > 2));
370  
371 # Set the status, text, and timestamp. The rawStatus is the original
372 # status of the object, before any upgrades were applied.
373 $self->{Status} = $newStatus;
374 $self->{Timestamp} = $time;
375 $self->{type} = "object";
376  
377 # Construct the file path for the history file. Remove any ':' in the
378 # file name.
379 $self->{histFile} = $histFileName = $time;
380  
381 # Unload other passed parms into the object, if any of these parms are
382 # specified, then we need to re-write the metadata file so mark a flag.
383 my $metaDataChangedFlg = 0;
384 foreach my $key (keys %args)
385 {
386 if ($PERSISTENT_PARMS_HASH{$key})
387 {
388 $self->set($key => $args{$key});
389 $metaDataChangedFlg = 1;
390 }
391 }
392  
393 # Validate the status change actions if passed in
394 $self->validateActions if (defined $args{'StatusChangeActions'});
395  
396 # If the status is EXPIRED, then don't bother recalculating
397 # the expiration time.
398 $self->updateExpirTime() if ($newStatus ne $::EXPIRED);
399  
400 # Create the directory where object info will be saved
401 mkdir "$VB_OBJ_FILE_DIR/$name",0775 if (! -d "$VB_OBJ_FILE_DIR/$name");
402  
403 # Store the latest time, status, and text into the history queue.
404 $histObj = new VBTK::Objects::History(
405 ObjPath => $VB_OBJ_FILE_DIR,
406 ObjName => $name,
407 FileName => $histFileName,
408 Timestamp => $time,
409 RepeatStart => $time,
410 Status => $newStatus,
411 RawStatus => $newStatus,
412 Text => $text,
413 HeaderMsg => $args{HeaderMsg},
414 FooterMsg => $args{FooterMsg},
415 ExpireTime => $self->{expireTime},
416 Repeated => 1);
417  
418 return $ERROR if (! defined $histObj);
419 $historyObjIndex->{$histFileName} = $histObj;
420 unshift(@{$historyObjList},$histObj);
421  
422 # Check to see if the object qualifies for a status upgrade
423 $newStatus = $self->checkForStatusUpgrade();
424  
425 # Remove duplicates in the history, incrementing the 'repeated' counter
426 # and removing entries older than the 'StatusHistoryLimit' parm.
427 $self->cleanHistory();
428  
429 # Now tell the history object to write itself.
430 $histObj->store;
431  
432 # Store any passed parameters which need to be persistent
433 $self->storeMetaData if ($metaDataChangedFlg);
434
435 # Store the baseline, if the setBaselineFlag was passed
436 $self->{baselineFileObj}->put($text) if ($args{SetBaselineFlag});
437  
438 # If the status didn't change, then return NO_CHANGE, skipping all the
439 # work of checking for status change actions.
440 return $NO_CHANGE if ($currStatus eq $newStatus);
441  
442 # If the status did change, then check for actions to be performed.
443 $self->checkForStatusChangeAction();
444 }
445  
446 # If this isn't the lowest level object, then check to see if the next level down
447 # exists. If not then create it. Recurse into the next object down.
448 else
449 {
450 # Split object name up into segments and determine current segment
451 my @objSegments = split(/[.]/, $name);
452 my $currSegment = $objSegments[$depth];
453  
454 # If the node has already been declared as an object, can't give it children
455 if($type eq 'object')
456 {
457 &error("Attempt to make '$name' a group when it's already an object");
458 return $ERROR;
459 }
460  
461 $self->{type} = "group" if ($type eq '');
462  
463 &log("Searching for sub-object '$currSegment'") if ($VERBOSE > 2);
464  
465 # Locate the pointer to the sub object referenced by the current name segment
466 my $ptr = $self->{childObjList}->{$currSegment};
467  
468 # If the sub object doesn't exist yet, then allocate one
469 unless ($ptr)
470 {
471 $subName = join('.',@objSegments[0..$depth]);
472  
473 $ptr = $self->{childObjList}->{$currSegment} = new VBTK::Objects(
474 Name => $subName,
475 SegmentName => $currSegment);
476  
477 # Select a template to inherit defaults from
478 $ptr->selectTemplate;
479 }
480  
481 # Increment the depth counter and recurse into the child object
482 $args{Depth}++;
483 $retval = $ptr->recurseSetStatus(%args);
484  
485 # A negative return value indicates an error, so just pass the error back.
486 return $retval if ($retval < 0);
487  
488 # If no change was made to the status, there is no need to update the group
489 return($NO_CHANGE) if ($retval == $NO_CHANGE);
490  
491 # Update the group status value
492 $self->updateGroup();
493 }
494 ($CHANGED);
495 }
496  
497 #-------------------------------------------------------------------------------
498 # Function: addGraphDbData
499 # Description: Use the passed data structure to update the corresponding
500 # graphing database.
501 # Input Parms: Graph data structure
502 # Output Parms: None
503 #-------------------------------------------------------------------------------
504 sub addGraphDbData
505 {
506 my $self = shift;
507 my $rrdObj = $self->{rrdObj};
508 my ($GraphStruct) = (@_);
509  
510 $rrdObj->addGraphDbData(%{$GraphStruct});
511  
512 (0);
513 }
514  
515 #-------------------------------------------------------------------------------
516 # Function: generateGraph
517 # Description: Generate and return a .png file graph with the specified attributes.
518 # Input Parms: Graph Attributes
519 # Output Parms: Png Graph Stream
520 #-------------------------------------------------------------------------------
521 sub generateGraph
522 {
523 my $self = shift;
524 my $name = $self->{Name};
525 my $rrdObj = $self->{rrdObj};
526  
527 if (! defined $rrdObj)
528 {
529 &error("Can't find Rrd Object for VBObject '$name'");
530 return undef;
531 }
532  
533 &log("Generating graph for '$name'") if ($VERBOSE > 1);
534 $rrdObj->generateGraph(@_);
535 }
536  
537 #-------------------------------------------------------------------------------
538 # Function: updateGroup
539 # Description: Look at the status and timestamp of sub objects and determine the
540 # group status and timestamp.
541 # Input Parms:
542 # Output Parms:
543 #-------------------------------------------------------------------------------
544 sub updateGroup
545 {
546 my $self = shift;
547 my $status = $self->{Status};
548 my $name = $self->{Name};
549 my ($ptr,$childStatus,$grandchildObjectName,$groupStatus);
550 my $grandchildObjectNames = {};
551  
552 &log("Updating group status of '$name'") if ($VERBOSE > 1);
553  
554 # Step through each sub object of the current object
555 foreach $ptr (values %{$self->{childObjList}})
556 {
557 # Determine the status of each sub-object and see if it's rank is higher
558 # than the current group status and set the group status accordingly.
559 $childStatus = $ptr->{Status};
560  
561 if((! defined $groupStatus)||
562 ($::VB_STATUS_RANK{$childStatus} > $::VB_STATUS_RANK{$groupStatus}))
563 {
564 $groupStatus = $childStatus;
565 }
566  
567 # Rebuild the list of grandchild nodes, just in case something was removed
568 foreach $grandchildObjectName (keys %{$ptr->{childObjList}})
569 {
570 $grandchildObjectNames->{$grandchildObjectName} = 1;
571 }
572 }
573  
574 # If the status changed, then store the new status.
575 if($groupStatus ne $status)
576 {
577 &log("Updating group status of '$name' to '$groupStatus'")
578 if ($VERBOSE > 1);
579 $self->{Status} = $groupStatus;
580 }
581  
582 # Store the new list of grandchildObjectNames
583 $self->{grandchildObjectNames} = $grandchildObjectNames;
584  
585 (0);
586 }
587  
588 #-------------------------------------------------------------------------------
589 # Function: updateExpirTime
590 # Description: Update the expiration time of the object based on the expiration
591 # rule.
592 # Input Parms:
593 # Output Parms: Status
594 #-------------------------------------------------------------------------------
595 sub updateExpirTime
596 {
597 my $self = shift;
598 my $template = $self->{template};
599 my $Timestamp = $self->{Timestamp};
600  
601 my $ExpireAfter = $self->{ExpireAfter} || $template->getExpireAfter;
602  
603 # If no expiration was specified, then just return
604 return 0 if (! defined $ExpireAfter);
605  
606 &log("Current timestamp is '$Timestamp'") if ($VERBOSE > 2);
607  
608 # Use the Date::Manip perl library to calculate the new expiration datetime.
609 my $expireAfterSec = &deltaSec($ExpireAfter) || return 0;
610 my $newExpireTimestamp = $Timestamp + $expireAfterSec;
611 &log("Used '$ExpireAfter' to set new expir to '$newExpireTimestamp'")
612 if ($VERBOSE > 2);
613  
614 $self->{expireTime} = $newExpireTimestamp;
615 (0);
616 }
617  
618 #-------------------------------------------------------------------------------
619 # Function: checkForExpiration
620 # Description: Check all sub-objects to see if they have expired and if so, set
621 # their status to expired, moving the current status to 'last_status'.
622 # Check also to see if their object files have been deleted and if
623 # so, remove them from the object tree in memory.
624 # Input Parms: object_name
625 # Output Parms: Status
626 #-------------------------------------------------------------------------------
627 sub checkForExpiration
628 {
629 my $self = shift;
630 my $now = shift;
631  
632 my $name = $self->{Name};
633 my $type = $self->{type};
634 my $childObjList = $self->{childObjList};
635 my $expireTime = $self->{expireTime};
636 my $status = $self->{Status};
637  
638 my ($ptr,$childObj,$childObjName,$result,$recalcGroupFlg);
639  
640 $now = time unless ($now);
641  
642 # Groups don't have an expiration time, so just recurse down.
643 if((defined $type)&&($type eq 'group'))
644 {
645 # Step through each child object.
646 while(($childObjName,$childObj) = each %{$childObjList})
647 {
648 $result = $childObj->checkForExpiration($now);
649  
650 # If $DELETED, then remove it as a child
651 if($result == $DELETED)
652 {
653 &log("Removing $name.$childObjName") if ($VERBOSE);
654 delete($childObjList->{$childObjName});
655 delete $NAME_CACHE{"$name.$childObjName"};
656 }
657  
658 $recalcGroupFlg = 1 if ($result ne $NO_CHANGE);
659 }
660  
661 # Check to see if all sub-objects have been deleted
662 if((keys %{$childObjList}) == 0)
663 {
664 ($DELETED);
665 }
666 # Otherwise, if anything changed, then update the group.
667 elsif($recalcGroupFlg)
668 {
669 $self->updateGroup();
670 ($CHANGED);
671 }
672 else
673 {
674 ($NO_CHANGE);
675 }
676 }
677 # Only need to check expiration/deletion of the lowest level objects
678 else
679 {
680 &log("Checking to see if $VB_OBJ_FILE_DIR/$name has been deleted")
681 if ($VERBOSE > 1);
682  
683 # Check to see if the files in vbobj have been deleted
684 if( ! -d "$VB_OBJ_FILE_DIR/$name")
685 {
686 &log("$VB_OBJ_FILE_DIR/$name has been deleted");
687 ($DELETED);
688 }
689 else
690 {
691 &log("Checking expiration date of '$name' - $expireTime")
692 if(($VERBOSE > 1)&&($expireTime));
693 if(($expireTime)&&($now > $expireTime)&&($status ne $::EXPIRED))
694 {
695 $self->recurseSetStatus(
696 Name => $name,
697 Status => $::EXPIRED,
698 Time => $now);
699  
700 ($CHANGED);
701 }
702 else
703 {
704 ($NO_CHANGE);
705 }
706 }
707 }
708 }
709  
710 #-------------------------------------------------------------------------------
711 # Function: deleteHistoryItem
712 # Description: Delete an entry from the object history
713 # Input Parms: None
714 # Output Parms: None
715 #-------------------------------------------------------------------------------
716 sub deleteHistoryItem
717 {
718 my $self = shift;
719 my ($pos) = @_;
720  
721 my $name = $self->{Name};
722 my $historyObjList = $self->{historyObjList};
723  
724 # Get the specified history object and the one previous to it.
725 my $histObj = $historyObjList->[$pos];
726 my $prevHistObj = $historyObjList->[$pos-1];
727  
728 # Return if the specified history entry doesn't exist
729 return 0 if (! defined $histObj);
730  
731 # Get their timestamps
732 my $histFile = $histObj->getFileName;
733 my $prevHistFile = $prevHistObj->getFileName if (defined $prevHistObj);
734  
735 &log("Removing element '$pos' from the history array") if ($VERBOSE > 2);
736 splice(@{$historyObjList},$pos,1);
737  
738 # In the rare case that the status was set twice in the same second, the
739 # obj file and historyObjIndex pointer have already been overwritten, so we
740 # don't want to delete them again, or we'll lose data.
741 if($prevHistFile ne $histFile)
742 {
743 $histObj->delete;
744 delete $self->{historyObjIndex}->{$histFile};
745 }
746  
747 (0);
748 }
749  
750 #-------------------------------------------------------------------------------
751 # Function: deleteObject
752 # Description: Delete an object along with all of it's history files
753 # Input Parms: Object name
754 # Output Parms: None
755 #-------------------------------------------------------------------------------
756 sub deleteObject
757 {
758 my $self = shift;
759 my %args = @_;
760  
761 my $name = $args{Name};
762 my $depth = $args{Depth};
763  
764 my $currName = $self->{Name};
765 my $type = $self->{type};
766 my $historyObjList = $self->{historyObjList};
767  
768 my ($ptr,$child_ptr,$retval,$file,@fileList,$childName);
769  
770 $depth = 0 if ($depth < 1);
771 $name = $currName if (! defined $name);
772  
773 &log("Delete - Entering object '$currName'") if ($VERBOSE > 2);
774  
775 # If this is the lowest level object, then set the status and return.
776 if ($name eq $currName)
777 {
778 &log("Deleting object '$currName'") if ($VERBOSE);
779  
780 # If this is a group, then delete all the child objects recursively.
781 if($type eq 'group')
782 {
783 foreach $ptr (values %{$self->{childObjList}})
784 {
785 $ptr->deleteObject();
786 }
787 }
788 # Otherwise clear out the history items and unlink the vbobj
789 # directory.
790 else
791 {
792 @fileList = <$VB_OBJ_FILE_DIR/$currName/*>;
793 foreach $file (@fileList)
794 {
795 &log("Deleting object file '$file'") if ($VERBOSE);
796 unlink("$file");
797 }
798 unlink("$VB_OBJ_FILE_DIR/$currName");
799 }
800 }
801 else
802 {
803 # Split object name up into segments and determine current segment
804 my @objSegments = split(/[.]/, $name);
805 my $currSegment = $objSegments[$depth];
806  
807 &log("Searching for sub-object '$currSegment'") if ($VERBOSE > 1);
808  
809 # Locate the pointer to the sub object referenced by the current name segment
810 my $ptr = $self->{childObjList}->{$currSegment};
811  
812 # If the sub object doesn't exist then complain
813 if ($ptr eq '')
814 {
815 &error("Attempt to delete non-existant node '$currName'");
816 return $ERROR;
817 }
818  
819 # Recurse into the sub object
820 $retval = $ptr->deleteObject(Name => $name, Depth => ($depth+1));
821  
822 # If the target of the delete is the immediate child, then unlink the
823 # child object.
824 $childName = join('.',@objSegments[0..($depth+1)]);
825 if($childName eq $name)
826 {
827 &log("Unlinking child object") if ($VERBOSE > 2);
828 delete $self->{childObjList}->{$currSegment};
829 delete $NAME_CACHE{$childName};
830 }
831  
832 # A negative return value indicates an error, so just pass the error back.
833 return $retval if ($retval < 0);
834  
835 # Update the group status value
836 $self->updateGroup();
837 }
838  
839 (0);
840 }
841  
842 #-------------------------------------------------------------------------------
843 # Function: selectTemplate
844 # Description: Use pattern matching to select the template for this object.
845 # Input Parms: None
846 # Output Parms: None
847 #-------------------------------------------------------------------------------
848 sub selectTemplate
849 {
850 my $self = shift;
851 my $name = $self->{Name};
852 my ($template,$Pattern);
853  
854 &log("Setting defaults for '$name'") if ($VERBOSE > 1);
855 foreach $template (@VB_TEMPLATE_LIST)
856 {
857 $Pattern = $template->{Pattern};
858  
859 &log("Checking '$name' against pattern '$Pattern'") if ($VERBOSE > 2);
860 next unless $name =~ /$Pattern/;
861  
862 &log("Using template '$Pattern' for object '$name'") if ($VERBOSE > 1);
863  
864 $self->{template} = $template;
865  
866 # Only use the first match
867 last;
868 }
869 (0);
870 }
871  
872 #-------------------------------------------------------------------------------
873 # Function: validateActions
874 # Description: Check all the action names listed in the StatusChangeActions rules
875 # and make sure they are all real actions. We should only run this
876 # if a client process just passed in some new action rules.
877 # Input Parms: None
878 # Output Parms: None
879 #-------------------------------------------------------------------------------
880 sub validateActions
881 {
882 my $self = shift;
883 my $name = $self->{Name};
884 my $StatusChangeActions = $self->{StatusChangeActions};
885 my $historyObjList = $self->{historyObjList};
886 my ($changeActionObj,$badActionList,$msg);
887  
888 return 0 if (! defined $StatusChangeActions);
889  
890 foreach $changeActionObj (@{$StatusChangeActions})
891 {
892 next if ($changeActionObj->validateActionNames);
893  
894 # If we made it this far, then one of the action names is bad
895 $self->{Status} = $::FAILED;
896 $badActionList = $changeActionObj->getActionList;
897 $msg = "Invalid action name in list '$badActionList', setting status to " .
898 $::FAILED;
899 &error("$msg");
900 $historyObjList->[0]->addHeaderMsg("$msg\n");
901 }
902 (0);
903 }
904  
905 #-------------------------------------------------------------------------------
906 # Function: checkForStatusChangeAction
907 # Description: Check for an action associated with a status change for the
908 # current object and execute it if one is found.
909 # Input Parms: Status
910 # Output Parms: None
911 #-------------------------------------------------------------------------------
912 sub checkForStatusChangeAction
913 {
914 my $self = shift;
915 my $status = $self->{Status};
916 my $name = $self->{Name};
917 my $histFile = $self->{histFile};
918 my $ChangeActionObjList = $self->getChangeActionObjList($status);
919  
920 my ($action,$action_ptr,$msgText,$actionName,$changeActionObj);
921  
922 &log("Status changed to '$status', looking for status change actions")
923 if ($VERBOSE > 1);
924  
925 return 0 if (@{$ChangeActionObjList} < 1);
926  
927 if ($VBVIEW_EXT_URL ne '')
928 {
929 $msgText = "See: ${VBVIEW_EXT_URL}?name=$name&histFile=$histFile";
930 }
931  
932 foreach $changeActionObj (@{$ChangeActionObjList})
933 {
934 $changeActionObj->checkForActions($status,$name,$msgText);
935 }
936 (0);
937 }
938  
939 #-------------------------------------------------------------------------------
940 # Function: checkForStatusUpgrade
941 # Description: Check to see if the object qualifies for a status upgrade
942 # Input Parms: None
943 # Output Parms: New Status
944 #-------------------------------------------------------------------------------
945 sub checkForStatusUpgrade
946 {
947 my $self = shift;
948 my $status = $self->{Status};
949  
950 my $historyObjList = $self->{historyObjList};
951 my $UpgradeRuleObjList = $self->getUpgradeRuleObjList($status);
952  
953 return $status if (@{$UpgradeRuleObjList} < 1);
954  
955 my $upgradeTo = $::SUCCESS;
956 my ($newStatus,$ruleObj);
957  
958 &log("Checking for status upgrade") if ($VERBOSE > 1);
959  
960 foreach $ruleObj (@{$UpgradeRuleObjList})
961 {
962 $newStatus = $ruleObj->checkForUpgrade($status,$historyObjList);
963 $upgradeTo = &find_higher_status($upgradeTo,$newStatus);
964 }
965  
966 # Decide which status is higher, and then store it in the current object as well
967 # as in the history object
968 $status = &find_higher_status($status,$upgradeTo);
969 $self->{Status} = $status;
970 $historyObjList->[0]->setStatus($status);
971  
972 ($status);
973 }
974  
975 #-------------------------------------------------------------------------------
976 # Function: cleanHistory
977 # Description: Scan through the object history, removing duplicates and incrementing
978 # the 'repeated' counter. Also, remove any entries older than the
979 # StatusHistoryLimit value.
980 # Input Parms: None
981 # Output Parms: None
982 #-------------------------------------------------------------------------------
983 sub cleanHistory
984 {
985 my $self = shift;
986  
987 my $h = $self->{historyObjList};
988 my $template = $self->{template};
989  
990 my $StatusHistoryLimit = $self->{StatusHistoryLimit} ||
991 $template->{StatusHistoryLimit};
992  
993 my $hLen = @{$h};
994 my ($startHistory,$timestamp,$historyLimitSec);
995  
996 &log("Cleaning history") if ($VERBOSE > 1);
997  
998 # If the 1st, 2nd, and 3rd history items all have the same status
999 # then consolidate the 2nd into the 1st, incrementing the 'repeated'
1000 # counter of the 1st. Also, preserve the repeatStart value from the
1001 # 2nd history item.
1002 if (($hLen > 2) &&
1003 ($h->[0]->getStatus eq $h->[1]->getStatus) &&
1004 ($h->[0]->getStatus eq $h->[2]->getStatus))
1005 {
1006 &log("Consolidating 1st & 2nd entries in history") if ($VERBOSE > 2);
1007 $h->[0]->addToRepeated($h->[1]->getRepeated);
1008 $h->[0]->setRepeatStart($h->[1]->getRepeatStart);
1009 $self->deleteHistoryItem(1);
1010 $hLen--;
1011 }
1012  
1013 # Just return if there's no StatusHistoryLimit entry
1014 return 0 if ($StatusHistoryLimit eq '');
1015  
1016 &log("Checking history limit of '$StatusHistoryLimit'") if ($VERBOSE > 1);
1017  
1018 # If the 'StatusHistoryLimit' entry is just an integer, then it means that
1019 # that is the total number of allowed history entries, so just trim off
1020 # all the entries over that count.
1021 if($StatusHistoryLimit =~ /^\d+$/)
1022 {
1023 while($hLen > $StatusHistoryLimit)
1024 {
1025 &log("Removing history entry #$hLen") if ($VERBOSE > 2);
1026 $self->deleteHistoryItem($hLen - 1);
1027 $hLen--;
1028 }
1029 }
1030 # Otherwise it's a date string and we need to run DateCalc to find the
1031 # starting cutoff.
1032 else
1033 {
1034 $historyLimitSec = &deltaSec($StatusHistoryLimit);
1035 $startHistory = time - $historyLimitSec;
1036 $timestamp = $h->[$hLen - 1]->getTimestamp;
1037  
1038 &log("Searching for history timestamps prior to '$startHistory'")
1039 if ($VERBOSE > 2);
1040  
1041 while($timestamp < $startHistory)
1042 {
1043 &log("Removing history entry for $timestamp") if ($VERBOSE > 2);
1044 $self->deleteHistoryItem($hLen - 1);
1045 $hLen--;
1046 $timestamp = $h->[$hLen - 1]->getTimestamp;
1047 }
1048 }
1049  
1050 (0);
1051 }
1052  
1053 #-------------------------------------------------------------------------------
1054 # Function: importObjects
1055 # Description: Import all objects from the object files in the VB_OBJ_FILE_DIR
1056 # Input Parms: None
1057 # Output Parms: None
1058 #-------------------------------------------------------------------------------
1059 sub importObjects
1060 {
1061 my $self = shift;
1062 my ($object,$objName,$objDir);
1063  
1064 &log("Importing all objects in '$VB_OBJ_FILE_DIR'");
1065  
1066 # Get a listing of subdirectories in the vbobj directory
1067 my @objList = grep((-d $_),<$VB_OBJ_FILE_DIR/*>);
1068  
1069 # Step through each directory.
1070 foreach $objDir (@objList)
1071 {
1072 $objName = basename($objDir);
1073  
1074 # Skip '.' and '..';
1075 next if ($objName =~ /^\./);
1076  
1077 &log("Importing object dir '$objDir'") if ($VERBOSE > 1);
1078  
1079 # Create the object. By passing no status value, we'll cause it to
1080 # load itself from it's history.
1081 $self->recurseSetStatus(Name => $objName);
1082 }
1083  
1084 # Step through all group objects and update the group statuses
1085 &log("Updating all group statuses");
1086 foreach $objName (reverse sort keys %NAME_CACHE)
1087 {
1088 $object=$NAME_CACHE{$objName};
1089 $object->updateGroup() if ((defined $object->{type}) &&
1090 ($object->{type} eq 'group'));
1091 }
1092 (0);
1093 }
1094  
1095 #-------------------------------------------------------------------------------
1096 # Function: loadMetaData
1097 # Description: Load metat data about this object
1098 # Input Parms: None
1099 # Output Parms: None
1100 #-------------------------------------------------------------------------------
1101 sub loadMetaData
1102 {
1103 my $self = shift;
1104 my $Name = $self->{Name};
1105 my $metaFileObj = $self->{metaFileObj};
1106  
1107 return 0 unless ($metaFileObj->exists);
1108  
1109 &log("Loading meta data for '$Name'") if ($VERBOSE > 1);
1110  
1111 my $struct = $metaFileObj->serGet;
1112  
1113 return undef if (! defined $struct);
1114  
1115 $self->set(%{$struct});
1116  
1117 (1);
1118 }
1119  
1120 #-------------------------------------------------------------------------------
1121 # Function: storeMetaData
1122 # Description: Write the some parms we want to be persistent out to a file
1123 # Input Parms: None
1124 # Output Parms: True | False
1125 #-------------------------------------------------------------------------------
1126 sub storeMetaData
1127 {
1128 my $self = shift;
1129 my $Name = $self->{Name};
1130 my $metaFileObj = $self->{metaFileObj};
1131  
1132 # Create a structure containing just the object members which we want to
1133 # be persistent.
1134 my $struct = { map { $_ => $self->{$_} } @PERSISTENT_PARMS };
1135  
1136 &log("Saving meta data for '$Name'") if ($VERBOSE > 1);
1137 $metaFileObj->serPut($struct) || return undef;
1138  
1139 (1);
1140 }
1141  
1142 #-------------------------------------------------------------------------------
1143 # Function: loadAllHistory
1144 # Description: Find all history objects stored in the object's vbobj directory and
1145 # create objects for them, returning an array of objects.
1146 # Input Parms: Object Dir
1147 # Output Parms: Array of history objects
1148 #-------------------------------------------------------------------------------
1149 sub loadAllHistory
1150 {
1151 my $self = shift;
1152 my $name = $self->{Name};
1153 my $historyObjList = $self->{historyObjList};
1154 my $historyObjIndex = $self->{historyObjIndex};
1155 my $vbObjPath = $VB_OBJ_FILE_DIR;
1156  
1157 my ($file,$timestamp,$histObj,$count,$histFile);
1158  
1159 my @histFileList = reverse sort <$vbObjPath/$name/[0-9]*.ser>;
1160 my $cacheMode = $VBTK::Objects::History::NOTEXT;
1161  
1162 # Loop through the history entries from oldest to newest
1163 foreach $file (@histFileList)
1164 {
1165 $file =~ /([^\/]+)\.ser$/;
1166 $histFile = $1;
1167
1168 # Only cache data for the first two entries, the rest will be
1169 # loaded on demand.
1170 $cacheMode = $VBTK::Objects::History::MINIMAL if (++$count > 2);
1171  
1172 $histObj = new VBTK::Objects::History(
1173 ObjPath => $vbObjPath,
1174 ObjName => $name,
1175 FileName => $histFile,
1176 CacheMode => $cacheMode);
1177  
1178 next if (! defined $histObj);
1179
1180 push(@{$historyObjList},$histObj);
1181 $historyObjIndex->{$histFile} = $histObj;
1182 }
1183  
1184 # Initialize a few entries in the object itself if any history entries
1185 # were found.
1186 if (defined $historyObjList->[0])
1187 {
1188 $self->{Status} = $historyObjList->[0]->getStatus;
1189 $self->{Timestamp} = $historyObjList->[0]->getTimestamp;
1190 $self->{expireTime} = $historyObjList->[0]->getExpireTime;
1191 $self->{histFile} = $historyObjList->[0]->getFileName;
1192 }
1193  
1194 (1);
1195 }
1196  
1197 #-------------------------------------------------------------------------------
1198 # Function: addObjectTemplate
1199 # Description: Add an object template to the global array of templates
1200 # Input Parms: Object pattern
1201 # Output Parms: None
1202 #-------------------------------------------------------------------------------
1203 sub addObjectTemplate
1204 {
1205 my $self = shift;
1206 my $template = shift;
1207  
1208 push(@VB_TEMPLATE_LIST,$template);
1209 (0);
1210 }
1211  
1212 #-------------------------------------------------------------------------------
1213 # Function: getMatrixList
1214 # Description: Return a list of top level objects used as the starting point
1215 # for each matrix to be displayed. Note that if a name is specified,
1216 # then only that top-level object will be returned.
1217 # Input Parms: Object Name
1218 # Output Parms: Array List of top level objects
1219 #-------------------------------------------------------------------------------
1220 sub getMatrixList
1221 {
1222 my $self = shift;
1223 my $name = $self->{Name};
1224 my ($targetObj,$ptr,@matrixList,$child);
1225  
1226 &log("Retrieving matrix list for object '$name'") if ($VERBOSE > 1);
1227  
1228 # If no name was passed, then return a list of child objects of this object.
1229 if ($name eq $::MASTER_NODE)
1230 {
1231 foreach $child (sort keys %{$self->{childObjList}})
1232 {
1233 $ptr = $self->{childObjList}->{$child};
1234 push(@matrixList,$ptr);
1235 }
1236 (@matrixList);
1237 }
1238 # If a name was passed, then lookup the object associated with that name
1239 # and return it.
1240 else
1241 {
1242 ($self);
1243 }
1244 }
1245  
1246 #-------------------------------------------------------------------------------
1247 # Function: getHistoryObjList
1248 # Description: Retrieve a list of history objects. If a timestamp is passed,
1249 # then limit the list to just the object with the matching timestamp
1250 # Input Parms: Optional timestamp
1251 # Output Parms: Array of history objects
1252 #-------------------------------------------------------------------------------
1253 sub getHistoryObjList
1254 {
1255 my $self = shift;
1256 my $histFile = shift;
1257 my $name = $self->{Name};
1258 my $historyObjList = $self->{historyObjList};
1259 my $historyObjIndex = $self->{historyObjIndex};
1260  
1261 if ($histFile)
1262 {
1263 &log("Retrieving history object for '$name' - '$histFile'")
1264 if ($VERBOSE > 1);
1265  
1266 ($historyObjIndex->{$histFile});
1267 }
1268 else
1269 {
1270 &log("Retrieving all history objects for '$name'") if ($VERBOSE > 1);
1271  
1272 (@{$historyObjList});
1273 }
1274 }
1275  
1276 #-------------------------------------------------------------------------------
1277 # Function: getUpgradeRuleObjList
1278 # Description: Return a list of upgrade rule objects for this object. If a status
1279 # is specified, then only get rules which correspond to the passed
1280 # status.
1281 # Input Parms: Status
1282 # Output Parms: Array List of rule objects
1283 #-------------------------------------------------------------------------------
1284 sub getUpgradeRuleObjList
1285 {
1286 my $self = shift;
1287 my $status = shift;
1288  
1289 my $template = $self->{template};
1290 my $UpgradeRuleObjList = $self->{UpgradeRuleObjList} ||
1291 $template->getUpgradeRuleObjList;
1292  
1293 my $result = [];
1294  
1295 return $result if (! defined $UpgradeRuleObjList);
1296  
1297 my ($ruleObj,$testStatus);
1298  
1299 foreach $ruleObj (@{$UpgradeRuleObjList})
1300 {
1301 $testStatus = $ruleObj->getTestStatus;
1302  
1303 push(@{$result},$ruleObj) if (($testStatus eq $status)||(! defined $status));
1304 }
1305  
1306 ($result);
1307 }
1308  
1309  
1310 #-------------------------------------------------------------------------------
1311 # Function: getStatusChangeActionObjList
1312 # Description: Return a list of status change action objects for this object.
1313 # If a status is specified, then only get rules which correspond
1314 # to the passed status.
1315 # Input Parms: Status
1316 # Output Parms: Array List of status change action objects
1317 #-------------------------------------------------------------------------------
1318 sub getChangeActionObjList
1319 {
1320 my $self = shift;
1321 my $status = shift;
1322  
1323 my $template = $self->{template};
1324 my $ChangeActionObjList = $self->{ChangeActionObjList} ||
1325 $template->getChangeActionObjList;
1326  
1327 my $result = [];
1328  
1329 return $result if (! defined $ChangeActionObjList);
1330  
1331 my ($ruleObj,$testStatus);
1332  
1333 foreach $ruleObj (@{$ChangeActionObjList})
1334 {
1335 $testStatus = $ruleObj->getTestStatus;
1336  
1337 push(@{$result},$ruleObj) if (($testStatus eq $status)||(! defined $status));
1338 }
1339  
1340 ($result);
1341 }
1342  
1343 #-------------------------------------------------------------------------------
1344 # Function: getGraphGroupObjList
1345 # Description: Retrieve the graph group definitions for the specified graph
1346 # group number. Default the group number to the first on the list
1347 # if not specified.
1348 # Input Parms: Group Number
1349 # Output Parms: Graph Group Object List
1350 #-------------------------------------------------------------------------------
1351 sub getGraphGroupObjList
1352 {
1353 my $self = shift;
1354 my $groupNumber = shift;
1355 my $GraphGroupList = $self->{GraphGroupList};
1356 my @groupNumberList;
1357  
1358 if (! defined $groupNumber)
1359 {
1360 @groupNumberList = $self->getGraphGroupNumberList;
1361 $groupNumber = $groupNumberList[0];
1362 }
1363  
1364 my $graphObjList = $GraphGroupList->{$groupNumber};
1365  
1366 @{$graphObjList};
1367 }
1368  
1369 #-------------------------------------------------------------------------------
1370 # Function: getGraphGroupNumberList
1371 # Description: Retrieve a list of valid graph group numbers for this object.
1372 # Input Parms: Group Number
1373 # Output Parms: Graph Group Number List
1374 #-------------------------------------------------------------------------------
1375 sub getGraphGroupNumberList
1376 {
1377 my $self = shift;
1378 my $GraphGroupList = $self->{GraphGroupList};
1379  
1380 sub byNumber { $a <=> $b }
1381 sort byNumber keys %{$GraphGroupList};
1382 }
1383  
1384 #-------------------------------------------------------------------------------
1385 # Function: getUpgradeRuleObjText
1386 # Description: Retrieve an array of text describing the upgrade rules
1387 # Input Parms: None
1388 # Output Parms: Array of text describing the upgrade rules for this object
1389 #-------------------------------------------------------------------------------
1390 sub getUpgradeRuleObjText
1391 {
1392 my $self = shift;
1393 my $UpgradeRuleObjList = $self->{UpgradeRuleObjList};
1394 return () if (! defined $UpgradeRuleObjList);
1395  
1396 map { $_->getRuleText } @{$UpgradeRuleObjList};
1397 }
1398  
1399 #-------------------------------------------------------------------------------
1400 # Function: getChangeActionObjText
1401 # Description: Retrieve an array of text describing the change actions
1402 # Input Parms: None
1403 # Output Parms: Array of text describing the change actions for this object
1404 #-------------------------------------------------------------------------------
1405 sub getChangeActionObjText
1406 {
1407 my $self = shift;
1408 my $ChangeActionObjList = $self->{ChangeActionObjList};
1409 return () if (! defined $ChangeActionObjList);
1410  
1411 map { $_->getRuleText } @{$ChangeActionObjList};
1412 }
1413  
1414 # Simple Get Methods
1415 sub getObject { $NAME_CACHE{$_[1]}; }
1416 sub getFullName { $_[0]->{Name}; }
1417 sub getHistFile { $_[0]->{histFile}; }
1418 sub getSegName { $_[0]->{SegmentName}; }
1419 sub getTimestamp { $_[0]->{Timestamp}; }
1420 sub getTimestampText { ($_[0]->{Timestamp}) ? &UnixDate("epoch $_[0]->{Timestamp}","%C") : "None"; }
1421 sub getStatus { $_[0]->{Status}; }
1422 sub getExpiration { $_[0]->{expireTime}; }
1423 sub getExpirationText { ($_[0]->{expireTime}) ? &UnixDate("epoch $_[0]->{expireTime}","%C") : "None"; }
1424 sub getNameSegments { split(/\./,$_[0]->{Name}); }
1425 sub getGrandChildNames { sort keys %{$_[0]->{grandchildObjectNames}}; }
1426 sub getGrandChildCount { (keys %{$_[0]->{grandchildObjectNames}}) + 0; }
1427 sub getChildObjects { map { $_[0]->{childObjList}->{$_} } sort keys %{$_[0]->{childObjList}}; }
1428 sub getChildNames { sort keys %{$_[0]->{childObjList}}; }
1429 sub getChild { $_[0]->{childObjList}->{$_[1]}; }
1430 sub isGroup { ($_[0]->{type} eq 'group'); }
1431 sub getRrdObj { $_[0]->{rrdObj}; }
1432 sub getTemplate { $_[0]->{template}; }
1433 sub getBaselineText { $_[0]->{baselineFileObj}->get; }
1434 sub getRunningFrom { $_[0]->{RunningFrom}; }
1435 sub getScriptName { $_[0]->{ScriptName}; }
1436 sub getLogFile { $_[0]->{LogFile}; }
1437  
1438 sub getBaselineDiffStatus { $_[0]->{BaselineDiffStatus}; }
1439 sub getInterval { $_[0]->{Interval}; }
1440  
1441 # These get methods will use the template value if no direct value was specified.
1442 sub getExpireAfter { $_[0]->{ExpireAfter}; }
1443 sub getDescription { $_[0]->{Description}; }
1444  
1445 # Simple Set Methods
1446 sub setBaselineText { $_[0]->{baselineFileObj}->put($_[1]); }
1447  
1448  
1449 #-------------------------------------------------------------------------------
1450 # Function: FindObjByName
1451 # Description: Locate the specified object by name
1452 # Input Parms: Object name
1453 # Output Parms: Object pointer
1454 #-------------------------------------------------------------------------------
1455 sub FindObjByName
1456 {
1457 my ($objName) = @_;
1458  
1459 if ((! defined $objName)||($objName eq ''))
1460 {
1461 $objName = $::MASTER_NODE;
1462 }
1463 else
1464 {
1465 # If the object name starts with a '.' then prepend the default prefix
1466 $objName = $DEFAULT_PREFIX . $objName if ($objName =~ /^\./);
1467
1468 # Make sure no invalid characters were passed in
1469 if ($objName =~ /[^\w\@\.-]/)
1470 {
1471 &error("Invalid object name '$objName', ignoring");
1472 return $ERROR;
1473 }
1474 }
1475  
1476 my $targetObj = $NAME_CACHE{$objName};
1477  
1478 &log("Unable to find object '$objName' on this server")
1479 if ((! defined $targetObj)&&($VERBOSE > 1));
1480  
1481 ($targetObj);
1482 }
1483  
1484 1;
1485 __END__