VBTK

 view release on metacpan or  search on metacpan

VBTK/Objects.pm  view on Meta::CPAN

        }

        $self->{type} = "group" if ($type eq '');

        &log("Searching for sub-object '$currSegment'") if ($VERBOSE > 2);

        # Locate the pointer to the sub object referenced by the current name segment
        my $ptr = $self->{childObjList}->{$currSegment};

        # If the sub object doesn't exist yet, then allocate one
        unless ($ptr)
        {
            $subName = join('.',@objSegments[0..$depth]);

            $ptr = $self->{childObjList}->{$currSegment} = new VBTK::Objects(
                Name        => $subName,
                SegmentName => $currSegment);

            # Select a template to inherit defaults from 
            $ptr->selectTemplate;
        }

        # Increment the depth counter and recurse into the child object
        $args{Depth}++;
        $retval = $ptr->recurseSetStatus(%args);

        # A negative return value indicates an error, so just pass the error back.
        return $retval if ($retval < 0);

        # If no change was made to the status, there is no need to update the group
        return($NO_CHANGE) if ($retval == $NO_CHANGE);

        # Update the group status value
        $self->updateGroup();
    }
    ($CHANGED);
}

#-------------------------------------------------------------------------------
# Function:     addGraphDbData
# Description:  Use the passed data structure to update the corresponding 
#               graphing database.
# Input Parms:  Graph data structure
# Output Parms: None
#-------------------------------------------------------------------------------
sub addGraphDbData
{
    my $self = shift;
    my $rrdObj = $self->{rrdObj};
    my ($GraphStruct) = (@_);

    $rrdObj->addGraphDbData(%{$GraphStruct});

    (0);
}

#-------------------------------------------------------------------------------
# Function:     generateGraph
# Description:  Generate and return a .png file graph with the specified attributes.
# Input Parms:  Graph Attributes
# Output Parms: Png Graph Stream
#-------------------------------------------------------------------------------
sub generateGraph
{
    my $self = shift;
    my $name = $self->{Name};
    my $rrdObj = $self->{rrdObj};

    if (! defined $rrdObj)
    {
        &error("Can't find Rrd Object for VBObject '$name'");
        return undef;
    }

    &log("Generating graph for '$name'") if ($VERBOSE > 1);    
    $rrdObj->generateGraph(@_);
}

#-------------------------------------------------------------------------------
# Function:     updateGroup
# Description:  Look at the status and timestamp of sub objects and determine the
#               group status and timestamp.
# Input Parms:
# Output Parms:
#-------------------------------------------------------------------------------
sub updateGroup
{
    my $self = shift;
    my $status = $self->{Status};
    my $name = $self->{Name};
    my ($ptr,$childStatus,$grandchildObjectName,$groupStatus);
    my $grandchildObjectNames = {};

    &log("Updating group status of '$name'") if ($VERBOSE > 1);

    # Step through each sub object of the current object
    foreach $ptr (values %{$self->{childObjList}})
    {
        # Determine the status of each sub-object and see if it's rank is higher
        # than the current group status and set the group status accordingly.
        $childStatus = $ptr->{Status};

        if((! defined $groupStatus)||
           ($::VB_STATUS_RANK{$childStatus} > $::VB_STATUS_RANK{$groupStatus}))
        {
            $groupStatus = $childStatus;
        }

        # Rebuild the list of grandchild nodes, just in case something was removed
        foreach $grandchildObjectName (keys %{$ptr->{childObjList}})
        {
            $grandchildObjectNames->{$grandchildObjectName} = 1;
        }
    }

    # If the status changed, then store the new status.
    if($groupStatus ne $status)
    {
        &log("Updating group status of '$name' to '$groupStatus'")
            if ($VERBOSE > 1);
        $self->{Status} = $groupStatus;



( run in 1.694 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )