Module: nagvis Branch: master Commit: beeb899a03b4b3101853c6242c8ca81d0f9311d3 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=beeb899a03b4b3101853c6242c8ca81d0f9311d3
Author: Lars Michelsen <[email protected]> Date: Wed Nov 24 18:04:59 2010 +0100 Colors and ranges of weathermap lines are now customizable using the object configuration option line_weather_colors --- ChangeLog | 2 + .../frontend/nagvis-js/js/NagVisStatefulObject.js | 42 +++++++++++++++----- share/frontend/nagvis-js/js/lines.js | 35 ---------------- share/server/core/classes/GlobalMapCfg.php | 31 ++++++++++++++ share/server/core/defines/matches.php | 1 + 5 files changed, 66 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6819f09..b27c644 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,8 @@ Frontend single nodes is stored in user specific profile files * Added new parameter {parent_map} to map/automap global sections which is used in header/sidebar menus to draw a map hierarchy + * Colors and ranges of weathermap lines are now customizable using the + object configuration option line_weather_colors * Fixed wrong label for MBit/s in weathermap bandwidth displaying WUI diff --git a/share/frontend/nagvis-js/js/NagVisStatefulObject.js b/share/frontend/nagvis-js/js/NagVisStatefulObject.js index 8a8fe82..32d0f44 100644 --- a/share/frontend/nagvis-js/js/NagVisStatefulObject.js +++ b/share/frontend/nagvis-js/js/NagVisStatefulObject.js @@ -493,11 +493,11 @@ var NagVisStatefulObject = NagVisObject.extend({ case 'DOWN': case 'CRITICAL': case 'WARNING': - case 'UNKNOWN': + case 'UNKNOWN': case 'ERROR': - case 'UP': - case 'OK': - case 'PENDING': + case 'UP': + case 'OK': + case 'PENDING': colorFill = oStates[this.conf.summary_state].color; break; default: @@ -512,7 +512,7 @@ var NagVisStatefulObject = NagVisObject.extend({ // Convert perfdata to structured array setPerfdata = splicePerfdata(this.conf.perfdata); - + // array index returned from splice function /* 0 = label 1 = value @@ -533,7 +533,7 @@ var NagVisStatefulObject = NagVisObject.extend({ else { if(setPerfdata[0][0] == 'dummyPercentIn' || setPerfdata[1][0] == 'dummyPercentOut') msg += "value 1 is \'" + setPerfdata[0][1] + "\' value 2 is \'" + setPerfdata[1][1] + "\'"; - + if(this.conf.line_type == 14 && (setPerfdata[2][0] == 'dummyActualIn' || setPerfdata[3][0] == 'dummyActualOut')) msg += " value 3 is \'" + setPerfdata[2][1] + "\' value 4 is \'" + setPerfdata[3][1] + "\'"; } @@ -553,7 +553,7 @@ var NagVisStatefulObject = NagVisObject.extend({ // Get colorFill #1 (in) if(setPerfdata[0][2] !== null && setPerfdata[0][2] == '%' && setPerfdata[0][1] !== null && setPerfdata[0][1] >= 0 && setPerfdata[0][1] <= 100) - colorFill = getColorFill(setPerfdata[0][1]); + colorFill = this.getColorFill(setPerfdata[0][1]); else { colorFill = '#000000'; this.perfdataError('First', setPerfdata[0][1], this.conf.name, this.conf.service_description); @@ -561,7 +561,7 @@ var NagVisStatefulObject = NagVisObject.extend({ // Get colorFill #2 (out) if(setPerfdata[1][2] !== null && setPerfdata[1][2] == '%' && setPerfdata [1][1] !== null && setPerfdata[1][1] >= 0 && setPerfdata[1][1] <= 100) - colorFill2 = getColorFill(setPerfdata[1][1]); + colorFill2 = this.getColorFill(setPerfdata[1][1]); else { colorFill = '#000000'; this.perfdataError('Second', setPerfdata[1][1], this.conf.name, this.conf.service_description); @@ -586,6 +586,28 @@ var NagVisStatefulObject = NagVisObject.extend({ }, /** + * PRIVATE getColorFill() + * + * This function returns the color to use for this line depending on the + * given percentage usage and on the configured options for this object + * + * @author Lars Michelsen <[email protected]> + */ + getColorFill: function(perc) { + var ranges = this.conf.line_weather_colors.split(','); + for(var i = 0; i < ranges.length; i++) { + // 0 contains the percentage until this color is used + // 1 contains the color to be used + var parts = ranges[i].split(':'); + if(perc <= parts[0]) + return parts[1]; + parts = null; + } + ranges = null; + return '#000000'; + }, + + /** * PRIVATE calculateUsage() * * Loops all perfdata sets and searches for labels "in" and "out" @@ -603,12 +625,12 @@ var NagVisStatefulObject = NagVisObject.extend({ for(var i = 0; i < oldPerfdata.length; i++) { if(oldPerfdata[i][0] == 'in' && (oldPerfdata[i][2] === null || oldPerfdata[i][2] === '')) { newPerfdata[0] = this.perfdataCalcPerc(oldPerfdata[i]); - newPerfdata[2] = this.perfdataCalcBytesReadable(oldPerfdata[i]); + newPerfdata[2] = this.perfdataCalcBytesReadable(oldPerfdata[i]); foundNew = true; } if(oldPerfdata[i][0] == 'out' && (oldPerfdata[i][2] === null || oldPerfdata[i][2] === '')) { newPerfdata[1] = this.perfdataCalcPerc(oldPerfdata[i]); - newPerfdata[3] = this.perfdataCalcBytesReadable(oldPerfdata[i]); + newPerfdata[3] = this.perfdataCalcBytesReadable(oldPerfdata[i]); foundNew = true; } } diff --git a/share/frontend/nagvis-js/js/lines.js b/share/frontend/nagvis-js/js/lines.js index 9345516..3437762 100644 --- a/share/frontend/nagvis-js/js/lines.js +++ b/share/frontend/nagvis-js/js/lines.js @@ -395,38 +395,3 @@ function splicePerfdata(nagiosPerfdata) { } } } - -/** - * Sets fill color for bandwidth based lines - * - * @param Number Percent value - * @return String Hex value for fill color - * @author Greg Frater <[email protected]> - */ -function getColorFill(percent) { - if(percent >= 0 && percent <= 10) { - // purple - return '#8c00ff'; - } else if (percent > 10 && percent <= 25) { - // blue - return '#2020ff'; - } else if (percent > 25 && percent <= 40) { - // light blue - return '#00c0ff'; - } else if (percent > 40 && percent <= 55) { - // green - return '#00f000'; - } else if (percent > 55 && percent <= 70) { - // yellow - return '#f0f000'; - } else if (percent > 70 && percent <= 85) { - // orange - return '#ffc000'; - } else if (percent > 85 && percent <= 100) { - // red - return '#ff0000'; - } else { - return '#000000'; - } -} - diff --git a/share/server/core/classes/GlobalMapCfg.php b/share/server/core/classes/GlobalMapCfg.php index 55498f9..17f51fa 100644 --- a/share/server/core/classes/GlobalMapCfg.php +++ b/share/server/core/classes/GlobalMapCfg.php @@ -254,6 +254,11 @@ class GlobalMapCfg { 'match' => MATCH_INTEGER, 'depends_on' => 'view_type', 'depends_value' => 'line'), + 'line_weather_colors' => Array('must' => 0, + 'default' => '10:#8c00ff,25:#2020ff,40:#00c0ff,55:#00f000,70:#f0f000,85:#ffc000,100:#ff0000', + 'match' => MATCH_WEATHER_COLORS, + 'depends_on' => 'view_type', + 'depends_value' => 'line'), 'in_maintenance' => Array('must' => 0, 'default' => '0', @@ -376,6 +381,11 @@ class GlobalMapCfg { 'match' => MATCH_INTEGER, 'depends_on' => 'view_type', 'depends_value' => 'line'), + 'line_weather_colors' => Array('must' => 0, + 'default' => '', + 'match' => MATCH_WEATHER_COLORS, + 'depends_on' => 'view_type', + 'depends_value' => 'line'), 'context_menu' => Array('must' => 0, 'match' => MATCH_BOOLEAN, @@ -548,6 +558,11 @@ class GlobalMapCfg { 'match' => MATCH_INTEGER, 'depends_on' => 'view_type', 'depends_value' => 'line'), + 'line_weather_colors' => Array('must' => 0, + 'default' => '', + 'match' => MATCH_WEATHER_COLORS, + 'depends_on' => 'view_type', + 'depends_value' => 'line'), 'context_menu' => Array('must' => 0, 'match' => MATCH_BOOLEAN, @@ -741,6 +756,11 @@ class GlobalMapCfg { 'match' => MATCH_INTEGER, 'depends_on' => 'view_type', 'depends_value' => 'line'), + 'line_weather_colors' => Array('must' => 0, + 'default' => '', + 'match' => MATCH_WEATHER_COLORS, + 'depends_on' => 'view_type', + 'depends_value' => 'line'), 'gadget_url' => Array('must' => 0, 'match' => MATCH_STRING_URL, 'field_type' => 'dropdown', @@ -924,6 +944,11 @@ class GlobalMapCfg { 'match' => MATCH_INTEGER, 'depends_on' => 'view_type', 'depends_value' => 'line'), + 'line_weather_colors' => Array('must' => 0, + 'default' => '', + 'match' => MATCH_WEATHER_COLORS, + 'depends_on' => 'view_type', + 'depends_value' => 'line'), 'context_menu' => Array('must' => 0, 'match' => MATCH_BOOLEAN, @@ -1088,6 +1113,11 @@ class GlobalMapCfg { 'match' => MATCH_INTEGER, 'depends_on' => 'view_type', 'depends_value' => 'line'), + 'line_weather_colors' => Array('must' => 0, + 'default' => '', + 'match' => MATCH_WEATHER_COLORS, + 'depends_on' => 'view_type', + 'depends_value' => 'line'), 'context_menu' => Array('must' => 0, 'match' => MATCH_BOOLEAN, @@ -1381,6 +1411,7 @@ class GlobalMapCfg { 'line_type', 'line_width', 'line_arrow', + 'line_weather_colors', 'context_menu', 'context_template', 'hover_menu', diff --git a/share/server/core/defines/matches.php b/share/server/core/defines/matches.php index 32e837f..d32a993 100644 --- a/share/server/core/defines/matches.php +++ b/share/server/core/defines/matches.php @@ -87,6 +87,7 @@ define('MATCH_INTEGER_PRESIGN_EMPTY', '/^[\+\-]?[0-9]*$/'); define('MATCH_ORDER', '/^(?:asc|desc)$/'); define('MATCH_TEXTBOX_WIDTH', '/^([0-9]+|auto)$/'); define('MATCH_TEXTBOX_HEIGHT', '/^([0-9]+|auto)$/'); +define('MATCH_WEATHER_COLORS', '/^(?:[0-9]{1,3}:#[0-9a-f]{6},?)+$/'); define('MATCH_SOCKET', '/^(unix:[a-zA-Z0-9\-_\.\/]+|tcp:[a-zA-Z0-9\-\.]+:[0-9]{1,5})$/'); define('MATCH_WUI_ADDMODIFY_DO', '/^(add|modify)$/'); ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
