[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * Added dispatcher routes to Ext. Ajax and Ping action to avoid false-positives on server-down check

git at icinga.org git at icinga.org
Fri Aug 5 11:16:25 CEST 2011


Module: icinga-web
Branch: jmosshammer/default
Commit: bca31028bf9f15837ec531ca7e5581cd1b55ea03
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=bca31028bf9f15837ec531ca7e5581cd1b55ea03

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Fri Aug  5 11:14:34 2011 +0200

* Added dispatcher routes to Ext.Ajax and Ping action to avoid false-positives on server-down check

---

 app/config/routing.xml                             |    8 +++--
 app/modules/AppKit/actions/PingAction.class.php    |   27 ++++++++++++++++
 app/modules/AppKit/cache/Ping.xml                  |   11 ++++++
 app/modules/AppKit/config/javascript.xml           |    2 +
 app/modules/AppKit/lib/js/AppKitErrorHandler.js    |   33 ++++++++++++++++---
 app/modules/AppKit/lib/js/request/Ajax.js          |   30 ++++++++++++++++++
 app/modules/AppKit/templates/PingSuccess.php       |    1 +
 app/modules/AppKit/validate/Ping.xml               |   15 +++++++++
 app/modules/AppKit/views/PingSuccessView.class.php |   13 ++++++++
 9 files changed, 131 insertions(+), 9 deletions(-)

diff --git a/app/config/routing.xml b/app/config/routing.xml
index 451cac3..4643617 100755
--- a/app/config/routing.xml
+++ b/app/config/routing.xml
@@ -2,7 +2,7 @@
 <ae:configurations xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0" xmlns="http://icinga.org/appkit/config/parts/routing/1.0">
 	<ae:configuration context="web">
 		<routes>
-
+            
 			<!-- INDEX -->
 			<route name="index_page" pattern="^/$" module="Web" action="Icinga.PortalView"/>
 			
@@ -20,8 +20,10 @@
 				* AppKit routes
 			-->
 			<route name="appkit" pattern="^/appkit" module="%actions.default_module%">
-
-				<route name=".login" pattern="^/login" action="%actions.login_action%">
+                <!-- check if the webserver is dead -->
+                <route name="ping" pattern="^/ping" action="Ping"/>
+				
+                <route name=".login" pattern="^/login" action="%actions.login_action%">
 					<route name=".provider" pattern="^/json" module="%actions.default_module%" action="Login.AjaxLogin" output_type="json"/>
 					<route name=".check" pattern="^/check" module="%actions.default_module%" action="Login.LoginCheck" output_type="simple"/>
 				</route>
diff --git a/app/modules/AppKit/actions/PingAction.class.php b/app/modules/AppKit/actions/PingAction.class.php
new file mode 100644
index 0000000..fe97363
--- /dev/null
+++ b/app/modules/AppKit/actions/PingAction.class.php
@@ -0,0 +1,27 @@
+<?php
+
+class AppKit_PingAction extends AppKitBaseAction
+{
+	/**
+	 * Returns the default view if the action does not serve the request
+	 * method used.
+	 *
+	 * @return     mixed <ul>
+	 *                     <li>A string containing the view name associated
+	 *                     with this action; or</li>
+	 *                     <li>An array with two indices: the parent module
+	 *                     of the view to be executed and the view to be
+	 *                     executed.</li>
+	 *                   </ul>
+	 */
+	public function getDefaultViewName()
+	{
+		return 'Success';
+	}
+
+    public function isSimple()  {
+        return true;
+    }
+}
+
+?>
diff --git a/app/modules/AppKit/cache/Ping.xml b/app/modules/AppKit/cache/Ping.xml
new file mode 100644
index 0000000..058a8ee
--- /dev/null
+++ b/app/modules/AppKit/cache/Ping.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ae:configurations xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0" xmlns="http://agavi.org/agavi/config/parts/caching/1.0">
+	
+	<ae:configuration>
+		
+		<caching enabled="false">
+		</caching>
+		
+	</ae:configuration>
+	
+</ae:configurations>
\ No newline at end of file
diff --git a/app/modules/AppKit/config/javascript.xml b/app/modules/AppKit/config/javascript.xml
index 2049a0f..cfd67a8 100644
--- a/app/modules/AppKit/config/javascript.xml
+++ b/app/modules/AppKit/config/javascript.xml
@@ -18,6 +18,8 @@
             <ae:parameter>%core.module_dir%/AppKit/lib/js/Layout.js</ae:parameter>
             <ae:parameter>%core.module_dir%/AppKit/lib/js/HttpStateProvider.js</ae:parameter>
             <ae:parameter>%core.module_dir%/AppKit/lib/js/JSONSubmit.js</ae:parameter>
+            
+            <ae:parameter>%core.module_dir%/AppKit/lib/js/request/Ajax.js</ae:parameter>
 
             <!-- jsgettext -->
             <ae:parameter>%core.root_dir%/lib/jsgettext/lib/Gettext.js</ae:parameter>
diff --git a/app/modules/AppKit/lib/js/AppKitErrorHandler.js b/app/modules/AppKit/lib/js/AppKitErrorHandler.js
index 6866e05..347a4fb 100755
--- a/app/modules/AppKit/lib/js/AppKitErrorHandler.js
+++ b/app/modules/AppKit/lib/js/AppKitErrorHandler.js
@@ -277,6 +277,17 @@ Ext.ns("AppKit.errorHandler");
 		Ext.Ajax.on("requestException",function(conn,response,opts) {
 			handleError(response,opts);
 		})
+        var pingCount = 0;
+        var pingServer = function() {
+            Ext.Ajax.request({
+                icingaAction: 'Ping',
+                icingaModule: 'AppKit',
+                isPing: true
+            });
+            
+            
+        }
+    
 		var handleError = function(response,proxy) {
 			switch(response.status) {	
 				case 200:
@@ -295,8 +306,14 @@ Ext.ns("AppKit.errorHandler");
 				default:
 					if(response.status < 400 && response.status)
 						break;
-					AppKit.AjaxErrorHandler.error_unknown(proxy.url,response);
-					break;
+                    // check if a ping failed
+                    if(proxy.isPing)
+                        AppKit.AjaxErrorHandler.error_connection();
+                    // check if the server is dead
+			        else 
+                        AppKit.AjaxErrorHandler.error_unknown(proxy.url,response); 
+					
+                    break;
 			}
 		}
 		return {
@@ -329,11 +346,15 @@ Ext.ns("AppKit.errorHandler");
 			error_401 : function(target) {
 				trackError(_("Access denied"));
 			},
+            error_connection : function(target) {
+               
+				Ext.Msg.alert(_("Critical error"),_("Couldn't connect to web-server."));   
+				
+				trackError(_("A error occured when requesting ")+target);//+" : "+error.length <200 ? error: error.substr(0,200)+"...");
+            },
 			error_unknown : function(target,error) {
-				if(!(error.status)) {
-					Ext.Msg.alert(_("Critical error"),_("Couldn't connect to web-server."));
-			//		window.location.reload();
-				}
+				
+                pingServer();	
 				if(!error)
 					error = "Unkown error";
 					AppKit.log(error, target);
diff --git a/app/modules/AppKit/lib/js/request/Ajax.js b/app/modules/AppKit/lib/js/request/Ajax.js
new file mode 100644
index 0000000..3c8df0f
--- /dev/null
+++ b/app/modules/AppKit/lib/js/request/Ajax.js
@@ -0,0 +1,30 @@
+Ext.Ajax.request = function(o) {
+    if(!o.icingaAction || !o.icingaModule) {
+        return this.directRequest(o);
+    } else {
+        return this.dispatchRequest(o);
+    }
+}
+
+Ext.Ajax.directRequest = function(o) {
+    if(!o.allowBatch) {
+        return Ext.data.Connection.prototype.request.call(this,o);
+    } else {
+        return Ext.data.Connection.prototype.request.call(this,o);
+    }
+}
+
+Ext.Ajax.dispatchRequest = function(o) {
+   
+    if(!o.url)
+        o.url = AppKit.c.path+'/appkit/dispatch';
+    var p = o.params;
+    o.params = {}
+    o.params.module = o.icingaModule;
+    o.params.action = o.icingaAction;
+    if(o.output_type)
+        o.params.output_type = o.output_type;
+    
+    o.params.params = Ext.encode(p);
+    return Ext.data.Connection.prototype.request.call(this,o);
+}
diff --git a/app/modules/AppKit/templates/PingSuccess.php b/app/modules/AppKit/templates/PingSuccess.php
new file mode 100644
index 0000000..31ccbf8
--- /dev/null
+++ b/app/modules/AppKit/templates/PingSuccess.php
@@ -0,0 +1 @@
+I'm still alive
diff --git a/app/modules/AppKit/validate/Ping.xml b/app/modules/AppKit/validate/Ping.xml
new file mode 100644
index 0000000..c75f597
--- /dev/null
+++ b/app/modules/AppKit/validate/Ping.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ae:configurations
+	xmlns="http://agavi.org/agavi/config/parts/validators/1.0"
+	xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0"
+	parent="%core.module_dir%/AppKit/config/validators.xml"
+>
+	
+	<ae:configuration>
+		
+		<validators>
+		</validators>
+		
+	</ae:configuration>
+	
+</ae:configurations>
\ No newline at end of file
diff --git a/app/modules/AppKit/views/PingSuccessView.class.php b/app/modules/AppKit/views/PingSuccessView.class.php
new file mode 100644
index 0000000..d9be23f
--- /dev/null
+++ b/app/modules/AppKit/views/PingSuccessView.class.php
@@ -0,0 +1,13 @@
+<?php
+
+class AppKit_PingSuccessView extends AppKitBaseView
+{
+	public function executeHtml(AgaviRequestDataHolder $rd)
+	{
+		$this->setupHtml($rd);
+		
+		$this->setAttribute('_title', 'Ping');
+	}
+}
+
+?>





More information about the icinga-checkins mailing list