2013-07-22 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_graph.php, include/functions_reports.php,
	include/functions_groups.php, include/functions_incidents.php: fixed
	the source code style.
	
	* include/javascript/d3.v3.js: uploaded custom d3 version from
	https://github.com/mdtrooper/d3 . We need to pull request to
	the main branch...I love git.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8555 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-07-22 14:33:37 +00:00
parent 4cf2304b67
commit 67857667a4
6 changed files with 150 additions and 47 deletions

View File

@ -1,3 +1,13 @@
2013-07-22 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_graph.php, include/functions_reports.php,
include/functions_groups.php, include/functions_incidents.php: fixed
the source code style.
* include/javascript/d3.v3.js: uploaded custom d3 version from
https://github.com/mdtrooper/d3 . We need to pull request to
the main branch...I love git.
2013-07-22 Sergio Martin <sergio.martin@artica.es> 2013-07-22 Sergio Martin <sergio.martin@artica.es>
* include/functions_ui.php * include/functions_ui.php

View File

@ -106,7 +106,7 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') {
$stats['max'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); $stats['max'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
foreach ($chart_array as $item) { foreach ($chart_array as $item) {
if($series_suffix != '') { if ($series_suffix != '') {
$item['sum'] = $item['sum'.$series_suffix]; $item['sum'] = $item['sum'.$series_suffix];
$item['min'] = $item['min'.$series_suffix]; $item['min'] = $item['min'.$series_suffix];
$item['max'] = $item['max'.$series_suffix]; $item['max'] = $item['max'.$series_suffix];
@ -277,7 +277,7 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
$data_i++; $data_i++;
} }
if($max_value < $interval_max) { if ($max_value < $interval_max) {
$max_value = $interval_max; $max_value = $interval_max;
} }
@ -303,17 +303,17 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
$alert_ids[] = $events[$event_i]['id_evento']; $alert_ids[] = $events[$event_i]['id_evento'];
} }
if ($show_unknown) { if ($show_unknown) {
if($events[$event_i]['event_type'] == 'going_unknown') { if ($events[$event_i]['event_type'] == 'going_unknown') {
$is_unknown = true; $is_unknown = true;
} }
else if(substr ($events[$event_i]['event_type'], 0, 5) == 'going') { else if (substr ($events[$event_i]['event_type'], 0, 5) == 'going') {
$is_unknown = false; $is_unknown = false;
} }
} }
$event_i++; $event_i++;
} }
if($is_unknown) { if ($is_unknown) {
$unknown_value++; $unknown_value++;
} }
@ -362,24 +362,24 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
} }
// Data // Data
if($show_events) { if ($show_events) {
if(!isset($chart[$timestamp]['event'.$series_suffix])) { if (!isset($chart[$timestamp]['event'.$series_suffix])) {
$chart[$timestamp]['event'.$series_suffix] = 0; $chart[$timestamp]['event'.$series_suffix] = 0;
} }
$chart[$timestamp]['event'.$series_suffix] += $event_value; $chart[$timestamp]['event'.$series_suffix] += $event_value;
$series_type['event'.$series_suffix] = 'points'; $series_type['event'.$series_suffix] = 'points';
} }
if($show_alerts) { if ($show_alerts) {
if(!isset($chart[$timestamp]['alert'.$series_suffix])) { if (!isset($chart[$timestamp]['alert'.$series_suffix])) {
$chart[$timestamp]['alert'.$series_suffix] = 0; $chart[$timestamp]['alert'.$series_suffix] = 0;
} }
$chart[$timestamp]['alert'.$series_suffix] += $alert_value; $chart[$timestamp]['alert'.$series_suffix] += $alert_value;
$series_type['alert'.$series_suffix] = 'points'; $series_type['alert'.$series_suffix] = 'points';
} }
if($show_unknown) { if ($show_unknown) {
if(!isset($chart[$timestamp]['unknown'.$series_suffix])) { if (!isset($chart[$timestamp]['unknown'.$series_suffix])) {
$chart[$timestamp]['unknown'.$series_suffix] = 0; $chart[$timestamp]['unknown'.$series_suffix] = 0;
} }
@ -387,7 +387,7 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
$series_type['unknown'.$series_suffix] = 'area'; $series_type['unknown'.$series_suffix] = 'area';
} }
if($is_unknown) { if ($is_unknown) {
$total = $interval_max = $interval_min = $previous_data = 0; $total = $interval_max = $interval_min = $previous_data = 0;
} }
@ -659,7 +659,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
//$color['baseline'.$series_suffix] = array('border' => null, 'color' => '#0097BD', 'alpha' => 10); //$color['baseline'.$series_suffix] = array('border' => null, 'color' => '#0097BD', 'alpha' => 10);
$color['unit'.$series_suffix] = array('border' => null, 'color' => '#0097BC', 'alpha' => 10); $color['unit'.$series_suffix] = array('border' => null, 'color' => '#0097BC', 'alpha' => 10);
if($show_events) { if ($show_events) {
$legend['event'.$series_suffix_str] = __('Events').$series_suffix_str; $legend['event'.$series_suffix_str] = __('Events').$series_suffix_str;
$chart_extra_data['legend_events'] = $legend['event'].$series_suffix_str; $chart_extra_data['legend_events'] = $legend['event'].$series_suffix_str;
} }
@ -667,7 +667,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$legend['alert'.$series_suffix] = __('Alerts').$series_suffix_str; $legend['alert'.$series_suffix] = __('Alerts').$series_suffix_str;
$chart_extra_data['legend_alerts'] = $legend['alert'.$series_suffix_str]; $chart_extra_data['legend_alerts'] = $legend['alert'.$series_suffix_str];
} }
if($show_unknown) { if ($show_unknown) {
$legend['unknown'.$series_suffix] = __('Unknown').$series_suffix_str; $legend['unknown'.$series_suffix] = __('Unknown').$series_suffix_str;
$chart_extra_data['legend_unknown'] = $legend['unknown'.$series_suffix_str]; $chart_extra_data['legend_unknown'] = $legend['unknown'.$series_suffix_str];
} }
@ -1479,7 +1479,7 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
} }
foreach ($events as $event) { foreach ($events as $event) {
if($event['id_agentmodule'] == 0) { if ($event['id_agentmodule'] == 0) {
$key = __('System') . ' ('.$event['count_number'].')'; $key = __('System') . ' ('.$event['count_number'].')';
} }
else { else {
@ -1734,7 +1734,7 @@ function graph_db_agentes_modulos($width, $height) {
foreach ($modules as $module) { foreach ($modules as $module) {
$agent_name = agents_get_name ($module['id_agente'], "none"); $agent_name = agents_get_name ($module['id_agente'], "none");
if(empty($agent_name)) { if (empty($agent_name)) {
continue; continue;
} }
switch ($config['dbtype']){ switch ($config['dbtype']){
@ -1788,7 +1788,7 @@ function graphic_user_activity ($width = 350, $height = 230) {
} }
$logins = db_get_all_rows_sql ($sql); $logins = db_get_all_rows_sql ($sql);
if($logins == false) { if ($logins == false) {
$logins = array(); $logins = array();
} }
foreach ($logins as $login) { foreach ($logins as $login) {
@ -1814,7 +1814,7 @@ function grafico_incidente_prioridad () {
ORDER BY 2 DESC'; ORDER BY 2 DESC';
$incidents = db_get_all_rows_sql ($sql); $incidents = db_get_all_rows_sql ($sql);
if($incidents == false) { if ($incidents == false) {
$incidents = array(); $incidents = array();
} }
foreach ($incidents as $incident) { foreach ($incidents as $incident) {
@ -1892,14 +1892,14 @@ function graphic_incident_group () {
$incidents_all = db_get_value_sql($sql); $incidents_all = db_get_value_sql($sql);
if($incidents == false) { if ($incidents == false) {
$incidents = array(); $incidents = array();
} }
foreach ($incidents as $incident) { foreach ($incidents as $incident) {
$data[$incident['nombre']] = $incident['n_incidents']; $data[$incident['nombre']] = $incident['n_incidents'];
} }
if($incidents_all > 0) { if ($incidents_all > 0) {
$data[__('All')] = $incidents_all; $data[__('All')] = $incidents_all;
} }
@ -1928,11 +1928,11 @@ function graphic_incident_user () {
ORDER BY 1 DESC LIMIT %d', $max_items); ORDER BY 1 DESC LIMIT %d', $max_items);
$incidents = db_get_all_rows_sql ($sql); $incidents = db_get_all_rows_sql ($sql);
if($incidents == false) { if ($incidents == false) {
$incidents = array(); $incidents = array();
} }
foreach ($incidents as $incident) { foreach ($incidents as $incident) {
if($incident['id_usuario'] == false) { if ($incident['id_usuario'] == false) {
$name = __('System'); $name = __('System');
} }
else { else {
@ -1983,7 +1983,7 @@ function graphic_incident_source($width = 320, $height = 200) {
} }
$origins = db_get_all_rows_sql ($sql); $origins = db_get_all_rows_sql ($sql);
if($origins == false) { if ($origins == false) {
$origins = array(); $origins = array();
} }
foreach ($origins as $origin) { foreach ($origins as $origin) {
@ -2004,7 +2004,7 @@ function graph_events_validated($width = 300, $height = 200, $url = "", $meta =
$colors = array(); $colors = array();
foreach ($data_graph as $k => $v) { foreach ($data_graph as $k => $v) {
if($k == __('Validated')) { if ($k == __('Validated')) {
$colors[$k] = COL_NORMAL; $colors[$k] = COL_NORMAL;
} }
else { else {
@ -2046,7 +2046,7 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta =
// Choose the table where search if metaconsole or not // Choose the table where search if metaconsole or not
if ($meta) { if ($meta) {
if($history) { if ($history) {
$event_table = 'tmetaconsole_event_history'; $event_table = 'tmetaconsole_event_history';
} }
else { else {
@ -2650,10 +2650,10 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$alert_ids[] = $events[$k]['id_evento']; $alert_ids[] = $events[$k]['id_evento'];
} }
if ($show_unknown) { if ($show_unknown) {
if($events[$k]['event_type'] == 'going_unknown') { if ($events[$k]['event_type'] == 'going_unknown') {
$is_unknown = true; $is_unknown = true;
} }
else if(substr ($events[$k]['event_type'], 0, 5) == 'going') { else if (substr ($events[$k]['event_type'], 0, 5) == 'going') {
$is_unknown = false; $is_unknown = false;
} }
} }
@ -3278,7 +3278,7 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
$j++; $j++;
} }
if($max_value < $count) { if ($max_value < $count) {
$max_value = $count; $max_value = $count;
} }
@ -3329,7 +3329,7 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
$chart[$timestamp]['alert'] = $alert_value; $chart[$timestamp]['alert'] = $alert_value;
} }
if(!$avg_only) { if (!$avg_only) {
$chart[$timestamp]['max'] = 0; $chart[$timestamp]['max'] = 0;
} }
@ -3342,7 +3342,7 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
$chart[$timestamp]['sum'] = $previous_data; $chart[$timestamp]['sum'] = $previous_data;
} }
if(!$avg_only) { if (!$avg_only) {
$chart[$timestamp]['min'] = 0; $chart[$timestamp]['min'] = 0;
} }
} }
@ -3376,12 +3376,12 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
$color['alert'] = array('border' => '#ff7f00', 'color' => '#ff7f00', 'alpha' => 50); $color['alert'] = array('border' => '#ff7f00', 'color' => '#ff7f00', 'alpha' => 50);
} }
if(!$avg_only) { if (!$avg_only) {
$color['max'] = array('border' => '#000000', 'color' => $config['graph_color3'], 'alpha' => 50); $color['max'] = array('border' => '#000000', 'color' => $config['graph_color3'], 'alpha' => 50);
} }
$color['sum'] = array('border' => '#000000', 'color' => $config['graph_color2'], 'alpha' => 50); $color['sum'] = array('border' => '#000000', 'color' => $config['graph_color2'], 'alpha' => 50);
if(!$avg_only) { if (!$avg_only) {
$color['min'] = array('border' => '#000000', 'color' => $config['graph_color1'], 'alpha' => 50); $color['min'] = array('border' => '#000000', 'color' => $config['graph_color1'], 'alpha' => 50);
} }
@ -3403,13 +3403,13 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
$legend['alert'] = __('Alerts'); $legend['alert'] = __('Alerts');
} }
if(!$avg_only) { if (!$avg_only) {
$legend['max'] = __('Max').': '.__('Last').': '.$graph_stats['max']['last'].' '.$unit.' ; '.__('Avg').': '.$graph_stats['max']['avg'].' '.$unit.' ; '.__('Max').': '.$graph_stats['max']['max'].' '.$unit.' ; '.__('Min').': '.$graph_stats['max']['min'].' '.$unit; $legend['max'] = __('Max').': '.__('Last').': '.$graph_stats['max']['last'].' '.$unit.' ; '.__('Avg').': '.$graph_stats['max']['avg'].' '.$unit.' ; '.__('Max').': '.$graph_stats['max']['max'].' '.$unit.' ; '.__('Min').': '.$graph_stats['max']['min'].' '.$unit;
} }
$legend['sum'] = __('Avg').': '.__('Last').': '.$graph_stats['sum']['last'].' '.$unit.' ; '.__('Avg').': '.$graph_stats['sum']['avg'].' '.$unit.' ; '.__('Max').': '.$graph_stats['sum']['max'].' '.$unit.' ; '.__('Min').': '.$graph_stats['sum']['min'].' '.$unit; $legend['sum'] = __('Avg').': '.__('Last').': '.$graph_stats['sum']['last'].' '.$unit.' ; '.__('Avg').': '.$graph_stats['sum']['avg'].' '.$unit.' ; '.__('Max').': '.$graph_stats['sum']['max'].' '.$unit.' ; '.__('Min').': '.$graph_stats['sum']['min'].' '.$unit;
if(!$avg_only) { if (!$avg_only) {
$legend['min'] = __('Min').': '.__('Last').': '.$graph_stats['min']['last'].' '.$unit.' ; '.__('Avg').': '.$graph_stats['min']['avg'].' '.$unit.' ; '.__('Max').': '.$graph_stats['min']['max'].' '.$unit.' ; '.__('Min').': '.$graph_stats['min']['min'].' '.$unit; $legend['min'] = __('Min').': '.__('Last').': '.$graph_stats['min']['last'].' '.$unit.' ; '.__('Avg').': '.$graph_stats['min']['avg'].' '.$unit.' ; '.__('Max').': '.$graph_stats['min']['max'].' '.$unit.' ; '.__('Min').': '.$graph_stats['min']['min'].' '.$unit;
} }
@ -3443,7 +3443,7 @@ function graphic_module_events ($id_module, $width, $height, $period = 0, $homeu
$resolution = $config['graph_res'] * ($period * 2 / $width); // Number of "slices" we want in graph $resolution = $config['graph_res'] * ($period * 2 / $width); // Number of "slices" we want in graph
$interval = (int) ($period / $resolution); $interval = (int) ($period / $resolution);
if($date === false) { if ($date === false) {
$date = get_system_time (); $date = get_system_time ();
} }
$datelimit = $date - $period; $datelimit = $date - $period;
@ -3501,13 +3501,13 @@ function graphic_module_events ($id_module, $width, $height, $period = 0, $homeu
// The default status is normal. Do nothing // The default status is normal. Do nothing
break; break;
case 'going_unknown': case 'going_unknown':
if($status == 'normal') { if ($status == 'normal') {
$status = 'unknown'; $status = 'unknown';
} }
break; break;
case 'going_up_warning': case 'going_up_warning':
case 'going_down_warning': case 'going_down_warning':
if($status == 'normal' || $status == 'unknown') { if ($status == 'normal' || $status == 'unknown') {
$status = 'warning'; $status = 'warning';
} }
break; break;

View File

@ -412,7 +412,7 @@ function groups_get_all($groupWithAgents = false) {
$rows = db_get_all_rows_sql ($sql); $rows = db_get_all_rows_sql ($sql);
if($rows === false) { if ($rows === false) {
$rows = array(); $rows = array();
} }
@ -573,7 +573,7 @@ function groups_get_status ($id_group = 0) {
function groups_get_name ($id_group, $returnAllGroup = false) { function groups_get_name ($id_group, $returnAllGroup = false) {
if ($id_group > 0) if ($id_group > 0)
return (string) db_get_value ('nombre', 'tgrupo', 'id_grupo', (int) $id_group); return (string) db_get_value ('nombre', 'tgrupo', 'id_grupo', (int) $id_group);
elseif($returnAllGroup) elseif ($returnAllGroup)
return __("All"); return __("All");
} }

View File

@ -408,7 +408,7 @@ function incidents_call_api($url, $postparameters = false) {
$curlObj = curl_init(); $curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $url); curl_setopt($curlObj, CURLOPT_URL, $url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
if($postparameters !== false) { if ($postparameters !== false) {
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $postparameters); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $postparameters);
} }
$result = curl_exec($curlObj); $result = curl_exec($curlObj);

View File

@ -595,7 +595,7 @@ function reports_get_report_types ($template = false, $not_editor = false) {
$types['event_report_group'] = array('optgroup' => __('Events'), $types['event_report_group'] = array('optgroup' => __('Events'),
'name' => __('Event report group')); 'name' => __('Event report group'));
if($config['enterprise_installed']) { if ($config['enterprise_installed']) {
$types['inventory'] = array('optgroup' => __('Inventory'), $types['inventory'] = array('optgroup' => __('Inventory'),
'name' => __('Inventory')); 'name' => __('Inventory'));
if (!$template) { if (!$template) {

View File

@ -1,3 +1,6 @@
//This is a custom version from
// https://github.com/mdtrooper/d3
d3 = function() { d3 = function() {
var d3 = { var d3 = {
version: "3.2.4" version: "3.2.4"
@ -1149,7 +1152,7 @@ d3 = function() {
return d3.rebind(drag, event, "on"); return d3.rebind(drag, event, "on");
}; };
d3.behavior.zoom = function() { d3.behavior.zoom = function() {
var translate = [ 0, 0 ], translate0, scale = 1, distance0, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime; var translate = [ 0, 0 ], zoom_levels = null, translate0, scale = 1, distance0, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
function zoom() { function zoom() {
this.on("mousedown.zoom", mousedown).on("mousemove.zoom", mousemove).on(d3_behavior_zoomWheel + ".zoom", mousewheel).on("dblclick.zoom", dblclick).on("touchstart.zoom", touchstart).on("touchmove.zoom", touchmove).on("touchend.zoom", touchstart); this.on("mousedown.zoom", mousedown).on("mousemove.zoom", mousemove).on(d3_behavior_zoomWheel + ".zoom", mousewheel).on("dblclick.zoom", dblclick).on("touchstart.zoom", touchstart).on("touchmove.zoom", touchmove).on("touchend.zoom", touchstart);
} }
@ -1208,6 +1211,88 @@ d3 = function() {
return (y - translate[1]) / scale; return (y - translate[1]) / scale;
}).map(y0.invert)); }).map(y0.invert));
} }
zoom.setScale = function(v) {
scale = v;
}
zoom.setTranslate = function(v) {
translate = v;
}
zoom.getTranslate = function() {
return translate;
}
zoom.convertLevelsToScale = function(i) {
min = Math.pow(2, (-360 * i) * .002) * 1;
max = Math.pow(2, (360 * i) * .002) * 1;
return [min, max];
}
zoom.getZoomLevel = function(x, y) {
if (typeof(x) == 'undefined') {
//Get center
}
if (typeof(y) == 'undefined') {
//Get center
}
zoom_levels = [];
if (!translate0)
translate0 = location([x, y]);
var old_scale = scale;
var old_translate = [translate[0], translate[1]];
var count = 0;
scale = 1;
high_levels = [];
high_levels.push({'scale': scale, 'translate': [translate[0], translate[1]]});
do {
scaleTo(Math.pow(2, 360 * .002) * scale);
translateTo([x, y], translate0);
high_levels.push({'scale': scale, 'translate': [translate[0], translate[1]]});
if (count > 30) {
break;
}
count++;
}
while (scale < scaleExtent[1]);
scale = 1;
count = 0;
do {
scaleTo(Math.pow(2, -360 * .002) * scale);
translateTo([x, y], translate0);
zoom_levels.push({'scale': scale, 'translate': [translate[0], translate[1]]});
if (count > 30) {
break;
}
count++;
}
while (scale > scaleExtent[0]);
zoom_levels.reverse();
high_levels.forEach(function(v, i) {
zoom_levels.push(v);
});
scale = old_scale;
translate = old_translate;
return zoom_levels;
}
function dispatch(event) { function dispatch(event) {
rescale(); rescale();
d3.event.preventDefault(); d3.event.preventDefault();
@ -1231,8 +1316,14 @@ d3 = function() {
} }
function mousewheel() { function mousewheel() {
if (!translate0) translate0 = location(d3.mouse(this)); if (!translate0) translate0 = location(d3.mouse(this));
scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * scale);
translateTo(d3.mouse(this), translate0); var d3_behavior_zoomDelta_var = d3_behavior_zoomDelta();
scaleTo(Math.pow(2, d3_behavior_zoomDelta_var * .002) * scale);
var d3_mouse_this = d3.mouse(this);
translateTo(d3_mouse_this, translate0);
dispatch(event.of(this, arguments)); dispatch(event.of(this, arguments));
} }
function mousemove() { function mousemove() {
@ -1240,7 +1331,9 @@ d3 = function() {
} }
function dblclick() { function dblclick() {
var p = d3.mouse(this), l = location(p), k = Math.log(scale) / Math.LN2; var p = d3.mouse(this), l = location(p), k = Math.log(scale) / Math.LN2;
scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1)); scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
translateTo(p, l); translateTo(p, l);
dispatch(event.of(this, arguments)); dispatch(event.of(this, arguments));
} }