# MonArch - Groundwork Monitor Architect
# MonarchTree.pm
#
############################################################################
# Release 4.0
# November 2011
############################################################################
#
# Original author: Scott Parris
#
# Copyright 2007-2011 GroundWork Open Source, Inc. (GroundWork)
# All rights reserved. This program is free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
use strict;
use URI::Escape;
use MonarchInstrument;
package Tree;
my $SERVER_SOFTWARE = $ENV{SERVER_SOFTWARE};
my $monarch_cgi;
my $monarch_css;
my $monarch_html;
my $monarch_images;
my $monarch_js;
if (defined($SERVER_SOFTWARE) && $SERVER_SOFTWARE eq 'TOMCAT') {
$monarch_cgi = '/monarch';
$monarch_css = '/monarch/css';
$monarch_html = '/monarch/html';
$monarch_images = '/monarch/images';
$monarch_js = '/monarch/js';
}
elsif ( -e '/usr/local/groundwork/config/db.properties' ) {
$monarch_cgi = '/monarch/cgi-bin';
$monarch_css = '/monarch';
$monarch_html = '/monarch';
$monarch_images = '/monarch/images';
$monarch_js = '/monarch';
}
else {
# Standalone Monarch (outside of GW Monitor) is no longer supported.
}
my $cgi_exe = 'monarch.cgi';
my $form_class = 'row1';
my $global_cell_pad = 3;
my $debug = 0;
sub header(@) {
my $title = $_[1];
my $load_main = undef;
unless ( $_[2] ) {
$load_main = "\"onload=\"parent.monarch_main.location=\'$monarch_html/blank.html\'\"";
}
return qq(
@{[&$Instrument::show_trace_as_html_comment()]}
$title
);
}
sub get_ajax_url() {
my $nocache = time;
return "$monarch_cgi/monarch_tree.cgi?nocache=$nocache";
}
sub footer(@) {
my $debug = $_[1];
return qq(@{[&$Instrument::show_trace_as_html_comment()]}
);
return $tree;
}
sub child_tree(@) {
my @nodes = @{ $_[1] };
my $type = $_[2];
my $level = $_[3];
my $levels = $_[4];
my $last_node = $_[5];
my $qstr = $_[6];
my $sub_type = $_[7];
my $ez = $_[8];
use URI::Escape;
my $id = rand();
my $i = 0;
my $next_level = $level + 1;
my $table = qq(@{[&$Instrument::show_trace_as_html_comment()]}
);
my $indent = '';
for ( my $l = 1 ; $l <= $level ; $l++ ) {
$indent .= qq(@{[&$Instrument::show_trace_as_html_comment()]}
);
}
if (@nodes) {
my $obj_view = '';
if ( $type eq 'host_services' && $level == $levels ) {
$last_node = uri_escape($last_node);
$id++;
$obj_view = '&name=';
$table .= qq(@{[&$Instrument::show_trace_as_html_comment()]}
);
}
elsif ( $level == $levels ) {
my $gif = $gif{"$type\_child"};
if ( $type eq 'groups' ) {
$gif = $gif{"$node\_child"};
$obj_view = "obj_view=$name&name=$last_node";
$name = undef;
$node = "\u$node";
$node =~ s/_/ /g;
}
# Encoding fixes the text so the browser understands it -- but
# I don't know why this is necessary here and not in the right-side panel.
utf8::encode($node);
$table .= qq(@{[&$Instrument::show_trace_as_html_comment()]}