From 63d07e1416721e94baec3f2c590d4d2e049744a3 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 12 Jul 2017 13:34:20 +0200 Subject: [PATCH] Added more things to new vc item --- .../visual_console_builder.editor.js | 35 +++++++++- .../visual_console_builder.elements.php | 1 + .../ajax/visual_console_builder.ajax.php | 70 ++++++++++++++++++- 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index 5b7b801f8b..fb28c0afb3 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -515,9 +515,10 @@ function readFields() { values['parent'] = $("select[name=parent]").val(); values['map_linked'] = $("select[name=map_linked]").val(); values['width_percentile'] = $("input[name=width_percentile]").val(); - values['max_percentile'] = $("input[name=max_percentile]").val(); + values['max_percentile'] = parseInt($("input[name=max_percentile]").val()); values['width_module_graph'] = $("input[name=width_module_graph]").val(); values['height_module_graph'] = $("input[name=height_module_graph]").val(); + values['event_max_time_row'] = $("select[name=event_max_time_row]").val(); values['type_percentile'] = $("input[name=type_percentile]:checked").val(); values['value_show'] = $("input[name=value_show]:checked").val(); values['enable_link'] = $("input[name=enable_link]").is(':checked') ? 1 : 0; @@ -587,6 +588,16 @@ function create_button_palette_callback() { validate = false; } break; + case 'auto_sla_graph': + if ((values['agent'] == '')) { + alert($("#message_alert_no_agent").html()); + validate = false; + } + if ((values['module'] == 0)) { + alert($("#message_alert_no_module").html()); + validate = false; + } + break; case 'label': if ((values['label'] == '')) { alert($("#message_alert_no_label").html()); @@ -1783,6 +1794,17 @@ function setPercentileBar(id_data, values) { }); } +function setEventsBar(id_data, values) { + metaconsole = $("input[name='metaconsole']").val(); + + var url_hack_metaconsole = ''; + if (is_metaconsole()) { + url_hack_metaconsole = '../../'; + } + + $("#image_" + id_data).attr('src', data); +} + function setPercentileBubble(id_data, values) { metaconsole = $("input[name='metaconsole']").val(); @@ -2094,6 +2116,17 @@ function createItem(type, values, id_data) { set_static_graph_status(id_data, values['image']); + break; + case 'auto_sla_graph': + var sizeStyle = ''; + var imageSize = ''; + item = $('
' + + '
' + values['label'] + '
' + + '' + + '
' + ); + + setEventsBar(id_data, values); break; case 'percentile_bar': case 'percentile_item': diff --git a/pandora_console/godmode/reporting/visual_console_builder.elements.php b/pandora_console/godmode/reporting/visual_console_builder.elements.php index 747a293de4..15134a9c1d 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.elements.php +++ b/pandora_console/godmode/reporting/visual_console_builder.elements.php @@ -470,6 +470,7 @@ foreach ($layoutDatas as $layoutData) { switch ($layoutData['type']) { case LINE_ITEM: case BOX_ITEM: + case AUTO_SLA_GRAPH: $table->data[$i + 2][4] = ""; break; default: diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index 2a786200ad..b096212b26 100755 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -95,6 +95,7 @@ $top = get_parameter('top', null); $agent = get_parameter('agent', null); $id_module = get_parameter('module', null); $period = get_parameter('period', null); +$event_max_time_row = get_parameter('event_max_time_row', null); $width = get_parameter('width', null); $height = get_parameter('height', null); $parent = get_parameter('parent', null); @@ -139,7 +140,70 @@ switch ($action) { echo json_encode($return); break; - + case 'get_module_events': + $data = array (); + + $resolution = $config['graph_res'] * ($event_max_time_row * 2 / 450); // Number of "slices" we want in graph + + $interval = (int) ($event_max_time_row / $resolution); + $date = get_system_time (); + $datelimit = $date - $event_max_time_row; + $periodtime = floor ($event_max_time_row / $interval); + $time = array (); + $data = array (); + $legend = array(); + $full_legend = array(); + + $cont = 0; + for ($i = 0; $i < $interval; $i++) { + $bottom = $datelimit + ($periodtime * $i); + + $name = date('H:i', $bottom); + + // Show less values in legend + if ($cont == 0 or $cont % 2) + $legend[$cont] = $name; + + $full_legend[$cont] = $name; + + $top = $datelimit + ($periodtime * ($i + 1)); + $event = db_get_row_filter ('tevento', + array ('id_agente' => $id_agent, + 'id_agentmodule' => $id_module, + 'utimestamp > '.$bottom, + 'utimestamp < '.$top), 'criticity, utimestamp'); + + if (!empty($event['utimestamp'])) { + $data[$cont]['utimestamp'] = $periodtime; + switch ($event['criticity']) { + case EVENT_CRIT_WARNING: + $data[$cont]['data'] = 2; + break; + case EVENT_CRIT_CRITICAL: + $data[$cont]['data'] = 3; + break; + default: + $data[$cont]['data'] = 1; + break; + } + } + else { + $data[$cont]['utimestamp'] = $periodtime; + $data[$cont]['data'] = 1; + } + $cont++; + } + + $colors = array(1 => COL_NORMAL, 2 => COL_WARNING, 3 => COL_CRITICAL, 4 => COL_UNKNOWN); + + $out = flot_slicesbar_graph($data, $period, 450, 15, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $homeurl, '', '', false, $id_agent); + html_debug($out, true); + if (!$out) { + $out = array(); + } + + echo json_encode($out); + break; case 'get_image_sparse': //Metaconsole db connection @@ -868,6 +932,10 @@ switch ($action) { } $values['period'] = $period; break; + case 'auto_sla_graph': + $values['type'] = AUTO_SLA_GRAPH; + $values['period'] = $event_max_time_row; + break; case 'percentile_item': case 'percentile_bar': if ($type_percentile == 'percentile') {