Module: nagvis
Branch: master
Commit: 319e9da7ad1c4a56df01993f96a6cc60a99b288f
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=319e9da7ad1c4a56df01993f96a6cc60a99b288f

Author: Lars Michelsen <[email protected]>
Date:   Tue Oct  5 19:16:50 2010 +0200

#352 Added ack and downtime parameters to the gadgets; Some code cleanups in 
gadgets core code

---

 share/frontend/nagvis-js/js/NagVisService.js |   10 ++++-
 share/userfiles/gadgets/gadgets_core.php     |   52 +++++++------------------
 2 files changed, 24 insertions(+), 38 deletions(-)

diff --git a/share/frontend/nagvis-js/js/NagVisService.js 
b/share/frontend/nagvis-js/js/NagVisService.js
index 2c35a9f..120f064 100644
--- a/share/frontend/nagvis-js/js/NagVisService.js
+++ b/share/frontend/nagvis-js/js/NagVisService.js
@@ -59,7 +59,15 @@ var NagVisService = NagVisStatefulObject.extend({
                        sGadgetOpts = '&opts=' + 
escapeUrlValues(this.conf.gadget_opts.toString());
                }
                
-               sParams = sParams + 'name1=' + this.conf.name + '&name2=' + 
escapeUrlValues(this.conf.service_description) + '&scale=' + 
escapeUrlValues(this.conf.gadget_scale.toString()) + '&state=' + 
this.conf.state + '&stateType=' + this.conf.state_type + '&perfdata=' + 
this.conf.perfdata.replace(/\&quot\;|\&\#145\;/g,'%22') + sGadgetOpts;
+               sParams = sParams + 'name1=' + this.conf.name
+                         + '&name2=' + 
escapeUrlValues(this.conf.service_description)
+                         + '&scale=' + 
escapeUrlValues(this.conf.gadget_scale.toString())
+                         + '&state=' + this.conf.state
+                         + '&stateType=' + this.conf.state_type
+                         + '&ack=' + 
this.conf.summary_problem_has_been_acknowledged
+                         + '&downtime=' + this.conf.summary_in_downtime
+                         + '&perfdata=' + 
this.conf.perfdata.replace(/\&quot\;|\&\#145\;/g,'%22')
+                         + sGadgetOpts;
                
                var oIcon = document.createElement('img');
                oIcon.setAttribute('id', this.conf.object_id+'-icon');
diff --git a/share/userfiles/gadgets/gadgets_core.php 
b/share/userfiles/gadgets/gadgets_core.php
index 315a538..5c893ad 100644
--- a/share/userfiles/gadgets/gadgets_core.php
+++ b/share/userfiles/gadgets/gadgets_core.php
@@ -187,49 +187,27 @@ $aPerfdata = Array();
  *  scale=100
  */
 
-if(isset($_GET['opts']) && $_GET['opts'] != '') {
-        $aOpts['opts'] = $_GET['opts'];
-}
-
-if(isset($_GET['perfdata']) && $_GET['perfdata'] != '') {
+// Get params without default values
+foreach(Array('opts'  => null, 'name1'     => null, 'name2' => null,
+              'state' => null, 'stateType' => null, 'scale' => 100,
+              'ack'   => null, 'downtime'  => null) AS $opt => $default)
+       if(isset($_GET[$opt]) && $_GET[$opt] != '')
+               $aOpts[$opt] = $_GET[$opt];
+       elseif($default !== null)
+               $aOpts[$opt] = $default;
+
+if(isset($_GET['perfdata']) && $_GET['perfdata'] != '')
        $aOpts['perfdata'] = $_GET['perfdata'];
-} elseif(isset($_GET['conf']) &&  $_GET['conf'] != '' && 
isset($sDummyPerfdata) && $sDummyPerfdata != '') {
+elseif(isset($_GET['conf']) &&  $_GET['conf'] != '' && isset($sDummyPerfdata) 
&& $sDummyPerfdata != '')
        $aOpts['perfdata'] = $sDummyPerfdata;
-} elseif(!isset($_GET['opts']) || strpos($_GET['opts'], 'no_perf') === false) {
+elseif(!isset($_GET['opts']) || strpos($_GET['opts'], 'no_perf') === false)
        errorBox('ERROR: The needed parameter "perfdata" is missing.');
-}
-
-if(isset($_GET['name1']) && $_GET['name1'] != '') {
-       $aOpts['name1'] = $_GET['name1'];
-}
-
-if(isset($_GET['name2']) && $_GET['name2'] != '') {
-       $aOpts['name2'] = $_GET['name2'];
-}
-
-if(isset($_GET['state']) && $_GET['state'] != '') {
-       $aOpts['state'] = $_GET['state'];
-}
-
-if(isset($_GET['stateType']) && $_GET['stateType'] != '') {
-       $aOpts['stateType'] = $_GET['stateType'];
-}
-
-if (isset($_GET['scale']) && $_GET['scale'] != '') {
-       $aOpts['scale'] = $_GET['scale'];
-} else {
-       /* If no scale is set, default to 100 */
-       $aOpts['scale'] = 100;
-}
-
 
 /* Now parse the perfdata */
-if(isset($_GET['opts']) && ($_GET['opts'] != '')) {
-       if(strpos($_GET['opts'],'no_perf') === false) {
+if(isset($_GET['opts']) && ($_GET['opts'] != ''))
+       if(strpos($_GET['opts'],'no_perf') === false)
                $aPerfdata = parsePerfdata($aOpts['perfdata']);
-       }
-} else {
+else
        $aPerfdata = parsePerfdata($aOpts['perfdata']);
-}
 
 ?>


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to