Author:   Lars Michelsen <[email protected]>
Date:     Thu Jan 15 17:27:02 2015 +0100
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Thu Jan 15 17:27:02 2015 +0100

Gadgets can use object member states now

---

 ChangeLog                                          |    6 ++++++
 .../frontend/nagvis-js/js/NagVisStatefulObject.js  |   10 ++++++++--
 share/frontend/nagvis-js/js/ajax.js                |   18 ++++++++++++++++--
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9f78d36..4dba072 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,12 @@ Core:
     which have no perfdata. But you can build one now)
   * The option gadget_type is now deprecated as the type is automatically 
detected
   * FIX: gadgets_core.php perfdata parsing allows "/" for perfdatas UOM now
+  * Gadgets can use object member states now
+    Gadgets are now called with mixed POST request where the GET vars used in 
previous
+    versions are still handed over to the gadgets per GET parameters to
+    maintain compatibility. More complex parameters are now given to the
+    gadget with POST vars. For example there is the POST var "members" now,
+    which provides information about the object members states.
   (e.g. to be able to parse units like Kb/s, even when they are not allowed
   according to nagios plugin guidelines)
 
diff --git a/share/frontend/nagvis-js/js/NagVisStatefulObject.js 
b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
index ad4e9e2..d6fe3d0 100644
--- a/share/frontend/nagvis-js/js/NagVisStatefulObject.js
+++ b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
@@ -1032,8 +1032,13 @@ var NagVisStatefulObject = NagVisObject.extend({
         oObjIcon    = null;
     },
 
+    requestGadget: function (param_str) {
+        var data = 'members='+escape(JSON.stringify(this.conf.members));
+        return postSyncUrl(this.conf.gadget_url + param_str, data);
+    },
+
     detectGadgetType: function (param_str) {
-        var content = getSyncUrl(this.conf.gadget_url + param_str);
+        var content = this.requestGadget(param_str);
         if (content.substring(0, 4) === 'GIF8' || ! 
/^[\x00-\x7F]*$/.test(content[0]))
             this.gadget_type = 'img';
         else
@@ -1049,6 +1054,7 @@ var NagVisStatefulObject = NagVisObject.extend({
             sParams += '&name2=' + 
escapeUrlValues(this.conf.service_description);
 
         sParams += '&type=' + this.conf.type
+                 + '&object_id=' + this.conf.object_id
                  + '&scale=' + 
escapeUrlValues(this.conf.gadget_scale.toString())
                  + '&state=' + this.conf.state
                  + '&stateType=' + this.conf.state_type
@@ -1080,7 +1086,7 @@ var NagVisStatefulObject = NagVisObject.extend({
             oGadget.alt = alt;
         } else {
             var oGadget = document.createElement('div');
-            oGadget.innerHTML = getSyncUrl(this.conf.gadget_url + sParams);
+            oGadget.innerHTML = this.requestGadget(sParams);
         }
         oGadget.setAttribute('id', this.conf.object_id + '-icon');
 
diff --git a/share/frontend/nagvis-js/js/ajax.js 
b/share/frontend/nagvis-js/js/ajax.js
index ecd0d0d..14a7839 100644
--- a/share/frontend/nagvis-js/js/ajax.js
+++ b/share/frontend/nagvis-js/js/ajax.js
@@ -365,8 +365,6 @@ function handleJsonResponse(sUrl, responseText) {
 /**
  * This function simply loads a remote url and returns the responseText 1:1
  * without any special error handling
- *
- * @author     Lars Michelsen <[email protected]>
  */
 function getSyncUrl(url) {
     var oReq = initXMLHttpClient();
@@ -375,6 +373,22 @@ function getSyncUrl(url) {
     return oReq.responseText;
 }
 
+ /**
+  * This function simply loads a remote url using a POST request including 
sending
+  * a request body and returns the responseText 1:1 without any special error 
handling
+  */
+function postSyncUrl(url, data) {
+    var oReq = initXMLHttpClient();
+    oReq.open('POST', url, false);
+    oReq.setRequestHeader("If-Modified-Since", "Sat, 22 Sep 1986 00:00:00 
GMT");
+    // Set post specific options
+    oReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+    oReq.setRequestHeader("Content-length", data.length);
+    oReq.setRequestHeader("Connection", "close");
+    oReq.send(data);
+    return oReq.responseText;
+}
+
 /**
  * Prevent reaching too long urls, split the update to several
  * requests. Just start the request and clean the string strUrl


------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to