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

* include/javascript/d3.v3.js: removed some changes.
	
	* include/functions_networkmap.php,
	operation/agentes/networkmap.dinamic.php,
	operation/agentes/networkmap.php: first version of dinamic view
	for networkmap. It needs implement tooltip and of course fix
	the new bugs.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8579 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-07-25 16:52:45 +00:00
parent f2450b3e8c
commit ef837a8378
5 changed files with 441 additions and 24 deletions

View File

@ -1,3 +1,13 @@
2013-07-25 Miguel de Dios <miguel.dedios@artica.es>
* include/javascript/d3.v3.js: removed some changes.
* include/functions_networkmap.php,
operation/agentes/networkmap.dinamic.php,
operation/agentes/networkmap.php: first version of dinamic view
for networkmap. It needs implement tooltip and of course fix
the new bugs.
2013-07-25 Sergio Martin <sergio.martin@artica.es>
* godmode/alerts/configure_alert_template.php: Fix alert

View File

@ -46,6 +46,189 @@ function networkmap_is_descendant ($node, $ascendant, $parents) {
return networkmap_is_descendant ($parents[$node], $ascendant, $parents);
}
function networkmap_print_jsdata($graph, $js_tags = true) {
if ($js_tags) {
echo "<script type='text/javascript'>";
if (empty($graph)) {
echo "var graph = null;\n";
return;
}
else {
echo "var graph = \n";
}
}
echo "{\n";
echo "'nodes' : \n";
echo "[\n";
$first = true;
foreach ($graph['nodes'] as $id => $node) {
if (!$first) {
echo ",\n";
}
$first = false;
echo "{
'id' : " . $id . ",
'name' : '" . $node['label'] . "',
'url' : '" . $node['url'] . "',
'tooltip' : '" . $node['tooltip'] . "',
'color' : '" . $node['color'] . "'}\n";
}
echo "],\n";
echo "'links' : \n";
echo "[\n";
$first = true;
foreach ($graph['lines'] as $line) {
if (!$first) {
echo ",\n";
}
$first = false;
echo "{
'source' : " . $line['source'] . ",
'target' : " . $line['target'] . "}\n";
}
echo "]\n";
echo "}\n";
if ($js_tags) {
echo ";\n";
echo "</script>";
}
}
function networkmap_generate_hash($pandora_name, $group = 0,
$simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0,
$zoom = 1, $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0,
$id_networkmap = 0, $show_snmp_modules = 0, $cut_names = true,
$relative = false, $text_filter = '') {
$graph = networkmap_generate_dot($pandora_name, $group,
$simple, $font_size, $layout, $nooverlap, $zoom, $ranksep,
$center, $regen, $pure, $id_networkmap, $show_snmp_modules,
$cut_names, $relative, $text_filter); html_debug_print($graph, true);
$return = array();
if (!empty($graph)) {
$graph = str_replace("\r", "\n", $graph);
$graph = str_replace("\n", " ", $graph);
//Removed the head
preg_match("/graph networkmap {(.*)}/", $graph, $matches);
$graph = $matches[1];
//Get the lines and nodes
$tokens = preg_split("/; /", $graph);
foreach ($tokens as $token) {
if (empty($token)) {
continue;
}
//Ignore the head rests.
if (preg_match("/(.+)\s*\[(.*)\]/", $token) != 0) {
$items[] = $token;
}
}
$lines = $nodes = array();
foreach ($items as $item) {
$matches = null;
preg_match("/(.+)\s*\[(.*)\]/", $item, $matches);
if (empty($matches))
continue;
$id_item = trim($matches[1]);
$content_item = trim($matches[2]);
//Check if is a edge or node
if (strstr($id_item, "--") !== false) {
//edge
$lines[$id_item] = $content_item;
}
else {
//node
$id_item = (int)$id_item;
$nodes[$id_item] = $content_item;
}
}
foreach($nodes as $key => $node) {
if ($key != 0) {
//Get label
$matches = null;
preg_match("/label=(.*),/", $node, $matches);
$label = $matches[1];
$matches = null;
preg_match("/\<TR\>\<TD\>(.*?)\<\/TD\>\<\/TR\>/",
$label, $matches);
$label = str_replace($matches[0], '', $label);
$matches = null;
preg_match("/\<TR\>\<TD\>(.*?)\<\/TD\>\<\/TR\>/",
$label, $matches);
$label = $matches[1];
//Get color
$matches = null;
preg_match("/color=\"([^\"]*)/", $node, $matches);
$color = $matches[1];
//Get tooltip
$matches = null;
preg_match("/tooltip=\"([^\"]*)/", $node, $matches);
$tooltip = $matches[1];
//Get URL
$matches = null;
preg_match("/URL=\"([^\"]*)/", $node, $matches);
$url = $matches[1];
$return['nodes'][$key]['label'] = $label;
$return['nodes'][$key]['color'] = $color;
$return['nodes'][$key]['tooltip'] = $tooltip;
$return['nodes'][$key]['url'] = $url;
}
else {
//Get tooltip
$matches = null;
preg_match("/tooltip=\"([^\"]*)/", $node, $matches);
$tooltip = $matches[1];
//Get URL
$matches = null;
preg_match("/URL=\"([^\"]*)/", $node, $matches);
$url = $matches[1];
$return['nodes'][$key]['label'] = "Pandora FMS";
$return['nodes'][$key]['color'] = "#7EBE3F";
$return['nodes'][$key]['tooltip'] = $tooltip;
$return['nodes'][$key]['url'] = $url;
}
}
ksort($return['nodes']);
foreach($lines as $key => $line) {
$data = array();
$points = explode(' -- ', $key);
$data['source'] = (int) $points[0];
$data['target'] = (int) $points[1];
$return['lines'][] = $data;
}
//html_debug_print($graph, true);
}
return $return;
}
// Generate a dot graph definition for graphviz
function networkmap_generate_dot ($pandora_name, $group = 0,
$simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0,
@ -180,7 +363,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
foreach ($parents as $node => $parent_id) {
// Verify that the parent is in the graph
if (isset ($nodes[$parent_id])) {
$graph .= networkmap_create_edge ($node, $parent_id, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'topology', $id_networkmap);
$graph .= networkmap_create_edge ($parent_id, $node , $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'topology', $id_networkmap);
}
else {
$orphans[$node] = 1;
@ -1062,11 +1245,17 @@ function networkmap_get_networkmaps ($id_user = '', $type = '', $optgrouped = tr
switch ($config["dbtype"]) {
case "mysql":
$networkmaps_raw = db_get_all_rows_filter ('tnetwork_map', 'id_user = "'.$id_user.'"'.$type_cond.' ORDER BY type DESC, name ASC', array('id_networkmap','name', 'type'));
$networkmaps_raw = db_get_all_rows_filter(
'tnetwork_map', 'id_user = "' . $id_user . '" ' .
$type_cond . ' ORDER BY type DESC, name ASC',
array('id_networkmap','name', 'type'));
break;
case "postgresql":
case "oracle":
$networkmaps_raw = db_get_all_rows_filter ('tnetwork_map', 'id_user = \''.$id_user.'\' '.$type_cond.' ORDER BY type DESC, name ASC', array('id_networkmap','name', 'type'));
$networkmaps_raw = db_get_all_rows_filter(
'tnetwork_map', 'id_user = \'' . $id_user . '\' ' .
$type_cond . ' ORDER BY type DESC, name ASC',
array('id_networkmap','name', 'type'));
break;
}
@ -1082,7 +1271,8 @@ function networkmap_get_networkmaps ($id_user = '', $type = '', $optgrouped = tr
'optgroup' => $networkmapitem['type']);
}
else {
$networkmaps[$networkmapitem['id_networkmap']] = $networkmapitem['name'];
$networkmaps[$networkmapitem['id_networkmap']] =
$networkmapitem['name'];
}
}
@ -1135,6 +1325,7 @@ function networkmap_get_types () {
$networkmap_types['topology'] = __('Create a new topology map');
$networkmap_types['groups'] = __('Create a new group map');
$networkmap_types['dinamic'] = __('Create a new dinamic map');
if ($is_enterprise !== ENTERPRISE_NOT_HOOK) {
$enterprise_types = enterprise_hook('policies_get_networkmap_types');
@ -1157,6 +1348,7 @@ function networkmap_get_filter_types () {
$networkmap_types['topology'] = __('Topology');
$networkmap_types['groups'] = __('Group');
$networkmap_types['dinamic'] = __('Dinamic');
if ($is_enterprise !== ENTERPRISE_NOT_HOOK) {
$enterprise_types = enterprise_hook('policies_get_networkmap_filter_types');

View File

@ -1152,7 +1152,7 @@ d3 = function() {
return d3.rebind(drag, event, "on");
};
d3.behavior.zoom = function() {
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;
var translate = [ 0, 0 ], translate0, scale = 1, distance0, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime;
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);
}
@ -1211,34 +1211,36 @@ d3 = function() {
return (y - translate[1]) / scale;
}).map(y0.invert));
}
zoom.setScale = function(v) {
zoom.setScale = function(v) {
scale = v;
}
zoom.setTranslate = function(v) {
zoom.setTranslate = function(v) {
translate = v;
}
zoom.getTranslate = function() {
zoom.getTranslate = function() {
return translate;
}
zoom.convertLevelsToScale = function(i) {
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) {
zoom.getZoomLevel = function(x, y) {
if (typeof(x) == 'undefined') {
x = 0;
//Get center
}
if (typeof(y) == 'undefined') {
y = 0;
//Get center
}
zoom_levels = [];
var zoom_levels = [];
if (!translate0)
translate0 = location([x, y]);

View File

@ -0,0 +1,192 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 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.
// Load global vars
global $config;
check_login ();
if (! check_acl ($config['id_user'], 0, "AR")) {
db_pandora_audit("ACL Violation",
"Trying to access node graph builder");
include ("general/noaccess.php");
exit;
}
require_once ('include/functions_networkmap.php');
// Set filter
$filter = networkmap_get_filter ($layout);
if (!isset($text_filter)) {
$text_filter = '';
}
// Generate dot file
$graph = networkmap_generate_hash(__('Pandora FMS'), $group, $simple,
$font_size, $layout, $nooverlap, $zoom, $ranksep, $center, $regen,
$pure, $id_networkmap, $show_snmp_modules, true, true,
$text_filter);
html_debug_print($graph, true);
networkmap_print_jsdata($graph);
//html_debug_print($graph);
echo '<script type="text/javascript" src="' . $config['homeurl'] . 'include/javascript/d3.v3.js" charset="utf-8"></script>';
echo '<div id="dinamic_networkmap"></div>';
?>
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.select_node {
stroke: #000;
stroke-width: 1.5px;
}
.link {
stroke: #999;
stroke-opacity: 1;
stroke-width: 1;
}
.select_link {
stroke: #000;
stroke-opacity: 1;
stroke-width: 1;
}
</style>
<script>
var width = $("#dinamic_networkmap").width(),
height = $("#main").height();
var color = d3.scale.category20();
var force = d3.layout.force()
.charge(-60)
.linkDistance(20)
.friction(0.9)
//.gravity(0.2)
.size([width, height]);
var zoom_obj = d3.behavior.zoom();
zoom_obj.scaleExtent([0.3, 3]).on("zoom", zoom);
var svg = d3.select("#dinamic_networkmap").append("svg")
.attr("width", width)
.attr("height", height)
.attr("pointer-events", "all")
.call(zoom_obj)
.append('svg:g');
force
.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("id", function(d) {
var id_text = 'link_'
+ d.source.id
+ "_" + d.target.id;
return id_text;
})
.attr("class", function(d) {
var class_text = 'link';
class_text += " source_" + d.source.id;
class_text += " target_" + d.target.id;
return class_text;
});
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("id", function(d) { return "node_" + d.id})
.attr("class", "node")
.attr("r", 5)
.style("fill", function(d) { return d.color; })
.call(force.drag)
.on("mouseover", over)
.on("mouseout", out)
.on("click", click);
node.append("title")
.text(function(d) { return d.name; });
svg.style("opacity", 1e-6)
.transition()
.duration(1000)
.style("opacity", 1);
force.on("tick", function() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
});
function over(d) {
$("#node_" + d.id).attr('class', 'select_node');
$.each($(".source_" + d.id), function(i, line) {
class_txt = $(line).attr('class');
id_txt = $(line).attr('id');
$("#" + id_txt).attr('class',
class_txt.replace("link", "select_link"));
});
}
function out(d) {
$("#node_" + d.id).attr('class', 'node');
$.each($(".source_" + d.id), function(i, line) {
class_txt = $(line).attr('class');
id_txt = $(line).attr('id');
$("#" + id_txt).attr('class',
class_txt.replace("select_link", "link"));
});
}
function click(d) {
window.location = d.url;
}
function zoom(translate_param, scale_param) {
var scale;
var translate;
if (typeof(translate_param) == "undefined") {
scale = d3.event.scale;
translate = d3.event.translate;
}
svg.attr("transform", "translate(" + translate + ")scale(" + scale + ")");
}
</script>

View File

@ -251,6 +251,9 @@ switch ($activeTab) {
case 'policies':
$title = __('Policies view');
break;
case 'dinamic':
$title = __('Dinamic view');
break;
}
if (!empty($name)) {
@ -307,8 +310,12 @@ if ($activeTab == 'topology') {
$table->data[0][] = __('Show interfaces') . '&nbsp;' .
html_print_checkbox ('show_snmp_modules', '1', $show_snmp_modules, true);
}
$table->data[0][] = __('Layout') . '&nbsp;' .
html_print_select ($layout_array, 'layout', $layout, '', '', '', true);
if ($activeTab != 'dinamic') {
$table->data[0][] = __('Layout') . '&nbsp;' .
html_print_select ($layout_array, 'layout', $layout, '', '', '', true);
}
if ($activeTab == 'groups') {
$depth_levels = array(
'all' => __('All'),
@ -327,8 +334,10 @@ if ($activeTab == 'policies') {
html_print_select ($depth_levels, 'depth', $depth, '', '', '', true, false, false);
}
$table->data[1][] = __('No Overlap') . '&nbsp;' .
html_print_checkbox ('nooverlap', '1', $nooverlap, true);
if ($activeTab != 'dinamic') {
$table->data[1][] = __('No Overlap') . '&nbsp;' .
html_print_checkbox ('nooverlap', '1', $nooverlap, true);
}
if (($activeTab == 'groups' || $activeTab == 'policies') &&
$depth == 'all') {
@ -342,11 +351,16 @@ if (($activeTab == 'groups' || $activeTab == 'policies') &&
}
}
}
$table->data[1][] = __('Simple') . '&nbsp;' .
html_print_checkbox ('simple', '1', $simple, true);
$table->data[1][] = __('Regenerate') . '&nbsp;' .
html_print_checkbox ('regen', '1', $regen, true);
if ($activeTab != 'dinamic') {
$table->data[1][] = __('Simple') . '&nbsp;' .
html_print_checkbox ('simple', '1', $simple, true);
}
if ($activeTab != 'dinamic') {
$table->data[1][] = __('Regenerate') . '&nbsp;' .
html_print_checkbox ('regen', '1', $regen, true);
}
if ($pure == "1") {
// Zoom
@ -368,8 +382,12 @@ if ($nooverlap == 1) {
$table->data[1][] = __('Distance between nodes') . '&nbsp;' .
html_print_input_text ('ranksep', $ranksep, __('Separation between elements in the map (in Non-overlap mode)'), 3, 4, true);
}
$table->data[1][] = __('Font') . '&nbsp;' .
html_print_input_text ('font_size', $font_size, $alt = 'Font size (in pt)', 2, 4, true);
if ($activeTab != 'dinamic') {
$table->data[1][] = __('Font') . '&nbsp;' .
html_print_input_text ('font_size', $font_size, $alt = 'Font size (in pt)', 2, 4, true);
}
$table->data[2][] = __('Free text for search (*):') . '&nbsp;' .
html_print_input_text('text_filter', $text_filter, '', 30, 100, true);
if ($activeTab == 'groups') {
@ -397,6 +415,9 @@ if ($id_networkmap != 0) {
case 'policies':
require_once(ENTERPRISE_DIR . '/operation/policies/networkmap.policies.php');
break;
case 'dinamic':
require_once('operation/agentes/networkmap.dinamic.php');
break;
default:
case 'topology':
require_once('operation/agentes/networkmap.topology.php');