# 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()]} ); } my %obj = ( 'host_wizard' => 'hosts' ); my %gif = ( 'search' => 'search.gif', 'search_hosts' => 'search.gif', 'search_services' => 'search.gif', 'search_host_externals' => 'search.gif', 'search_service_externals' => 'search.gif', 'search_commands' => 'search.gif', 'detail' => 'file.gif', 'detail_child' => 'file.gif', 'nagios_cgi_child' => 'config.gif', 'nagios_cfg_child' => 'config.gif', 'resource_cfg_child' => 'template.gif', 'pre_flight_test_child' => 'preflight.gif', 'build_instance_child' => 'build.gif', 'export_child' => 'export.gif', 'setup' => 'config.gif', 'nagios_cgi_configuration' => 'config.gif', 'nagios_main_configuration' => 'config.gif', 'nagios_resource_macros' => 'template.gif', 'pre_flight_test' => 'preflight.gif', 'commit' => 'commit.gif', 'contacts' => 'user.gif', 'contacts_child' => 'user.gif', 'contacts_new' => 'user_new.gif', 'contact_groups' => 'users.gif', 'contact_groups_child' => 'users.gif', 'contact_groups_new' => 'users_new.gif', 'contact_templates' => 'user.gif', 'contact_templates_child' => 'user.gif', 'contact_templates_new' => 'user_new.gif', 'commands' => 'command.gif', 'commands_new' => 'command.gif', 'commands_child' => 'command.gif', 'escalations' => 'paging.gif', 'escalations_new' => 'paging.gif', 'escalations_child' => 'paging.gif', 'escalation_trees_new' => 'paging.gif', 'escalation_trees_child' => 'paging.gif', 'notifications_on' => 'paging.gif', 'notifications_off' => 'paging.gif', 'escalation_trees' => 'paging.gif', 'host_groups_new' => 'hostgroup_add.gif', 'host_groups' => 'hostgroup.gif', 'groups_child' => 'hostgroup_sm.gif', 'groups_new' => 'hostgroup_add.gif', 'groups' => 'hostgroup.gif', 'build_instances' => 'build.gif', 'macros' => 'template.gif', 'macros_new' => 'template.gif', 'macros_child' => 'template.gif', 'host_groups_child' => 'hostgroup_sm.gif', 'host_wizard' => 'clone_host.gif', 'clone_host' => 'clone_host.gif', 'import' => 'load.gif', 'discover' => 'clone_host.gif', 'hosts' => 'server.gif', 'hosts_child' => 'serversm.gif', 'host_services' => 'service-blue.gif', 'host_services_child' => 'service-blue.gif', 'parent_child' => 'parent_child.gif', 'parent_child_child' => 'parent_child.gif', 'parent_child_new' => 'parent_child_add.gif', 'host_dependencies' => 'parent_child.gif', 'host_dependencies_child' => 'parent_child.gif', 'host_dependencies_new' => 'parent_child_add.gif', 'host_externals' => 'template.gif', 'host_externals_new' => 'template.gif', 'host_externals_child' => 'template.gif', 'host_templates' => 'template.gif', 'host_templates_new' => 'template.gif', 'host_templates_child' => 'template.gif', 'host_extended_info' => 'template.gif', 'host_extended_info_new' => 'template.gif', 'host_extended_info_child' => 'template.gif', 'profiles' => 'profile.gif', 'profiles_new' => 'profile.gif', 'profiles_child' => 'profile.gif', 'host_profiles' => 'profile.gif', 'host_profiles_new' => 'profile.gif', 'host_profiles_child' => 'profile.gif', 'service_profiles' => 'profile.gif', 'service_profiles_new' => 'profile.gif', 'service_profiles_child' => 'profile.gif', 'profile_importer' => 'load.gif', 'services' => 'service-blue.gif', 'new_service' => 'service-blue-add.gif', 'clone_service' => 'service-blue-add.gif', 'services_child' => 'service-blue.gif', 'service_templates' => 'template.gif', 'service_templates_new' => 'template.gif', 'service_templates_child' => 'template.gif', 'service_groups' => 'service-group.gif', 'service_groups_new' => 'service-group-add.gif', 'service_groups_child' => 'service-group.gif', 'service_dependencies' => 'template.gif', 'service_dependencies_new' => 'template.gif', 'service_dependencies_child' => 'template.gif', 'build_externals' => 'template.gif', 'service_externals' => 'template.gif', 'service_externals_new' => 'template.gif', 'service_externals_child' => 'template.gif', 'service_extended_info' => 'template.gif', 'service_extended_info_new' => 'template.gif', 'service_extended_info_child' => 'template.gif', 'profiles' => 'profile.gif', 'time_periods_new' => 'time.gif', 'time_periods' => 'time.gif', 'time_periods_child' => 'time.gif', 'notifications' => 'paging.gif', 'pre_flight' => 'preflight.gif', 'users' => 'user.gif', 'users_child' => 'user.gif', 'users_new' => 'user_new.gif', 'user_groups_new' => 'users_new.gif', 'user_groups_child' => 'users.gif', 'user_groups' => 'users.gif', 'commit' => 'commit.gif', 'export' => 'export.gif', 'import_from_files' => 'load.gif', 'export_to_files' => 'export.gif', 'host_delete_tool' => 'server_delete.gif', 'service_delete_tool' => 'service_delete.gif', 'delete_hosts' => 'server_delete.gif', 'delete_host_services' => 'service_delete.gif', 'line' => 'empty.gif', 'plus' => 'nolines_plus.gif', 'plusbottom' => 'nolines_plus.gif', 'minus' => 'nolines_minus.gif', 'minusbottom' => 'nolines_minus.gif', 'join' => 'empty.gif', 'joinbottom' => 'empty.gif' ); my $x = qq( 'line' => 'line.gif', 'plus' => 'plus.gif', 'plusbottom' => 'plusbottom.gif', 'minus' => 'minus.gif', 'minusbottom' => 'minusbottom.gif', 'join' => 'join.gif', 'joinbottom' => 'joinbottom.gif' ); sub root_tree(@) { my @menus = @{ $_[1] }; my %sub_menus = %{ $_[2] }; my $top_menu = $_[3]; my $session_id = $_[4]; my $ez = $_[5]; my $level = 1; my $view = $top_menu; $top_menu =~ s/time_periods/time Periods/g; $top_menu =~ s/host_groups/host Groups/g; my $tree = qq(@{[&$Instrument::show_trace_as_html_comment()]} ); my $i = 0; my $id = time; foreach my $menu (@menus) { my $name = $menu; $name =~ s/_/ /g; $i++; my $menu_gif = $menu; if ( $menu =~ /^copy$|^modify$|^new$/i ) { $menu_gif = $view } if ( $sub_menus{$menu} ) { $id++; my $plus_image = $gif{'plusbottom'}; if ( $menus[$i] ) { $plus_image = $gif{'plus'} } my $anchor = "#$level$id"; $tree .= qq(@{[&$Instrument::show_trace_as_html_comment()]} ); } else { my $monarch_exe = 'monarch.cgi'; my $obj_view = ''; my $fill_image = $gif{'joinbottom'}; if ( $menus[$i] ) { $fill_image = $gif{'join'} } if ($ez) { $monarch_exe = 'monarch_ez.cgi'; $obj_view = "&view=$menu"; if ( $menu eq 'new' ) { $obj_view = "&view=$view&new=1"; } } elsif ( $menu =~ /^new/ ) { if ( $view eq 'time_periods' ) { $obj_view = '&view=design&obj=time_periods&task=new'; } elsif ( $view eq 'commands' ) { $obj_view = '&view=commands&obj=commands&task=new'; } elsif ( $view eq 'groups' ) { $obj_view = '&view=groups&obj=groups&obj_view=new'; } elsif ( $view eq 'services' ) { $obj_view = '&view=service&obj=services&obj_view=new'; } else { $obj_view = '&obj_view=new'; } } elsif ( $menu eq 'clone_service' ) { $obj_view = '&view=service&obj=services&obj_view=clone'; } elsif ( $view eq 'control' || $view eq 'tools' ) { $obj_view = "&view=$view&obj=$menu"; } else { $obj_view = "&view=$menu&obj=$top_menu"; } $tree .= qq(@{[&$Instrument::show_trace_as_html_comment()]} ); # } } $tree .= qq(@{[&$Instrument::show_trace_as_html_comment()]}
\u$top_menu
 \u$name
 \u$name
); 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()]} ); $obj_view = "&name=$last_node&obj_view=service_detail&form_service=1&service_name="; } foreach my $node (@nodes) { $id++; $i++; my $name = uri_escape($node); # Further escape some escaping (a necessary evil, to ensure #'s and %'s # [at least] are ultimately processed and displayed correctly). $name =~ s/%/%25/g; my $plus_image = $gif{'plusbottom'}; if ( $nodes[$i] ) { $plus_image = $gif{'plus'} } my $anchor = "#$level$id"; my $monarch_exe = 'monarch.cgi'; if ($ez) { $monarch_exe = 'monarch_ez.cgi' } if ( $ez && $sub_type eq 'time_periods' ) { $type = 'time_periods' } if ( $node eq 'new' ) { if ($ez) { $obj_view = "view=$last_node&new=1"; } elsif ( $last_node eq 'host_groups' ) { $obj_view = 'view=design&obj=hostgroups&task=new'; } elsif ( $sub_type eq 'host' ) { $obj_view = "obj_view=new&type=host"; } elsif ( $sub_type eq 'service' ) { $obj_view = "view=$type&obj_view=new&task=new&type=service"; } elsif ( $last_node eq 'service_templates' ) { $obj_view = "view=service_template&obj=service_templates&task=new"; } elsif ( $last_node eq 'service_groups' ) { $obj_view = "view=service_group&obj=service_groups&task=new"; } elsif ( $last_node eq 'service_dependencies' ) { $obj_view = "view=design&obj=service_dependency_templates&task=new"; } elsif ( $last_node eq 'contacts' ) { $obj_view = "view=design&obj=contacts&task=new"; } elsif ( $last_node eq 'users' ) { $obj_view = "view=control&obj=users&task=new"; } elsif ( $last_node eq 'user_groups' ) { $obj_view = "view=control&obj=user_groups&task=new"; } elsif ( $last_node eq 'contact_groups' ) { $obj_view = "view=design&obj=contactgroups&task=new"; } elsif ( $last_node eq 'host_profiles' ) { $obj_view = "view=host_profile&obj=profiles&obj_view=new"; } elsif ( $last_node eq 'service_profiles' ) { $obj_view = "view=service_profile&obj=profiles&obj_view=new"; } elsif ( $last_node eq 'host_extended_info' ) { $obj_view = "view=design&obj=extended_host_info_templates&task=new"; } elsif ( $last_node eq 'service_extended_info' ) { $obj_view = "view=design&obj=extended_service_info_templates&task=new"; } elsif ( $last_node =~ /template|extended_info/ ) { $obj_view = "view=design&obj=$last_node&task=new"; } else { $obj_view = "view=$last_node&obj=$last_node&task=new"; } $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()]} ); } else { $node =~ s/copy/Copy/; $node =~ s/modify/Modify/; my $gif = $gif{"$type\_child"}; if ( $node eq 'copy' ) { $gif = $gif{"$type\_new"} } utf8::encode($node); $table .= qq(@{[&$Instrument::show_trace_as_html_comment()]} ); } } } elsif ( $type eq 'host_services' && $level == $levels ) { $last_node = uri_escape($last_node); $id++; my $obj_view = '&name='; $table .= qq(@{[&$Instrument::show_trace_as_html_comment()]} ); } else { $table .= qq( ); } $table .= qq(@{[&$Instrument::show_trace_as_html_comment()]}
$indent
   Detail
$indent
   New
$indent
   $node
$indent
 $node
$indent
   Detail
$indent
  nothing found
); return $table; } 1;