Merge branch 'ent-10696-nuevo-widget-netflow' into 'develop'
Ent 10696 nuevo widget netflow See merge request artica/pandorafms!5890
This commit is contained in:
commit
9ff13234be
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -4624,7 +4624,10 @@ function graph_netflow_circular_mesh($data)
|
|||
|
||||
include_once $config['homedir'].'/include/graphs/functions_d3.php';
|
||||
|
||||
return d3_relationship_graph($data['elements'], $data['matrix'], 900, true);
|
||||
$width = (empty($data['width']) === false) ? $data['width'] : 900;
|
||||
$height = (empty($data['height']) === false) ? $data['height'] : 900;
|
||||
|
||||
return d3_relationship_graph($data['elements'], $data['matrix'], $width, true, $height);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1233,7 +1233,9 @@ function netflow_draw_item(
|
|||
$max_aggregates,
|
||||
$connection_name='',
|
||||
$output='HTML',
|
||||
$address_resolution=false
|
||||
$address_resolution=false,
|
||||
$width_content=false,
|
||||
$height_content=false
|
||||
) {
|
||||
$aggregate = $filter['aggregate'];
|
||||
$interval = ($end_date - $start_date);
|
||||
|
@ -1432,6 +1434,9 @@ function netflow_draw_item(
|
|||
netflow_aggregate_is_ip($aggregate)
|
||||
);
|
||||
|
||||
$data_circular['width'] = $width_content;
|
||||
$data_circular['height'] = $height_content;
|
||||
|
||||
$html = '<div class="center">';
|
||||
$html .= graph_netflow_circular_mesh($data_circular);
|
||||
$html .= '</div>';
|
||||
|
|
|
@ -57,7 +57,7 @@ function include_javascript_d3($return=false)
|
|||
}
|
||||
|
||||
|
||||
function d3_relationship_graph($elements, $matrix, $width=700, $return=false)
|
||||
function d3_relationship_graph($elements, $matrix, $width=700, $return=false, $height=700)
|
||||
{
|
||||
global $config;
|
||||
|
||||
|
@ -72,7 +72,7 @@ function d3_relationship_graph($elements, $matrix, $width=700, $return=false)
|
|||
$output = '<div id="chord_diagram"></div>';
|
||||
$output .= include_javascript_d3(true);
|
||||
$output .= "<script language=\"javascript\" type=\"text/javascript\">
|
||||
chordDiagram('#chord_diagram', $elements, $matrix, $width);
|
||||
chordDiagram('#chord_diagram', $elements, $matrix, $width, $height);
|
||||
</script>";
|
||||
|
||||
if (!$return) {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
// matrix = [[0, 0, 2], // a[a => a, a => b, a => c]
|
||||
// [5, 0, 1], // b[b => a, b => b, b => c]
|
||||
// [2, 3, 0]]; // c[c => a, c => b, c => c]
|
||||
function chordDiagram(recipient, elements, matrix, width) {
|
||||
function chordDiagram(recipient, elements, matrix, width, height) {
|
||||
d3.chart = d3.chart || {};
|
||||
d3.chart.chordWheel = function(options) {
|
||||
// Default values
|
||||
|
@ -59,10 +59,13 @@ function chordDiagram(recipient, elements, matrix, width) {
|
|||
.enter()
|
||||
.append("svg:svg")
|
||||
.attr("width", width)
|
||||
.attr("height", width)
|
||||
.attr("height", height)
|
||||
.attr("class", "dependencyWheel")
|
||||
.append("g")
|
||||
.attr("transform", "translate(" + width / 2 + "," + width / 2 + ")");
|
||||
.attr(
|
||||
"transform",
|
||||
"translate(" + width / 2 + "," + height / 2 + ") scale(1.2)"
|
||||
);
|
||||
|
||||
var arc = d3.svg
|
||||
.arc()
|
||||
|
@ -206,8 +209,8 @@ function chordDiagram(recipient, elements, matrix, width) {
|
|||
.on("mousemove", move_tooltip);
|
||||
|
||||
function move_tooltip(d) {
|
||||
x = d3.event.pageX + 10;
|
||||
y = d3.event.pageY + 10;
|
||||
x = d3.event.layerX + 10;
|
||||
y = d3.event.layerY + 10;
|
||||
|
||||
$("#tooltip").css("left", x + "px");
|
||||
$("#tooltip").css("top", y + "px");
|
||||
|
|
|
@ -416,6 +416,10 @@ class Widget
|
|||
$className .= '\OsQuickReportWidget';
|
||||
break;
|
||||
|
||||
case 'netflow':
|
||||
$className .= '\Netflow';
|
||||
break;
|
||||
|
||||
case 'GroupedMeterGraphs':
|
||||
case 'ColorModuleTabs':
|
||||
case 'BlockHistogram':
|
||||
|
|
|
@ -0,0 +1,465 @@
|
|||
<?php
|
||||
/**
|
||||
* Widget Netflow Pandora FMS Console
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Widget Netflow
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
namespace PandoraFMS\Dashboard;
|
||||
|
||||
/**
|
||||
* Netflow.
|
||||
*/
|
||||
class Netflow extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Title widget.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Page widget;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Class name widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* Values options for each widget.
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Configuration required.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $configurationRequired;
|
||||
|
||||
/**
|
||||
* Error load widget.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $loadError;
|
||||
|
||||
/**
|
||||
* Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* Heigth.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* Grid Width.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $gridWidth;
|
||||
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param integer $cellId Cell ID.
|
||||
* @param integer $dashboardId Dashboard ID.
|
||||
* @param integer $widgetId Widget ID.
|
||||
* @param integer|null $width New width.
|
||||
* @param integer|null $height New height.
|
||||
* @param integer|null $gridWidth Grid width.
|
||||
*/
|
||||
public function __construct(
|
||||
int $cellId,
|
||||
int $dashboardId=0,
|
||||
int $widgetId=0,
|
||||
?int $width=0,
|
||||
?int $height=0,
|
||||
?int $gridWidth=0
|
||||
) {
|
||||
global $config;
|
||||
|
||||
// Includes.
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
include_once $config['homedir'].'/include/class/NetworkMap.class.php';
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
$dashboardId,
|
||||
$widgetId
|
||||
);
|
||||
|
||||
// Width.
|
||||
$this->width = $width;
|
||||
|
||||
// Height.
|
||||
$this->height = $height;
|
||||
|
||||
// Grid Width.
|
||||
$this->gridWidth = $gridWidth;
|
||||
|
||||
// Options.
|
||||
$this->values = $this->getOptionsWidget();
|
||||
|
||||
// Positions.
|
||||
$this->position = $this->getPositionWidget();
|
||||
|
||||
// Page.
|
||||
$this->page = basename(__FILE__);
|
||||
|
||||
// ClassName.
|
||||
$class = new \ReflectionClass($this);
|
||||
$this->className = $class->getShortName();
|
||||
|
||||
// Title.
|
||||
$this->title = __('Netflow');
|
||||
|
||||
// Name.
|
||||
if (empty($this->name) === true) {
|
||||
$this->name = 'netflow';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
* @return array Of inputs.
|
||||
*
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
$values = $this->values;
|
||||
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Default values.
|
||||
if (isset($values['quantity']) === false) {
|
||||
$values['quantity'] = 5;
|
||||
}
|
||||
|
||||
// Default values.
|
||||
if (isset($values['period']) === false) {
|
||||
$values['period'] = SECONDS_1WEEK;
|
||||
}
|
||||
|
||||
// Default values.
|
||||
if (isset($values['max_values']) === false) {
|
||||
$values['max_values'] = 10;
|
||||
}
|
||||
|
||||
// Period.
|
||||
$inputs[] = [
|
||||
'label' => __('Interval'),
|
||||
'arguments' => [
|
||||
'name' => 'period',
|
||||
'type' => 'interval',
|
||||
'value' => $values['period'],
|
||||
'nothing' => __('None'),
|
||||
'nothing_value' => 0,
|
||||
'style_icon' => 'flex-grow: 0',
|
||||
],
|
||||
];
|
||||
$chart_types = netflow_get_chart_types();
|
||||
$chart_types['usage_map'] = __('Usage map');
|
||||
$inputs[] = [
|
||||
'label' => __('Type graph'),
|
||||
'arguments' => [
|
||||
'name' => 'chart_type',
|
||||
'type' => 'select',
|
||||
'fields' => $chart_types,
|
||||
'selected' => $values['chart_type'],
|
||||
],
|
||||
];
|
||||
|
||||
$aggregate_list = [
|
||||
'srcip' => __('Src Ip Address'),
|
||||
'dstip' => __('Dst Ip Address'),
|
||||
'srcport' => __('Src Port'),
|
||||
'dstport' => __('Dst Port'),
|
||||
];
|
||||
$inputs[] = [
|
||||
'label' => __('Aggregated by'),
|
||||
'id' => 'aggregated',
|
||||
'arguments' => [
|
||||
'name' => 'aggregate',
|
||||
'type' => 'select',
|
||||
'fields' => $aggregate_list,
|
||||
'selected' => $values['aggregate'],
|
||||
],
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Data to show'),
|
||||
'id' => 'data_to_show',
|
||||
'arguments' => [
|
||||
'name' => 'action',
|
||||
'type' => 'select',
|
||||
'fields' => network_get_report_actions(),
|
||||
'selected' => $values['action'],
|
||||
],
|
||||
];
|
||||
|
||||
$max_values = [
|
||||
'2' => '2',
|
||||
'5' => '5',
|
||||
'10' => '10',
|
||||
'15' => '15',
|
||||
'20' => '20',
|
||||
'25' => '25',
|
||||
'50' => '50',
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Max values'),
|
||||
'arguments' => [
|
||||
'name' => 'max_values',
|
||||
'type' => 'select',
|
||||
'fields' => $max_values,
|
||||
'selected' => $values['max_values'],
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Post for widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost():array
|
||||
{
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['period'] = \get_parameter('period', 0);
|
||||
$values['chart_type'] = \get_parameter('chart_type', '');
|
||||
$values['aggregate'] = \get_parameter('aggregate');
|
||||
$values['max_values'] = \get_parameter('max_values', 10);
|
||||
$values['action'] = \get_parameter('action', 'srcip');
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw widget.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
ui_require_css_file('netflow_widget', 'include/styles/', true);
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
|
||||
$size = parent::getSize();
|
||||
|
||||
$start_date = (time() - $this->values['period']);
|
||||
$end_date = time();
|
||||
if ($this->values['chart_type'] === 'usage_map') {
|
||||
$map_data = netflow_build_map_data(
|
||||
$start_date,
|
||||
$end_date,
|
||||
$this->values['max_values'],
|
||||
($this->values['action'] === 'talkers') ? 'srcip' : 'dstip'
|
||||
);
|
||||
$has_data = !empty($map_data['nodes']);
|
||||
|
||||
if ($has_data === true) {
|
||||
$map_manager = new \NetworkMap($map_data);
|
||||
$map_manager->printMap();
|
||||
} else {
|
||||
ui_print_info_message(__('No data to show'));
|
||||
}
|
||||
} else {
|
||||
$netflowContainerClass = ($this->values['chart_type'] === 'netflow_data' || $this->values['chart_type'] === 'netflow_summary' || $this->values['chart_type'] === 'netflow_top_N') ? '' : 'white_box';
|
||||
$filter = [
|
||||
'aggregate' => $this->values['aggregate'],
|
||||
'netflow_monitoring_interval' => 300,
|
||||
];
|
||||
|
||||
$output .= html_print_input_hidden(
|
||||
'selected_style_theme',
|
||||
$config['style'],
|
||||
true
|
||||
);
|
||||
$style = 'width:100%; height: 100%; border: none;';
|
||||
if ($this->values['chart_type'] !== 'netflow_area') {
|
||||
$style .= ' width: 95%;';
|
||||
}
|
||||
|
||||
if ($size['width'] > $size['height']) {
|
||||
$size['width'] = $size['height'];
|
||||
}
|
||||
|
||||
// Draw the netflow chart.
|
||||
$output .= html_print_div(
|
||||
[
|
||||
'class' => $netflowContainerClass,
|
||||
'style' => $style,
|
||||
'content' => netflow_draw_item(
|
||||
$start_date,
|
||||
$end_date,
|
||||
12,
|
||||
$this->values['chart_type'],
|
||||
$filter,
|
||||
$this->values['max_values'],
|
||||
'',
|
||||
'HTML',
|
||||
0,
|
||||
($size['width'] - 50),
|
||||
($size['height'] - 20),
|
||||
),
|
||||
],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return aux javascript code for forms.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormJS()
|
||||
{
|
||||
return '
|
||||
$(document).ready(function(){
|
||||
//Limit 1 week
|
||||
$("#period_select option").each(function(key, element){
|
||||
if(element.value > 604800){
|
||||
$(element).remove();
|
||||
}
|
||||
})
|
||||
$("#period_manual option").each(function(key, element){
|
||||
if(element.value > 604800){
|
||||
$(element).remove();
|
||||
}
|
||||
});
|
||||
$("#period_manual input").on("change", function(e){
|
||||
if($("#hidden-period").val() > 604800) {
|
||||
$(this).val(1);
|
||||
$("#hidden-period").val(604800);
|
||||
$("#period_manual select option").removeAttr("selected");
|
||||
setTimeout(() => {
|
||||
$("#period_default select option[value=\'604800\']").attr("selected", "selected");
|
||||
$("#period_manual select option[value=\'604800\']").attr("selected", "selected");
|
||||
$("#period_manual select").val(604800);
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
if($("#chart_type").val() === "usage_map") {
|
||||
$("#data_to_show").show();
|
||||
$("#aggregated").hide();
|
||||
} else {
|
||||
$("#data_to_show").hide();
|
||||
$("#aggregated").show();
|
||||
}
|
||||
$("#chart_type").on("change", function(e){
|
||||
if(this.value === "usage_map") {
|
||||
$("#data_to_show").show();
|
||||
$("#aggregated").hide();
|
||||
} else {
|
||||
$("#data_to_show").hide();
|
||||
$("#aggregated").show();
|
||||
}
|
||||
});
|
||||
});
|
||||
';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get description.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return __('Netflow');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Name.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'netflow';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get size Modal Configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSizeModalConfiguration(): array
|
||||
{
|
||||
$size = [
|
||||
'width' => 400,
|
||||
'height' => 530,
|
||||
];
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
.menu_graph {
|
||||
display: none;
|
||||
}
|
||||
.parent_graph {
|
||||
width: 97% !important;
|
||||
}
|
||||
#image_hide_show_labels {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.select2-search--dropdown .select2-search__field {
|
||||
padding: 0px !important;
|
||||
}
|
Loading…
Reference in New Issue