pandorafms/pandora_console/operation/agentes/networkmap.php

331 lines
9.7 KiB
PHP
Raw Normal View History

<?PHP
// Copyright (c) 2008 Ramon Novoa, rnovoa@gmail.com
//
// 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; 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.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Load global vars
require("include/config.php");
2008-06-30 10:11:10 +02:00
$pandora_name = 'Pandora FMS';
// Generate a dot graph definition for graphviz
2008-06-30 10:11:10 +02:00
function generate_dot ($simple = 0) {
global $config;
global $pandora_name;
$group_id = -1;
$parents = array();
$orphans = array();
// Open Graph
$graph = open_graph();
// Get agent data
$agents = mysql_query('SELECT * FROM tagente WHERE disabled = 0 ORDER BY id_grupo');
while ($agent = mysql_fetch_array($agents)) {
if (give_acl($config["id_user"], $agent["id_grupo"], "AR") == 0)
continue;
// Save node parent information to define edges later
if ($agent['id_parent'] != "0") {
$parents[$agent['id_agente']] = $agent['id_parent'];
}
else {
$orphans[$agent['id_agente']] = 1;
}
// Add node
$graph .= create_node($agent , $simple)."\n\t\t";
}
// Create a central node if orphan nodes exist
if (count ($orphans)) {
2008-06-30 10:11:10 +02:00
$graph .= create_pandora_node ($pandora_name);
}
// Define edges
foreach ($parents as $node => $parent_id) {
$graph .= create_edge ($node, $parent_id);
}
// Define edges for orphan nodes
foreach (array_keys($orphans) as $node) {
$graph .= create_edge ('0', $node);
}
// Close graph
$graph .= close_graph();
return $graph;
}
// Returns an edge definition
2008-06-30 10:11:10 +02:00
function create_edge ($head, $tail) {
$edge = $head.' -- '.$tail.'[color="#BDBDBD", headclip=false, tailclip=false];';
return $edge;
}
// Returns a node definition
2008-06-30 10:11:10 +02:00
function create_node ($agent, $simple = 0) {
$sql = sprintf ('SELECT COUNT(*) FROM tagente_estado,
tagente_modulo
WHERE tagente_modulo.id_agente = %d
AND tagente_modulo.id_tipo_modulo in (2, 6, 9, 18, 21, 100)
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.disabled = 0
AND tagente_estado.estado = 1', $agent['id_agente']);
$bad_modules = get_db_sql ($sql);
// Set node status
2008-06-30 10:11:10 +02:00
if ($bad_modules) {
$status_color = '#FF1D1D';
2008-06-30 10:11:10 +02:00
} else {
$status_color = '#8DFF1D';
}
2008-06-30 10:11:10 +02:00
// Short name
$name = strtolower ($agent["nombre"]);
if (strlen ($name) > 12)
$name = substr ($name, 0, 12);
2008-06-30 10:11:10 +02:00
if ($simple == 0){
// Set node icon
if (file_exists ('images/networkmap/'.$agent['id_os'].'.png')) {
$img_node = 'images/networkmap/'.$agent['id_os'].'.png';
2008-06-30 10:11:10 +02:00
} else {
$img_node = 'images/networkmap/0.png';
}
$node = $agent['id_agente'].' [ color="'.$status_color.'", fontsize=9, style="filled", fixedsize=true, width=0.40, height=0.40, label=<<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR><TD><IMG SRC="'.$img_node.'"/></TD></TR>
<TR><TD>'.$name.'</TD></TR></TABLE>>,
2008-06-30 10:11:10 +02:00
shape="ellipse", URL="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent['id_agente'].'",
tooltip="ajax.php?page=operation/agentes/ver_agente&get_agent_status_tooltip=1&id_agent='.$agent['id_agente'].'"];';
2008-06-30 10:11:10 +02:00
} else {
$node = $agent['id_agente'] . ' [ color="' . $status_color . '", fontsize=7, style="filled", fixedsize=true, width=0.20, height=0.20, label="", tooltip="ajax.php?page=operation/agentes/ver_agente&get_agent_status_tooltip=1&id_agent='.$agent['id_agente'].'"];';
2008-06-30 10:11:10 +02:00
}
return $node;
}
// Returns the definition of the central module
2008-06-30 10:11:10 +02:00
function create_pandora_node ($name) {
$node = '0 [ color="#364D1F", fontsize=10, style="filled", fixedsize=true, width=0.8, height=0.6, label=<<TABLE BORDER="0">
2008-06-30 10:11:10 +02:00
<TR><TD><IMG SRC="images/networkmap/pandora_node.png"/></TD></TR>
<TR><TD BGCOLOR="#FFFFFF">'.$name.'</TD></TR></TABLE>>,
shape="ellipse", tooltip="'.$name.'", URL="index.php?sec=estado&sec2=operation/agentes/estado_grupo" ];';
return $node;
}
// Opens a group definition
2008-06-30 10:11:10 +02:00
function open_group ($id) {
$img = 'images/' . dame_grupo_icono($id) . '.png';
$name = dame_nombre_grupo($id);
$group = 'subgraph cluster_' . $id .
2008-06-30 10:11:10 +02:00
' { style=filled; color=darkolivegreen3; label=<<TABLE BORDER="0">
<TR><TD><IMG SRC="'.$img.'"/></TD><TD>'.$name.'</TD></TR>
</TABLE>>; tooltip="'.$name.'";
2008-06-30 10:11:10 +02:00
URL="index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id='
. $id . '";';
return $group;
}
// Closes a group definition
2008-06-30 10:11:10 +02:00
function close_group () {
return '}';
}
// Opens a graph definition
function open_graph () {
global $config, $layout, $nooverlap, $pure, $zoom, $ranksep;
$overlap = 'compress';
$size_x = 8;
$size_y = 5.4;
$size = '';
if ($layout == "")
$layout = "radial";
if ($layout == 'radial')
$overlap = 'true';
if (($layout == 'flat') OR ($layout == 'spring1') OR ($layout == "spring2"))
if ($nooverlap != '')
$overlap = 'scalexy';
if ($pure == 1 && $zoom > 1 && $zoom <= 3) {
2008-07-02 Esteban Sanchez <estebans@artica.es> * general/logon_ok.php: Style correction. * include/languages/language_en.php: Added a couple of strings. * include/styles/pandora.css: Container div has now variable width, so Pandora console is wider now. * include/config.php: Replaced default values from last commit. Change homeurl variable, which now points to base url directory. * include/config_process.php: Style correction. Use pandora functions and indent the code properly. * reporting/fgraph.php, include/functions.php, ajax.php: Use require_once instead of require which speeds up the code parsing. * index.php: Use require_once instead of require which speeds up the code parsing. Add all GET and POST variables when refreshing a page. Style corrections. Use $_SERVER instead getenv. * include/functions_db.php: Avoid including config.php and use global instead. Replaced some id_user with the respective variable holds in config array. Replaced SQL syntax, removed an undeclared variable and renamed to english in event_insert(). Renamed return_moduledata_*_value() to get_agent_module_value_*(). Fixed an error in the sumatory when the module is incremental. * include/functions_reporting.php: Renamed return_module_SLA() to get_agent_module_sla(). * include/functions_reporting_pdf.php: Tabs and blankspaces correction. Style correction. Added new reports rendering, and fixed images references. Removed old and deprecated functions. * operation/agentes/networkmap.php: Style correction. * operation/agentes/sla_view.php, reporting/stat_win.php: Use renamed functions. * operation/reporting/reporting_viewer.php: Table reports width are now wider. Fixed some colspan problems. Generate custom graph ids better. Added agent and module name to SLAs. Style correction in the use of rowclass structure since now each content has its own table. * operation/reporting/custom_reporting.php: Removed unused variable for PDF reporting generation link. * operation/reporting/reporting_viewer_pdf.php: Rewrite the code to make style corrections and use pandora functions. * operation/menu.php: Tabs and blankspaces correction. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@916 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2008-07-02 14:30:56 +02:00
$size_x *= $zoom;
$size_y *= $zoom;
}
$size = $size_x . ',' . $size_y;
2008-06-30 10:11:10 +02:00
// BEWARE: graphwiz DONT use single ('), you need double (")
$head = "graph networkmap { labeljust=l; margin=0; ";
if ($nooverlap != '')
$head .= "ranksep=\"$ranksep\";";
$head .= "outputorder=edgesfirst;
2008-06-30 10:11:10 +02:00
overlap=\"$overlap\";
ratio=fill;
root=0;
size=\"$size\";
";
return $head;
2008-06-30 10:11:10 +02:00
}
// Closes a graph definition
function close_graph () {
return '}';
}
// Returns the filter used to achieve the desired layout
function set_filter () {
global $layout;
switch($layout) {
2008-06-30 10:11:10 +02:00
case 'flat':
return 'dot';
case 'radial':
return 'twopi';
case 'circular':
return 'circo';
case 'spring1':
return 'neato';
case 'spring2':
return 'fdp';
default:
return 'twopi';
}
}
2008-06-30 10:11:10 +02:00
/* Main code */
// Load variables
$layout = (string) get_parameter ('layout');
$nooverlap = (boolean) get_parameter ('nooverlap');
$pure = (int) get_parameter ('pure');
$zoom = (float) get_parameter ('zoom');
$ranksep = (float) get_parameter ('ranksep', 2.5);
$simple = (int) get_parameter ('simple', 0);
// Login check
$id_user = $_SESSION["id_usuario"];
global $REMOTE_ADDR;
if (comprueba_login() != 0) {
audit_db($id_user, $REMOTE_ADDR, "ACL Violation", "Trying to access node graph builder");
include("general/noaccess.php");
exit;
}
2008-06-30 10:11:10 +02:00
if ((give_acl($id_user, 0, "AR") != 1 ) && (dame_admin($id_user) !=1 )) {
audit_db($id_user, $REMOTE_ADDR, "ACL Violation", "Trying to access node graph builder");
include("general/noaccess.php");
exit;
}
echo '<h2>'.lang_string ('ag_title').' &gt; '.lang_string("Network Map").'&nbsp';
if ($pure == 1) {
2008-06-30 10:11:10 +02:00
echo '<a href="index.php?sec=estado&sec2=operation/agentes/networkmap&pure=0"><img src="images/monitor.png" title="' . lang_string('Normal screen') . '"></a>';
} else {
echo '<a href="index.php?sec=estado&sec2=operation/agentes/networkmap&pure=1"><img src="images/monitor.png" title="' . lang_string('Full screen') . '"></a>';
}
echo '</h2>';
// Layout selection
2008-06-30 10:11:10 +02:00
$layout_array = array ('radial' => 'radial',
'circular' => 'circular',
'spring1' => 'spring 1',
'spring2' => 'spring 2',
'flat' => 'flat');
echo '<form name="input" action="index.php?sec=estado&sec2=operation/agentes/networkmap&pure=' . $pure . '" method="post">';
echo '<table cellpadding="4" cellspacing="4" class="databox">';
echo '<tr>';
echo '<td valign="top">' . lang_string('Layout') . ' &nbsp;';
print_select ($layout_array, 'layout', $layout, '', '', '');
echo '</td>';
echo '<td valign="top">' . lang_string('No Overlap') . ' &nbsp;';
print_checkbox ('nooverlap', 'nooverlap', $nooverlap);
echo '</td>';
echo '<td valign="top">' . lang_string('Simple') . ' &nbsp;';
print_checkbox ('simple', '1', $simple);
echo '</td>';
if ($pure == "1") {
// Zoom
$zoom_array = array (
'1' => 'x1',
'1.2' => 'x2',
'1.6' => 'x3',
'2' => 'x4',
'2.5' => 'x5',
2008-06-30 10:11:10 +02:00
'5' => 'x10',
);
echo '<td valign="top">' . lang_string('Zoom') . ' &nbsp;';
print_select ($zoom_array, 'zoom', $zoom, '', '', '');
echo '</td>';
}
//echo ' Display groups <input type="checkbox" name="group" value="group" class="chk"/>';
echo '<td>';
echo '<input name="updbutton" type="submit" class="sub upd" value="'. lang_string ("update"). '">';
echo '</td>';
echo '</table>';
echo '</form>';
// Set filter
$filter = set_filter();
// Generate dot file
$graph = generate_dot($simple);
// Generate image and map
$cmd = "echo " . escapeshellarg($graph) .
2008-06-30 10:11:10 +02:00
" | $filter -Tcmapx -o".$config["attachment_store"]."/networkmap.map -Tpng -o".$config["attachment_store"]."/networkmap.png";
$result = system ($cmd);
if ($result !== false) {
if (! file_exists ($config["attachment_store"]."/networkmap.map")) {
echo '<h2 class="err">'.lang_string ('Map could not be generated').'</h2>';
echo $result;
return;
}
echo '<img src="attachment/networkmap.png" usemap="#networkmap"/>';
include $config["attachment_store"]."/networkmap.map";
} else {
echo '<h2 class="err">'.lang_string ('Map could not be generated').'</h2>';
echo $result;
return;
}
?>
2008-06-30 10:11:10 +02:00
<link rel="stylesheet" href="include/styles/cluetip.css" type="text/css" />
<script type="text/javascript" src="include/javascript/jquery.js"></script>
<script type="text/javascript" src="include/javascript/jquery.js"></script>
<script type="text/javascript" src="include/javascript/jquery.cluetip.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready (function () {
$("area[title!='<?=$pandora_name?>']").cluetip ({
arrows: true,
attribute: 'title',
cluetipClass: 'default',
fx: { open: 'fadeIn', openSpeed: 'slow' },
});
});
</script>