diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 503f6c1a28..b26631cd4a 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-07-16 Miguel de Dios + + * include/graphs/flot/pandora.flot.js, + include/functions_networkmap.php, include/constants.php, + include/ajax/agent.php, include/ajax/events.php: improve the + source code and remove the magic number and they changed for + constants. + 2013-07-15 Sergio Martin * godmode/agentes/configurar_agente.php: Fixed javascript diff --git a/pandora_console/include/ajax/agent.php b/pandora_console/include/ajax/agent.php index f735f3e589..8ea2ec6058 100644 --- a/pandora_console/include/ajax/agent.php +++ b/pandora_console/include/ajax/agent.php @@ -94,7 +94,7 @@ if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) { $filter = array (); if ($id_group != -1) { - if($id_group == 0) { + if ($id_group == 0) { $user_groups = users_get_groups ($config['id_user'], "AR", true); $filter['id_grupo'] = array_keys ($user_groups); diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 8edb9519ba..d6a1a864be 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -40,14 +40,14 @@ $history = get_parameter ('history', 0); if ($get_event_name) { $event_id = get_parameter ('event_id'); - if($meta) { + if ($meta) { $name = events_meta_get_event_name($event_id, $history); } else { $name = db_get_value('evento','tevento','id_evento',$event_id); } - if($name === false) { + if ($name === false) { return; } @@ -78,7 +78,7 @@ if ($get_response_params) { $params = db_get_value('params','tevent_response','id',$response_id); - if($params === false) { + if ($params === false) { return; } @@ -94,7 +94,7 @@ if ($get_response_target) { $event_response = db_get_row('tevent_response','id',$response_id); - if(empty($event_response)) { + if (empty($event_response)) { return; } @@ -108,7 +108,7 @@ if ($get_response) { $event_response = db_get_row('tevent_response','id',$response_id); - if(empty($event_response)) { + if (empty($event_response)) { return; } @@ -116,11 +116,11 @@ if ($get_response) { return; } -if($perform_event_response) { +if ($perform_event_response) { global $config; - + $command = get_parameter('target',''); - + echo system('/usr/bin/timeout 10 '.io_safe_output($command).' 2>&1'); return; @@ -191,7 +191,7 @@ if ($change_owner) { $event_id = get_parameter ('event_id'); $similars = true; - if($new_owner == -1) { + if ($new_owner == -1) { $new_owner = ''; } @@ -218,13 +218,13 @@ if ($get_extended_event) { } $readonly = false; - if(!$meta && + if (!$meta && isset($config['event_replication']) && $config['event_replication'] == 1 && $config['show_events_in_local'] == 1) { $readonly = true; } - + // Clean url from events and store in array $event['clean_tags'] = events_clean_tags($event['tags']); @@ -432,7 +432,7 @@ if ($get_events_details) { $out .= ''; $out .= ''; $out .= html_print_image(ui_get_full_url('images/clock.png', false, false, false), true, array('title' => __('Timestamp')), false, true); - + $out .= ''; $out .= ''; $out .= date($config['date_format'], $event['utimestamp']); @@ -444,8 +444,8 @@ if ($get_events_details) { $out .= ''; $out .= ''; $out .= $title; - if($event["estado"] == 1) { - if(empty($event['id_usuario'])) { + if ($event["estado"] == 1) { + if (empty($event['id_usuario'])) { $ack_user = '' . __('Auto') . ''; } else { @@ -454,7 +454,7 @@ if ($get_events_details) { $out .= ' (' . $ack_user . ')'; } - + $out .= ''; $out .= ''; diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index a51b3915c7..6cd43c2032 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -156,6 +156,7 @@ define('AGENT_STATUS_NORMAL', 0); define('AGENT_STATUS_NOT_INIT', 5); define('AGENT_STATUS_NOT_NORMAL', 6); define('AGENT_STATUS_UNKNOW', 3); +define('AGENT_STATUS_ALERT_FIRED', 4); define('AGENT_STATUS_WARNING', 2); /* Visual maps contants */ diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index ec904876cc..25ccad385d 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -247,7 +247,7 @@ function networkmap_generate_dot_groups ($pandora_name, $group = 0, $simple = 0, } else { $groups = db_get_all_rows_in_table ('tgrupo'); - if($groups === false) { + if ($groups === false) { $groups = array(); } } @@ -545,7 +545,7 @@ function networkmap_create_agent_node ($agent, $simple = 0, $font_size = 10, $cu $server_data = db_get_row('tmetaconsole_setup', 'id', $agent['id_server']); } - if(empty($server_data)) { + if (empty($server_data)) { $server_name = ''; $server_id = ''; $url_hash = ''; @@ -560,20 +560,21 @@ function networkmap_create_agent_node ($agent, $simple = 0, $font_size = 10, $cu // Set node status switch ($status) { - case 0: - $status_color = '#8DFF1D'; // Normal monitor + case AGENT_STATUS_NORMAL: + $status_color = '#8DFF1D'; break; - case 1: - $status_color = '#FF1D1D'; // Critical monitor + case AGENT_STATUS_CRITICAL: + $status_color = '#FF1D1D'; break; - case 2: - $status_color = '#FFE308'; // Warning monitor + case AGENT_STATUS_WARNING: + $status_color = '#FFE308'; break; - case 4: - $status_color = '#FFA300'; // Alert fired + case AGENT_STATUS_ALERT_FIRED: + $status_color = '#FFA300'; break; default: - $status_color = '#BBBBBB'; // Unknown monitor + //Unknown monitor + $status_color = '#BBBBBB'; break; } @@ -641,7 +642,7 @@ function networkmap_create_agent_node ($agent, $simple = 0, $font_size = 10, $cu $ajax_prefix = '../../'; $meta_params = '&metaconsole=1&id_server=' . $id_server; } - + if (can_user_access_node ()) { $url_node_link = ', URL="' . $console_url . 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $agent['id_agente'] . $url_hash . '"'; } diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 04efba2bfc..2167e9d6cd 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -6,13 +6,13 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, water_mark, separator, legend_position, height, colors) { var labels = labels.split(separator); var data = values.split(separator); - if(colors != '') { + if (colors != '') { colors = colors.split(separator); } var color = null; for (var i = 0; i < nseries; i++) { - if(colors != '') { + if (colors != '') { color = colors[i]; } @@ -250,13 +250,13 @@ function pandoraFlotHBars(graph_id, values, labels, water_mark, maxvalue, water_ // Events $('#'+graph_id).bind('plothover', function (event, pos, item) { $('.values_'+graph_id).css('font-weight', ''); - if(item != null) { + if (item != null) { index = item.dataIndex; $('#value_'+index+'_'+graph_id).css('font-weight', 'bold'); } }); - if(water_mark) { + if (water_mark) { set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); } } @@ -270,17 +270,17 @@ function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors, var datas = new Array(); - for(i=0;i' + legend[i] + ''; } } @@ -553,7 +553,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, var warning_min = new Array(); $.each(serie,function(i,v) { aux.push([i, v]); - if(threshold) { + if (threshold) { critical_min.push([i,red_threshold]); warning_min.push([i,yellow_threshold]); } @@ -572,7 +572,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, } var serie_color; - if(colors[i] != '') { + if (colors[i] != '') { serie_color = colors[i]; } else { @@ -616,7 +616,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, var threshold_data = new Array(); - if(threshold) { + if (threshold) { // Warning and critical treshold threshold_data.push({ id: 'critical_min', @@ -775,7 +775,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, // i is the series counter without thresholds var series = dataset[k]; - if(series.label == null) { + if (series.label == null) { continue; } @@ -787,10 +787,10 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, var y = series.data[j][1]; - if(currentRanges == null || (currentRanges.xaxis.from < j && j < currentRanges.xaxis.to)) { + if (currentRanges == null || (currentRanges.xaxis.from < j && j < currentRanges.xaxis.to)) { $('#timestamp_'+graph_id).show(); // If no legend, the timestamp labels are short and with value - if(legends.length == 0) { + if (legends.length == 0) { $('#timestamp_'+graph_id).text(labels[j] + ' (' + parseFloat(y).toFixed(2) + ')'); } else { @@ -801,7 +801,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, var timesize = $('#timestamp_'+graph_id).width(); - if(currentRanges != null) { + if (currentRanges != null) { dataset = plot.getData(); } @@ -809,7 +809,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, var canvaslimit = plot.offset().left + plot.width(); - if(timesize+timenewpos > canvaslimit) { + if (timesize+timenewpos > canvaslimit) { $('#timestamp_'+graph_id).css('left', timenewpos - timesize); } else { @@ -855,7 +855,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, var extrasize = parseInt($('#extra_'+graph_id).css('width').split('px')[0]); var left_pos; - if(extrasize+timenewpos > canvaslimit) { + if (extrasize+timenewpos > canvaslimit) { left_pos = timenewpos - extrasize - 20; } else { @@ -872,7 +872,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, case legend_alerts+series_suffix_str: case legend_alerts: extra_info = ''+legend_alerts+':
From: '+labels_long[item.dataIndex]; - if(labels_long[item.dataIndex+1] != undefined) { + if (labels_long[item.dataIndex+1] != undefined) { extra_info += '
To: '+labels_long[item.dataIndex+1]; } extra_info += '
'+get_event_details(alertsz[item.dataIndex]); @@ -881,18 +881,18 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, case legend_events+series_suffix_str: case legend_events: extra_info = ''+legend_events+':
From: '+labels_long[item.dataIndex]; - if(labels_long[item.dataIndex+1] != undefined) { + if (labels_long[item.dataIndex+1] != undefined) { extra_info += '
To: '+labels_long[item.dataIndex+1]; } extra_info += '
'+get_event_details(eventsz[item.dataIndex]); extra_show = true; break; default: - return; + return; break; } - if(extra_show) { + if (extra_show) { $('#extra_'+graph_id).html(extra_info); $('#extra_'+graph_id).css('display',''); } @@ -929,7 +929,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, // Format functions function xFormatter(v, axis) { - if(labels[v] == undefined) { + if (labels[v] == undefined) { return ''; } return '
'+labels[v]+'
'; @@ -955,7 +955,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, //~ showed[id_clicked] = this.checked; //~ }); - if(menu) { + if (menu) { var parent_height; $('#menu_overview_'+graph_id).click(function() { $('#overview_'+graph_id).toggle(); @@ -965,7 +965,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, $('#menu_threshold_'+graph_id).click(function() { datas = new Array(); - if(thresholded) { + if (thresholded) { thresholded = false; } else { @@ -1054,7 +1054,7 @@ function set_watermark(graph_id, plot, watermark_src) { //~ // Now resize the image: x, y, w, h. var down_ticks_height = 0; - if($('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height') != undefined) { + if ($('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height') != undefined) { down_ticks_height = $('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height').split('px')[0]; } var left_pos = parseInt(context.canvas.width - 3) - $('#watermark_image_'+graph_id)[0].width; @@ -1106,7 +1106,7 @@ function check_adaptions(graph_id) { $.each(classes, function(i,v) { // If has a class starting with adapted, we adapt it - if(v.split('_')[0] == 'adapted') { + if (v.split('_')[0] == 'adapted') { var adapter_id = $('.adapter_'+v.split('_')[1]).attr('id'); adjust_left_width_canvas(adapter_id, graph_id); } @@ -1115,7 +1115,7 @@ function check_adaptions(graph_id) { function number_format(number, force_integer, unit) { if (force_integer) { - if(Math.round(number) != number) { + if (Math.round(number) != number) { return ''; } }