[opsview] [1682] Opsview Web can be relocatable
Revision 1682
Author ton
Date 2008-11-14 10:23:46 +0000 (Fri, 14 Nov 2008)
Log Message
Opsview Web can be relocatable
Modified Paths
branches/DEV-opsview3/CHANGES
branches/DEV-opsview3/opsview-base/patches/nmis_opsview_link.patch
branches/DEV-opsview3/opsview-core/bin/nagconfgen.pl
branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/Admin/Notifications.pm
branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/Root.pm
branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/SideNav.pm
branches/DEV-opsview3/opsview-web/lib/Opsview/Web/ControllerBase/Admin.pm
branches/DEV-opsview3/opsview-web/lib/Opsview/Web.pm
branches/DEV-opsview3/opsview-web/root/admin/auditlog/list_functions
branches/DEV-opsview3/opsview-web/root/admin/reload/opsview
branches/DEV-opsview3/opsview-web/root/login
branches/DEV-opsview3/opsview-web/root/opsview_status_lights
branches/DEV-opsview3/opsview-web/root/wrappers/default
Modified: branches/DEV-opsview3/CHANGES
===================================================================
--- branches/DEV-opsview3/CHANGES 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/CHANGES 2008-11-14 10:23:46 UTC (rev 1682)
@@ -11,6 +11,7 @@
Removed "Resolve" button in list hosts page as popup menu can access same information
send2slaves now puts a first install tarball into /usr/local/nagios/tmp
All database dates and times are in UTC now. Historical data is not changed
+ Opsview Web can be relocatable, instead of being based at /
Speed ups in configuration generation:
* use arguments instead of creating a whole new checkcommand for each service
Modified: branches/DEV-opsview3/opsview-base/patches/nmis_opsview_link.patch
===================================================================
--- branches/DEV-opsview3/opsview-base/patches/nmis_opsview_link.patch 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-base/patches/nmis_opsview_link.patch 2008-11-14 10:23:46 UTC (rev 1682)
@@ -1,11 +1,21 @@
-diff -ur nmis-4.2.13.original/cgi-bin/nmiscgi.pl nmis-4.2.13/cgi-bin/nmiscgi.pl
---- nmis-4.2.13.original/cgi-bin/nmiscgi.pl 2008-02-27 16:26:33.994859000 +0000
-+++ nmis-4.2.13/cgi-bin/nmiscgi.pl 2008-02-27 16:27:26.224946944 +0000
-@@ -3819,6 +3819,7 @@
+diff -ur nmis-4.2.13/cgi-bin/nmiscgi.pl nmis-4.2.13.with_opsview_link/cgi-bin/nmiscgi.pl
+--- nmis-4.2.13/cgi-bin/nmiscgi.pl 2008-11-14 18:18:50.000000000 +0800
++++ nmis-4.2.13.with_opsview_link/cgi-bin/nmiscgi.pl 2008-11-14 18:20:35.000000000 +0800
+@@ -3808,6 +3808,9 @@
+ # get localtime
+ $time = &get_localtime;
+ print "<!-- nmisMenuSmall begin -->\n";
++ use Opsview::Config::Web;
++ my $webcfg = Opsview::Config::Web->web_config;
++ my $opsview_base = $webcfg->{override_base_prefix} || "/";
+ print <<EO_HTML;
+ <tr>
+ <td class="grey">
+@@ -3819,6 +3822,7 @@
<div class="asb">
<a class="b" href="$this_script?file=$conf&amp;menu=small">Dash</a>
<a class="b" href="$this_script?file=$conf&amp;menu=large">Large Dash</a>
-+ <a class="b" href="/">Opsview</a>
++ <a class="b" href="$opsview_base">Opsview</a>
<a class="b" href="$NMIS::config{'<url_base>'}/">Doc</a>
<a class="b" href="$NMIS::config{help_file}">Help</a>
</div>
Modified: branches/DEV-opsview3/opsview-core/bin/nagconfgen.pl
===================================================================
--- branches/DEV-opsview3/opsview-core/bin/nagconfgen.pl 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-core/bin/nagconfgen.pl 2008-11-14 10:23:46 UTC (rev 1682)
@@ -41,6 +41,7 @@
use Opsview::Systempreference;
use Opsview::Utils;
use Opsview::Config;
+use Opsview::Config::Web;
use Time::HiRes qw(gettimeofday);
use Getopt::Std;
use Set::Cluster;
@@ -106,6 +107,8 @@
# Set configurations
my $nagios_interval_length = Opsview::Config->nagios_interval_length;
+my $webcfg = Opsview::Config::Web->web_config;
+
if ($opts->{s}) {
$monitoringserver = Opsview::Monitoringserver->get_master;
write_trapinfocfg($opts->{s});
@@ -332,7 +335,13 @@
$icon_name = $host->icon;
$icon_file = $host->icon->filename;
- my $host_info_url=Opsview::Systempreference->host_info_url || "/info/host/".$host->id;
+ my $host_info_url;
+ if ($_ = Opsview::Systempreference->host_info_url) {
+ $host_info_url = $_;
+ } else {
+ $host_info_url = ( exists $webcfg->{override_base_prefix} ? $webcfg->{override_base_prefix} : "" );
+ $host_info_url .= "/info/host/".$host->id;
+ }
print OUTFILE
"# ".$host->name." host definition
@@ -508,6 +517,9 @@
}
";
+
+ my $graph_url = ( exists $webcfg->{override_base_prefix} ? $webcfg->{override_base_prefix} : "" );
+ $graph_url .= "/cgi-bin/show.cgi";
foreach my $h (@hosts) {
my $array = $h->resolved_servicechecks;
foreach my $sc (@$array) {
@@ -673,10 +685,10 @@
if ( ($s->checktype->id == 1 or $s->checktype->id == 5) && ($s->supports_performance(host=>$h, rrddir=>Opsview::Config->root_dir."/var/rrd") == 1)) {
unless ($test) {
print OUTFILE
-' notes_url /cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&fixedscale
+" notes_url $graph_url?host=\$HOSTNAME\$&service=\$SERVICEDESC\$&fixedscale
icon_image graph-icon.gif
icon_image_alt View graphs
-';
+";
}
}
}
Modified: branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/Admin/Notifications.pm
===================================================================
--- branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/Admin/Notifications.pm 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/Admin/Notifications.pm 2008-11-14 10:23:46 UTC (rev 1682)
@@ -168,7 +168,7 @@
return $page;
} else {
use HTML::Entities;
- return '<a href="' . decode_entities($c->req->uri_with({ page => $page})) . '">' . $page . '</a>';
+ return '<a href="' . decode_entities($c->uri_for_params("", { page => $page})) . '">' . $page . '</a>';
}
}
Modified: branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/Root.pm
===================================================================
--- branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/Root.pm 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/Root.pm 2008-11-14 10:23:46 UTC (rev 1682)
@@ -318,7 +318,7 @@
sub refresh_page : Private {
my ( $self, $c ) = @_;
$c->stash( refresh_rate => Opsview::Systempreference->refresh_rate );
- $c->stash( refresh_link => $c->req->uri_with( { output => "ajax" } ) );
+ $c->stash( refresh_link => $c->uri_for_params( "", { output => "ajax" } ) );
}
sub soft_error :Private {
Modified: branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/SideNav.pm
===================================================================
--- branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/SideNav.pm 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/lib/Opsview/Web/Controller/SideNav.pm 2008-11-14 10:23:46 UTC (rev 1682)
@@ -61,8 +61,15 @@
$menu{'ident'} = "section-${ident}";
$menu{'display'} = 1 if $saved_sections{$ident};
- if($ident eq "help") {
- foreach my $entry (@{$menu{entries}}) {
+ foreach my $entry (@{$menu{entries}}) {
+ my $url = $entry->{url};
+ if ($url =~ /(.*)\?(.*)/) {
+ $entry->{url} = $c->uri_for( $1 )."?$2";
+ } else {
+ # Need the "" to force URI to be a scalar
+ $entry->{url} = $c->uri_for( $url )."";
+ }
+ if($ident eq "help") {
if($entry->{name} eq "Documentation") {
$entry->{url}=$c->config->{doc_url};
}
Modified: branches/DEV-opsview3/opsview-web/lib/Opsview/Web/ControllerBase/Admin.pm
===================================================================
--- branches/DEV-opsview3/opsview-web/lib/Opsview/Web/ControllerBase/Admin.pm 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/lib/Opsview/Web/ControllerBase/Admin.pm 2008-11-14 10:23:46 UTC (rev 1682)
@@ -231,7 +231,7 @@
return $page;
} else {
use HTML::Entities;
- return '<a href="' . decode_entities($c->req->uri_with({ page => $page})) . '">' . $page . '</a>';
+ return '<a href="' . decode_entities($c->uri_for_params("", { page => $page})) . '">' . $page . '</a>';
}
}
Modified: branches/DEV-opsview3/opsview-web/lib/Opsview/Web.pm
===================================================================
--- branches/DEV-opsview3/opsview-web/lib/Opsview/Web.pm 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/lib/Opsview/Web.pm 2008-11-14 10:23:46 UTC (rev 1682)
@@ -79,10 +79,21 @@
}
}
+# We're overriding Catalyst->prepare_path
+# We override to add base prefix here, to allow relocatable apps
+sub prepare_path {
+ my $c = shift;
+ $c->engine->prepare_path( $c, @_ );
+ if ($c->config->{override_base_prefix}) {
+ $c->request->base->path($c->config->{override_base_prefix}."/");
+ }
+}
+
# Convenience function to create a uri_for, but using existing params
sub uri_for_params {
my ($self, $path, $params) = @_;
$params ||= {};
+ $path = $self->request->uri->path unless $path;
my $uri = $self->uri_for($path);
$uri->query_form( {
%{ $self->req->params },
@@ -91,6 +102,7 @@
return $uri;
}
+
#
# Configure the application
#
Modified: branches/DEV-opsview3/opsview-web/root/admin/auditlog/list_functions
===================================================================
--- branches/DEV-opsview3/opsview-web/root/admin/auditlog/list_functions 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/root/admin/auditlog/list_functions 2008-11-14 10:23:46 UTC (rev 1682)
@@ -26,7 +26,7 @@
"</td>";
"<td>";
- '<a class="action" title="Filter current list by this username" href="'; c.req.uri_with({ username => object.username }) | html; '">';
+ '<a class="action" title="Filter current list by this username" href="'; c.uri_for_params("", { username => object.username }) | html; '">';
object.username || "SYSTEM";
'</a>';
"</td>";
Modified: branches/DEV-opsview3/opsview-web/root/admin/reload/opsview
===================================================================
--- branches/DEV-opsview3/opsview-web/root/admin/reload/opsview 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/root/admin/reload/opsview 2008-11-14 10:23:46 UTC (rev 1682)
@@ -11,23 +11,23 @@
var time_diff = 0;
function restartOpsview() {
window.clearTimeout(timerID);
- new Ajax.Request("/admin/reload/do_restart", {method:"post"});
+ new Ajax.Request("[% c.uri_for("/admin/reload/do_restart") %]", {method:"post"});
frequency = 5000;
timerID = window.setTimeout("getStatus()", frequency);
}
function getStatus() {
- new Ajax.Request('/admin/status/opsview', {onComplete: checkStatus, method:"post"});
+ new Ajax.Request('[% c.uri_for("/admin/status/opsview") %]', {onComplete: checkStatus, method:"post"});
}
function do_reload() {
window.clearTimeout(timerID);
- new Ajax.Request("/admin/reload/do_reload", {method:"post"});
+ new Ajax.Request("[% c.uri_for("/admin/reload/do_reload") %]", {method:"post"});
updateStatus(1);
last_state=1;
timerId=window.setTimeout("getStatus()", 5000);
}
function update_times() {
var initTime = new Date();
- new Ajax.Request("/admin/ajax/reload_start_time", { method:"post", onSuccess:function(t) {
+ new Ajax.Request("[% c.uri_for("/admin/ajax/reload_start_time") %]", { method:"post", onSuccess:function(t) {
var json = t.responseText.evalJSON(true);
if(json) {
if(json.ResultSet.call_time_epoch) {
Modified: branches/DEV-opsview3/opsview-web/root/login
===================================================================
--- branches/DEV-opsview3/opsview-web/root/login 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/root/login 2008-11-14 10:23:46 UTC (rev 1682)
@@ -5,17 +5,14 @@
<html xmlns="
http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>[% c.loc("Opsview login page") %]</title>
- <link rel="alternate" type="application/atom+xml" title="[% c.loc("Opsview") %] Atom feed" href="/atom" />
- <link rel="stylesheet" type="text/css" href="/stylesheets/opsview2.css" />
+ <link rel="alternate" type="application/atom+xml" title="[% c.loc("Opsview") %] Atom feed" href="[% c.uri_for("/atom") %]" />
+ <link rel="stylesheet" type="text/css" href="[% c.uri_for("/stylesheets/opsview2.css") %]" />
<!--[if IE]>
- <link rel="stylesheet" type="text/css" href="/stylesheets/opsview2_ie6.css" />
+ <link rel="stylesheet" type="text/css" href="[% c.uri_for("/stylesheets/opsview2_ie6.css") %]" />
<![endif]-->
- <link rel="stylesheet" type="text/css"
- href="/stylesheets/common.css" />
- <link rel="stylesheet" type="text/css"
- href="/stylesheets/status.css" />
- <link rel="stylesheet" type="text/css"
- href="/stylesheets/sidenav.css" />
+ <link rel="stylesheet" type="text/css" href="[% c.uri_for("/stylesheets/common.css") %]" />
+ <link rel="stylesheet" type="text/css" href="[% c.uri_for("/stylesheets/status.css") %]" />
+ <link rel="stylesheet" type="text/css" href="[% c.uri_for("/stylesheets/sidenav.css") %]" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
@@ -25,7 +22,7 @@
<div id='login_form'>
<p id='heading'>Please log in[% IF c.request.params.app; ": "; c.request.params.app; END %]</p>
[% IF login_error; '<h3>'; login_error; '</h3>'; END; %]
- <form name="login_form" method="post" action="/login">
+ <form name="login_form" method="post" action="[% c.uri_for("/login") %]">
<label for='login_username'>
Username<br />
<input id="login_username" name="login_username" value="[%
Modified: branches/DEV-opsview3/opsview-web/root/opsview_status_lights
===================================================================
--- branches/DEV-opsview3/opsview-web/root/opsview_status_lights 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/root/opsview_status_lights 2008-11-14 10:23:46 UTC (rev 1682)
@@ -1,12 +1,12 @@
-<a style="margin-right: 1em" href="[% c.uri_for("/admin/reload") %]">Server Status <img class="lights" id="server" src="/images/alert.gif" alt="alert" width="10" height="10"/></a>
-<a href="[% c.uri_for("/admin/reload") %]">Configuration Status <img class="lights" id="config" src="/images/alert.gif" alt="alert" width="10" height="10" /></a>
+<a style="margin-right: 1em" href="[% c.uri_for("/admin/reload") %]">Server Status <img class="lights" id="server" src="[% c.uri_for("/images/alert.gif") %]" alt="alert" width="10" height="10"/></a>
+<a href="[% c.uri_for("/admin/reload") %]">Configuration Status <img class="lights" id="config" src="[% c.uri_for("/images/alert.gif") %]" alt="alert" width="10" height="10" /></a>
<script type="text/javascript">
var opsview_timer;
var ok = "#00F000";
var warn = "#F0F000";
var crit = "#F00000";
function getStatusForBar() {
- new Ajax.Request('/admin/status/opsview', {onComplete: updateLights, method:"post"});
+ new Ajax.Request('[% c.uri_for("/admin/status/opsview") %]', {onComplete: updateLights, method:"post"});
}
function updateLights(t) {
var xmlOpsview = t.responseXML;
Modified: branches/DEV-opsview3/opsview-web/root/wrappers/default
===================================================================
--- branches/DEV-opsview3/opsview-web/root/wrappers/default 2008-11-14 10:07:38 UTC (rev 1681)
+++ branches/DEV-opsview3/opsview-web/root/wrappers/default 2008-11-14 10:23:46 UTC (rev 1682)
@@ -2,24 +2,24 @@
<html>
<head>
<title>[% page_title || c.loc("Opsview") %]</title>
- <link rel="alternate" type="application/atom+xml" title="[% c.loc("Opsview") %] Atom feed" href="/atom">
- <link rel="stylesheet" type="text/css" href="/stylesheets/opsview2.css">
+ <link rel="alternate" type="application/atom+xml" title="[% c.loc("Opsview") %] Atom feed" href="[% c.uri_for("/atom") %]">
+ <link rel="stylesheet" type="text/css" href="[% c.uri_for("/stylesheets/opsview2.css") %]">
<!--[if IE 6]>
- <link rel="stylesheet" type="text/css" href="/stylesheets/opsview2_ie6.css">
+ <link rel="stylesheet" type="text/css" href="[% c.uri_for("/stylesheets/opsview2_ie6.css") %]">
<![endif]-->
[%- FOREACH stylesheet IN stylesheets; %]
- <link rel="stylesheet" type="text/css" href="[% '/stylesheets/' _ stylesheet %]">
+ <link rel="stylesheet" type="text/css" href="[% c.uri_for('/stylesheets/' _ stylesheet) %]">
[%- END %]
- <script src="/javascript/prototype.js" type="text/javascript"></script>
- <script src="/javascript/scriptaculous.js?load=builder,effects,dragdrop,controls" type="text/javascript"></script>
- <script src="/javascript/validation.js" type="text/javascript"></script>
- <script src="/javascript/forms.js" type="text/javascript"></script>
- <script src="/javascript/opsview_sidenav.js" type="text/javascript"></script>
- <script src="/javascript/overlib_mini.js" type="text/javascript"><!-- overLIB (c) Erik Bosrup --></script>
- <script src="/javascript/overlib_anchor_mini.js" type="text/javascript"><!-- overLIB (c) Erik Bosrup --></script>
- <script src="/javascript/status.js" type="text/javascript"></script>
+ <script src="[% c.uri_for("/javascript/prototype.js") %]" type="text/javascript"></script>
+ <script src="[% c.uri_for("/javascript/scriptaculous.js") %]?load=builder,effects,dragdrop,controls" type="text/javascript"></script>
+ <script src="[% c.uri_for("/javascript/validation.js") %]" type="text/javascript"></script>
+ <script src="[% c.uri_for("/javascript/forms.js") %]" type="text/javascript"></script>
+ <script src="[% c.uri_for("/javascript/opsview_sidenav.js") %]" type="text/javascript"></script>
+ <script src="[% c.uri_for("/javascript/overlib_mini.js") %]" type="text/javascript"><!-- overLIB (c) Erik Bosrup --></script>
+ <script src="[% c.uri_for("/javascript/overlib_anchor_mini.js") %]" type="text/javascript"><!-- overLIB (c) Erik Bosrup --></script>
+ <script src="[% c.uri_for("/javascript/status.js") %]" type="text/javascript"></script>
[%- FOREACH js IN extra_javascript %]
- <script src="/javascript/[% js %].js" type="text/javascript"></script>
+ <script src="[% c.uri_for("/javascript/"_ js _".js") %]" type="text/javascript"></script>
[%- END %]
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
[% IF extra_head_info; extra_head_info | indent(4); END; %]