2011-05-30 Javier Lanz <javier.lanz@artica.es>

* include/functions_reporting.php: Edited "render_report_html" function
	to work with metaconsole printing metaconsole elements
	* include/javascript/pandora.js: Modified autocomplete javascript to use
	with metaconsole
	* include/ajax/reporting.ajax.php: Edited to work with metaconsole
	* include/ajax/agent.php: Edited autocomplete to work with metaconsole
	* operation/agentes/ver_agente.php: Modified to get the agent's modules
	using metacofacensole
	* godmode/reporting/reporting_builder.list_items.php: Edited to display
	agents & modules in metaconsole. Edited top filters to work with
	metaconsole
	* godmode/reporting/reporting_builder.php: Added getting parameter
	server_name & fixed deleting items
	* godmode/reporting/reporting_builder.item_editor.php: Edited to send
	the host when metaconsole is active


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4393 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
javilanz 2011-05-30 17:04:34 +00:00
parent 10d2bd9b7c
commit 7ab6d52403
9 changed files with 511 additions and 159 deletions

View File

@ -1,3 +1,20 @@
2011-05-30 Javier Lanz <javier.lanz@artica.es>
* include/functions_reporting.php: Edited "render_report_html" function
to work with metaconsole printing metaconsole elements
* include/javascript/pandora.js: Modified autocomplete javascript to use
with metaconsole
* include/ajax/reporting.ajax.php: Edited to work with metaconsole
* include/ajax/agent.php: Edited autocomplete to work with metaconsole
* operation/agentes/ver_agente.php: Modified to get the agent's modules
using metacofacensole
* godmode/reporting/reporting_builder.list_items.php: Edited to display
agents & modules in metaconsole. Edited top filters to work with
metaconsole
* godmode/reporting/reporting_builder.php: Added getting parameter
server_name & fixed deleting items
* godmode/reporting/reporting_builder.item_editor.php: Edited to send
the host when metaconsole is active
2011-05-30 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* install.php: Fixed typo mistake in this file.

View File

@ -28,6 +28,7 @@ $show_graph_options[1] = __('Table & Graph');
$show_graph_options[2] = __('Only graph');
enterprise_include('/godmode/reporting/reporting_builder.item_editor.php');
enterprise_include_once ('include/functions_metaconsole.php');
require_once ($config['homedir'].'/include/functions_agents.php');
switch ($action) {
@ -67,15 +68,24 @@ switch ($action) {
$show_in_two_columns = 0;
$show_in_landscape = 0;
$modulegroup = 0;
$server_name = '';
break;
default:
$actionParameter = 'update';
$item = db_get_row_filter('treport_content', array('id_rc' => $idItem));
$server_name = $item ['server_name'];
// Metaconsole db connection
if (($config ['metaconsole'] == 1) && ($server_name != '')) {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection)) {
ui_print_error_message ("Error connecting to ".$server_name);
}
}
$style = json_decode(io_safe_output($item['style']), true);
$show_in_two_columns = $style['show_in_two_columns'];
$show_in_landscape = $style['show_in_landscape'];
$type = $item['type'];
switch ($type) {
case 'avg_value':
@ -357,6 +367,7 @@ html_print_input_hidden('id_item', $idItem);
html_print_input_text_extended ('agent', agents_get_name ($idAgent), 'text-agent', '', 30, 100, false, '',
array('style' => 'background: url(images/lightning.png) no-repeat right;'))
. '<a href="#" class="tip">&nbsp;<span>' . __("Type at least two characters to search") . '</span></a>';
html_print_input_hidden ('server_name', $server_name);
?>
</td>
</tr>
@ -516,8 +527,13 @@ ui_require_javascript_file('pandora');
if ($enterpriseEnable) {
reporting_enterprise_text_box();
}
//Restore db connection
if ($config ['metaconsole'] == 1) {
metaconsole_restore_db();
}
function print_SLA_list($width, $action, $idItem = null) {
global $config;
?>
<table class="databox" id="sla_list" border="0" cellpadding="4" cellspacing="4" width="95%">
<thead>
@ -548,6 +564,14 @@ function print_SLA_list($width, $action, $idItem = null) {
$itemsSLA = array();
}
foreach ($itemsSLA as $item) {
$server_name = $item ['server_name'];
// Metaconsole db connection
if (($config ['metaconsole'] == 1) && ($server_name != '')) {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection)) {
ui_print_error_message ("Error connecting to ".$server_name);
}
}
$idAgent = db_get_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $item['id_agent_module']));
$nameAgent = agents_get_name ($idAgent);
$nameModule = db_get_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $item['id_agent_module']));
@ -562,6 +586,10 @@ function print_SLA_list($width, $action, $idItem = null) {
<a href="javascript: deleteSLARow(' . $item['id'] . ');">' . html_print_image("images/cross.png", true) . '</a>
</td>
</tr>';
if ($config ['metaconsole'] == 1) {
//Restore db connection
metaconsole_restore_db();
}
}
echo '</tbody>';
?>
@ -579,6 +607,7 @@ function print_SLA_list($width, $action, $idItem = null) {
<tr id="sla_form" style="" class="datos">
<td>
<input id="hidden-id_agent_sla" name="id_agent_sla" value="" type="hidden">
<input id="hidden-server_name" name="server_name" value="" type="hidden">
<input style="background: transparent url(images/lightning.png) no-repeat right;" name="agent_sla" id="text-agent_sla" size="15" maxlength="20" type="text"><a href="#" class="tip">&nbsp;<span>Type at least two characters to search</span></a></td>
<td><select id="id_agent_module_sla" name="id_agente_modulo_sla" disabled="disabled" style="max-width: 180px"><option value="0"><?php echo __('Select an Agent first'); ?></option></select></td>
<td><input name="sla_min" id="text-sla_min" size="10" maxlength="10" type="text"></td>
@ -599,6 +628,7 @@ function print_SLA_list($width, $action, $idItem = null) {
}
function print_General_list($width, $action, $idItem = null) {
global $config;
?>
<table class="databox" id="general_list" border="0" cellpadding="4" cellspacing="4" width="95%">
<thead>
@ -626,6 +656,14 @@ function print_General_list($width, $action, $idItem = null) {
$itemsGeneral = array();
}
foreach ($itemsGeneral as $item) {
$server_name = $item ['server_name'];
// Metaconsole db connection
if (($config ['metaconsole'] == 1) && ($server_name != '')) {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection)) {
ui_print_error_message ("Error connecting to ".$server_name);
}
}
$idAgent = db_get_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $item['id_agent_module']));
$nameAgent = agents_get_name ($idAgent);
$nameModule = db_get_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $item['id_agent_module']));
@ -637,6 +675,10 @@ function print_General_list($width, $action, $idItem = null) {
<a href="javascript: deleteGeneralRow(' . $item['id'] . ');">' . html_print_image("images/cross.png", true) . '</a>
</td>
</tr>';
if ($config ['metaconsole'] == 1) {
//Restore db connection
metaconsole_restore_db();
}
}
echo '</tbody>';
?>
@ -651,6 +693,7 @@ function print_General_list($width, $action, $idItem = null) {
<tr id="general_form" style="" class="datos">
<td>
<input id="hidden-id_agent_general" name="id_agent_general" value="" type="hidden">
<input id="hidden-server_name_general" name="server_name_general" value="" type="hidden">
<input style="background: transparent url(images/lightning.png) no-repeat right;" name="agent_general" id="text-agent_general" size="15" maxlength="20" type="text"><a href="#" class="tip">&nbsp;<span>Type at least two characters to search</span></a></td>
<td><select id="id_agent_module_general" name="id_agente_modulo_general" disabled="disabled" style="max-width: 180px"><option value="0"><?php echo __('Select an Agent first'); ?></option></select></td>
<td style="text-align: center;"><a href="javascript: addGeneralRow();"><?php html_print_image("images/disk.png", false); ?></a></td>
@ -670,9 +713,9 @@ function print_General_list($width, $action, $idItem = null) {
?>
<script>
$(document).ready (function () {
agent_module_autocomplete('#text-agent', '#hidden-id_agent', '#id_agent_module');
agent_module_autocomplete('#text-agent_sla', '#hidden-id_agent_sla', '#id_agent_module_sla');
agent_module_autocomplete('#text-agent_general', '#hidden-id_agent_general', '#id_agent_module_general');
agent_module_autocomplete('#text-agent', '#hidden-id_agent', '#id_agent_module', '#hidden-server_name');
agent_module_autocomplete('#text-agent_sla', '#hidden-id_agent_sla', '#id_agent_module_sla', '#hidden-server_name');
agent_module_autocomplete('#text-agent_general', '#hidden-id_agent_general', '#id_agent_module_general', '#hidden-server_name_general');
chooseType();
chooseSQLquery();
@ -768,6 +811,7 @@ function deleteGeneralRow(id_row) {
function addSLARow() {
var nameAgent = $("input[name=agent_sla]").val();
var idAgent = $("input[name=id_agent_sla]").val();
var serverName = $("input[name=server_name]").val();
var idModule = $("#id_agent_module_sla").val();
var nameModule = $("#id_agent_module_sla :selected").text();
var slaMin = $("input[name=sla_min]").val();
@ -814,6 +858,7 @@ function addSLARow() {
params.push("sla_min=" + slaMin);
params.push("sla_max=" + slaMax);
params.push("sla_limit=" + slaLimit);
params.push("server_name=" + serverName);
params.push("page=include/ajax/reporting.ajax");
jQuery.ajax ({
@ -836,6 +881,7 @@ function addSLARow() {
$(".delete_button", row).attr('href', 'javascript: deleteSLARow(' + data['id'] + ');');
$("#list_sla").append($(row).html());
$("input[name=id_agent_sla]").val('');
$("input[name=server_name]").val('');
$("input[name=agent_sla]").val('');
$("#id_agent_module_sla").empty();
$("#id_agent_module_sla").attr('disabled', 'true');
@ -855,6 +901,7 @@ function addSLARow() {
function addGeneralRow() {
var nameAgent = $("input[name=agent_general]").val();
var idAgent = $("input[name=id_agent_general]").val();
var serverName = $("input[name=server_name_general]").val();
var idModule = $("#id_agent_module_general").val();
var nameModule = $("#id_agent_module_general :selected").text();
@ -893,6 +940,8 @@ function addGeneralRow() {
params.push("add_general=1");
params.push("id=" + $("input[name=id_item]").val());
params.push("id_module=" + idModule);
params.push("server_name_general=" + serverName);
params.push("page=include/ajax/reporting.ajax");
jQuery.ajax ({
data: params.join ("&"),
@ -913,6 +962,7 @@ function addGeneralRow() {
$("#list_general").append($(row).html());
$("input[name=id_agent_general]").val('');
$("input[name=server_name_general]").val('');
$("input[name=agent_general]").val('');
$("#id_agent_module_general").empty();
$("#id_agent_module_general").attr('disabled', 'true');

View File

@ -24,87 +24,99 @@ if (! check_acl ($config['id_user'], 0, "IW")) {
}
include_once($config['homedir'] . "/include/functions_agents.php");
enterprise_include_once ('include/functions_metaconsole.php');
//FORM FILTER
switch ($config['dbtype']){
case "mysql":
case "postgresql":
$rows = db_get_all_rows_sql('
SELECT t5.nombre, t5.id_agente
FROM
(
SELECT t1.*, id_agente
if ($config ['metaconsole'] == 1) {
$agents = array();
$agents = metaconsole_get_report_agents($idReport);
$modules = array();
$modules = metaconsole_get_report_modules($idReport);
$types = array ();
$types = metaconsole_get_report_types($idReport);
}
else {
//FORM FILTER
switch ($config['dbtype']){
case "mysql":
case "postgresql":
$rows = db_get_all_rows_sql('
SELECT t5.nombre, t5.id_agente
FROM
(
SELECT t1.*, id_agente
FROM treport_content AS t1
LEFT JOIN tagente_modulo AS t2
ON t1.id_agent_module = id_agente_modulo
) AS t4
INNER JOIN tagente AS t5
ON (t4.id_agent = t5.id_agente OR t4.id_agente = t5.id_agente)
WHERE t4.id_report = ' . $idReport);
break;
case "oracle":
$rows = db_get_all_rows_sql('
SELECT t5.nombre, t5.id_agente
FROM
(
SELECT t1.*, id_agente
FROM treport_content t1
LEFT JOIN tagente_modulo t2
ON t1.id_agent_module = id_agente_modulo
) t4
INNER JOIN tagente t5
ON (t4.id_agent = t5.id_agente OR t4.id_agente = t5.id_agente)
WHERE t4.id_report = ' . $idReport);
break;
}
if ($rows === false) {
$rows = array();
}
$agents = array();
foreach ($rows as $row) {
$agents[$row['id_agente']] = $row['nombre'];
}
switch ($config['dbtype']){
case "mysql":
case "postgresql":
$rows = db_get_all_rows_sql('
SELECT t1.id_agent_module, t2.nombre
FROM treport_content AS t1
LEFT JOIN tagente_modulo AS t2
ON t1.id_agent_module = id_agente_modulo
) AS t4
INNER JOIN tagente AS t5
ON (t4.id_agent = t5.id_agente OR t4.id_agente = t5.id_agente)
WHERE t4.id_report = ' . $idReport);
break;
case "oracle":
$rows = db_get_all_rows_sql('
SELECT t5.nombre, t5.id_agente
FROM
(
SELECT t1.*, id_agente
INNER JOIN tagente_modulo AS t2
ON t1.id_agent_module = t2.id_agente_modulo
WHERE t1.id_report = ' . $idReport);
break;
case "oracle":
$rows = db_get_all_rows_sql('
SELECT t1.id_agent_module, t2.nombre
FROM treport_content t1
LEFT JOIN tagente_modulo t2
ON t1.id_agent_module = id_agente_modulo
) t4
INNER JOIN tagente t5
ON (t4.id_agent = t5.id_agente OR t4.id_agente = t5.id_agente)
WHERE t4.id_report = ' . $idReport);
break;
}
if ($rows === false) {
$rows = array();
}
INNER JOIN tagente_modulo t2
ON t1.id_agent_module = t2.id_agente_modulo
WHERE t1.id_report = ' . $idReport);
break;
}
if ($rows === false) {
$rows = array();
}
$agents = array();
foreach ($rows as $row) {
$agents[$row['id_agente']] = $row['nombre'];
}
$modules = array();
foreach ($rows as $row) {
$modules[$row['id_agent_module']] = $row['nombre'];
}
switch ($config['dbtype']){
case "mysql":
case "postgresql":
$rows = db_get_all_rows_sql('
SELECT t1.id_agent_module, t2.nombre
FROM treport_content AS t1
INNER JOIN tagente_modulo AS t2
ON t1.id_agent_module = t2.id_agente_modulo
WHERE t1.id_report = ' . $idReport);
break;
case "oracle":
$rows = db_get_all_rows_sql('
SELECT t1.id_agent_module, t2.nombre
FROM treport_content t1
INNER JOIN tagente_modulo t2
ON t1.id_agent_module = t2.id_agente_modulo
WHERE t1.id_report = ' . $idReport);
break;
}
if ($rows === false) {
$rows = array();
}
$rows = db_get_all_rows_sql('
SELECT DISTINCT(type)
FROM treport_content
WHERE id_report = ' . $idReport);
if ($rows === false) {
$rows = array();
}
$modules = array();
foreach ($rows as $row) {
$modules[$row['id_agent_module']] = $row['nombre'];
}
$rows = db_get_all_rows_sql('
SELECT DISTINCT(type)
FROM treport_content
WHERE id_report = ' . $idReport);
if ($rows === false) {
$rows = array();
}
$types = array();
foreach ($rows as $row) {
$types[$row['type']] = get_report_name($row['type']);
$types = array();
foreach ($rows as $row) {
$types[$row['type']] = get_report_name($row['type']);
}
}
$agentFilter = get_parameter('agent_filter', 0);
@ -253,6 +265,15 @@ foreach ($items as $item) {
$row[1] = get_report_name($item['type']);
$server_name = $item ['server_name'];
if (($config ['metaconsole'] == 1) && ($server_name != '')) {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
if ($item['id_agent'] == 0) {
if ($item['id_agent_module'] == '') {
$row[2] = '-';
@ -289,6 +310,10 @@ foreach ($items as $item) {
$table->data[] = $row;
$count++;
//Restore db connection
if (($config ['metaconsole'] == 1) && ($server_name != '') ) {
metaconsole_restore_db();
}
}
ui_pagination ($countItems, 'index.php?sec=greporting&sec2=godmode/reporting/reporting_builder&tab=list_items&action=edit&id_report=' . $idReport . $urlFilter);
html_print_table($table);

View File

@ -197,6 +197,7 @@ switch ($action) {
$values['show_graph'] = get_parameter('combo_graph_options');
$values['id_module_group'] = get_parameter('combo_modulegroup');
$values['id_group'] = get_parameter ('combo_group');
$values['server_name'] = get_parameter ('server_name');
if (($values['type'] == 'sql') OR ($values['type'] == 'sql_graph_hbar')OR ($values['type'] == 'sql_graph_vbar') OR ($values['type'] == 'sql_graph_pie')) {
$values['treport_custom_sql_id'] = get_parameter('id_custom');
@ -275,6 +276,7 @@ switch ($action) {
$values['show_graph'] = get_parameter('combo_graph_options');
$values['id_module_group'] = get_parameter('combo_modulegroup');
$values['id_group'] = get_parameter ('combo_group');
$values['server_name'] = get_parameter ('server_name');
if (($values['type'] == 'sql') OR ($values['type'] == 'sql_graph_hbar')OR ($values['type'] == 'sql_graph_vbar') OR ($values['type'] == 'sql_graph_pie')) {
@ -362,10 +364,13 @@ switch ($action) {
$reportName = $report['name'];
$resultOperationDB = db_process_sql_delete('treport_content_sla_combined', array('id_report_content' => $idItem));
$resultOperationDB2 = db_process_sql_delete('treport_content_item', array('id_report_content' => $idItem));
if ($resultOperationDB !== false) {
$resultOperationDB = db_process_sql_delete('treport_content', array('id_rc' => $idItem));
}
if ($resultOperationDB2 !== false) {
$resultOperationDB2 = db_process_sql_delete('treport_content', array('id_rc' => $idItem));
}
break;
case 'order':
$resultOperationDB = null;

View File

@ -14,6 +14,10 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
global $config;
require_once ('include/functions_agents.php');
include_once ('include/functions_reporting.php');
enterprise_include_once ('include/functions_metaconsole.php');
// Get list of agent + ip
// Params:
@ -23,7 +27,7 @@
// * id_group
$search_agents = (bool) get_parameter ('search_agents');
if ($search_agents) {
if ($search_agents && ($config['metaconsole'] == 0)) {
require_once ('include/functions_agents.php');
@ -62,6 +66,53 @@ if ($search_agents) {
return;
}
elseif ($search_agents && ($config['metaconsole'] == 1)) {
$servers = db_get_all_rows_sql ("SELECT * FROM tmetaconsole_setup");
if (!isset($servers)) {
return;
}
foreach ($servers as $server) {
if (!metaconsole_load_external_db ($server)) {
continue;
}
$id_agent = (int) get_parameter ('id_agent');
$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
$id_group = (int) get_parameter('id_group');
$addedItems = html_entity_decode((string) get_parameter('add'));
$addedItems = json_decode($addedItems);
if ($addedItems != null) {
foreach ($addedItems as $item) {
echo $item . "|\n";
}
}
$filter = array ();
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
break;
case "oracle":
$filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
break;
}
$filter['id_grupo'] = $id_group;
$agents = agents_get_agents ($filter, array ('id_agente','nombre', 'direccion'));
if ($agents === false)
return;
foreach ($agents as $agent) {
echo io_safe_output($agent['nombre']) . " (" . io_safe_output($server['server_name']) . ") " . "|" . io_safe_output($agent['id_agente']) . "|" . io_safe_output($server['server_name']) . "|" . io_safe_output($agent['direccion']) . "|". "\n";
}
//Restore db connection
metaconsole_restore_db();
}
return;
}
?>

View File

@ -63,13 +63,15 @@ if ($add_sla) {
$sla_limit = get_parameter('sla_limit', 0);
$sla_max = get_parameter('sla_max', 0);
$sla_min = get_parameter('sla_min', 0);
$server_name = get_parameter('server_name', '');
$result = db_process_sql_insert('treport_content_sla_combined', array(
'id_report_content' => $id,
'id_agent_module' => $id_module,
'sla_max' => $sla_max,
'sla_min' => $sla_min,
'sla_limit' => $sla_limit));
'sla_limit' => $sla_limit,
'server_name' => $server_name));
if ($result === false) {
$data['correct'] = 0;
@ -85,10 +87,12 @@ if ($add_sla) {
if ($add_general) {
$id_module = get_parameter('id_module', 0);
$server_name = get_parameter('server_name_general', '');
$result = db_process_sql_insert('treport_content_item', array(
'id_report_content' => $id,
'id_agent_module' => $id_module));
'id_agent_module' => $id_module,
'server_name' => $server_name));
if ($result === false) {
$data['correct'] = 0;

View File

@ -32,6 +32,7 @@ include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_events.php");
include_once($config['homedir'] . "/include/functions_alerts.php");
include_once($config['homedir'] . '/include/functions_users.php');
enterprise_include_once ('include/functions_metaconsole.php');
/**
* Get the average value of an agent module in a period of time.
@ -2012,7 +2013,13 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$sizgraph_w = '750';
$sizgraph_h = '230';
}
$server_name = $content ['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
$module_name = db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']);
if ($content['id_agent_module'] != 0) {
@ -2189,6 +2196,13 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$sla_failed = false;
foreach ($slas as $sla) {
$server_name = $sla ['server_name'];
//Metaconsole connection
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
//Get the sla_value in % and store it on $sla_value
$sla_value = reporting_get_agentmodule_sla ($sla['id_agent_module'], $content['period'],
$sla['sla_min'], $sla['sla_max'], $report["datetime"], $content, $content['time_from'],
@ -2242,6 +2256,10 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_push ($table1->data, $data);
}
if ($config ['metaconsole'] == 1) {
//Restore db connection
metaconsole_restore_db();
}
}
$table->colspan[2][0] = 3;
if ($show_graph == 0 || $show_graph == 1) {
@ -2858,10 +2876,8 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
switch ($group_by_agent) {
//0 means not group by agent
case 0:
$sql = sprintf("select a.id_agent_module, b.nombre as agent_name,
c.nombre as module_name from treport_content_item as a, tagente as b,
tagente_modulo as c where a.id_agent_module = c.id_agente_modulo and
c.id_agente = b.id_agente and id_report_content = %d", $content['id_rc']);
$sql = sprintf("select id_agent_module, server_name from treport_content_item
where id_report_content = %d", $content['id_rc']);
$generals = db_process_sql ($sql);
if ($generals === false) {
@ -2884,12 +2900,28 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$data_avg = array();
foreach ($generals as $key => $row) {
//Metaconsole connection
$server_name = $row ['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
$mod_name = modules_get_agentmodule_name ($row['id_agent_module']);
$ag_name = modules_get_agentmodule_agent_name ($row['id_agent_module']);
$data_avg[$key] = reporting_get_agentmodule_data_average ($row['id_agent_module'], $content['period']);
$id_agent_module[$key] = $row['id_agent_module'];
$agent_name[$key] = $row['agent_name'];
$module_name[$key] = $row['module_name'];
$agent_name[$key] = $ag_name;
$module_name[$key] = $mod_name;
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
}
//Order by data descending, ascending or without order
if ($order_uptodown == 0 || $order_uptodown == 1 || $order_uptodown == 2) {
switch ($order_uptodown) {
//Descending
@ -2911,6 +2943,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$i++;
}
}
//Order by agent name
elseif ($order_uptodown == 3) {
array_multisort($agent_name, SORT_ASC, $data_avg, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC);
$i=0;
@ -2931,25 +2964,9 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
break;
//1 means group by agent
case 1:
//Get the list of agents
$sql_agents = sprintf ("select distinct ta.nombre from tagente as ta,
tagente_modulo as tam, treport_content_item as trci
where ta.id_agente = tam.id_agente and tam.id_agente_modulo = trci.id_agent_module
and trci.id_report_content = %d", $content['id_rc']);
$agent_list = db_process_sql ($sql_agents);
//Get the list of modules
$sql_modules = sprintf ("select distinct tam.nombre from tagente_modulo as tam,
treport_content_item as trci where tam.id_agente_modulo = trci.id_agent_module
and trci.id_report_content = %d", $content['id_rc']);
$modules_list = db_process_sql ($sql_modules);
//Get the data
$sql_data = sprintf("select trci.id_agent_module, ta.nombre as agent_name,
tam.nombre as module_name from treport_content_item as trci, tagente as ta,
tagente_modulo as tam where ta.id_agente = tam.id_agente and
tam.id_agente_modulo = trci.id_agent_module
and id_report_content = %d", $content['id_rc']);
$sql_data = sprintf("select id_agent_module, server_name from treport_content_item
where id_report_content = %d", $content['id_rc']);
$generals = db_process_sql ($sql_data);
if ($generals === false) {
@ -2959,6 +2976,33 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_push ($table->data, $data);
break;
}
$agent_list = array();
$modules_list = array();
foreach ($generals as $general) {
//Metaconsole connection
$server_name = $general ['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
$ag_name = modules_get_agentmodule_agent_name ($general ['id_agent_module']);
if (!in_array ($ag_name, $agent_list)) {
array_push ($agent_list, $ag_name);
}
$mod_name = modules_get_agentmodule_name ($general ['id_agent_module']);
if (!in_array ($mod_name, $modules_list)) {
array_push ($modules_list, $mod_name);
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
}
$table2->width = '99%';
$table2->data = array ();
@ -2967,25 +3011,37 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$table2->style[0] = 'text-align: center';
$i = 1;
foreach ($modules_list as $m) {
$table2->head[$i] = ui_print_truncate_text($m['nombre'], 20, false);
$table2->head[$i] = ui_print_truncate_text($m, 20, false);
$table2->style[$i] = 'text-align: center';
$i++;
}
foreach ($agent_list as $a) {
$data = array();
$data[0] = printSmallFont($a['nombre']);
$data[0] = printSmallFont($a);
$i = 1;
foreach ($modules_list as $m) {
foreach ($generals as $g) {
$agent_name = $g['agent_name'];
$module_name = $g['module_name'];
//Metaconsole connection
$server_name = $g ['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection)) {
//ui_print_error_message ("Error connecting to ".$server_name);
}
}
$agent_name = modules_get_agentmodule_agent_name ($g['id_agent_module']);
$module_name = modules_get_agentmodule_name ($g['id_agent_module']);
$found = false;
if (strcmp($a['nombre'], $agent_name) == 0 && strcmp($m['nombre'], $module_name) == 0) {
if (reporting_get_agentmodule_data_average($g['id_agent_module'], $content['period']) === false)
if (strcmp($a, $agent_name) == 0 && strcmp($m, $module_name) == 0) {
$value_avg = reporting_get_agentmodule_data_average($g['id_agent_module'], $content['period']);
if ($value_avg === false) {
$data[$i] = '--';
else {
$data[$i] = reporting_get_agentmodule_data_average($g['id_agent_module'], $content['period']);
} else {
$data[$i] = $value_avg;
}
$found = true;
}
@ -2993,6 +3049,11 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$data[$i] = '--';
}
if ($found == true) break;
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
}
$i++;
}
@ -3011,8 +3072,21 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$min = false;
$i=0;
do {
//Metaconsole connection
$server_name = $generals[$i]['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
$min = reporting_get_agentmodule_data_average($generals[$i]['id_agent_module'], $content['period']);
$i++;
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
} while ($min === false && $i < count($generals));
$max = $min;
$avg = 0;
@ -3023,6 +3097,14 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
}
foreach ($generals as $g) {
//Metaconsole connection
$server_name = $g['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
$value = reporting_get_agentmodule_data_average ($g['id_agent_module'], $content['period']);
if ($value !== false) {
if ($value > $max) {
@ -3034,6 +3116,11 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$avg += $value;
$length++;
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
}
if ($length == 0) {
$avg = 0;
@ -3071,10 +3158,8 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_push ($table->data, $data_desc);
}
//Get all the related data
$sql = sprintf("select a.id_agent_module, b.nombre as agent_name,
c.nombre as module_name from treport_content_item as a, tagente as b,
tagente_modulo as c where a.id_agent_module = c.id_agente_modulo and
c.id_agente = b.id_agente and id_report_content = %d", $content['id_rc']);
$sql = sprintf("select id_agent_module, server_name from treport_content_item
where id_report_content = %d", $content['id_rc']);
$tops = db_process_sql ($sql);
if ($tops === false) {
@ -3098,6 +3183,18 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
}
$data_top = array();
foreach ($tops as $key => $row) {
//Metaconsole connection
$server_name = $row['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
$ag_name = modules_get_agentmodule_agent_name($row ['id_agent_module']);
$mod_name = modules_get_agentmodule_name ($row ['id_agent_module']);
switch ($top_n) {
//Max
case 1:
@ -3113,12 +3210,17 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$value = reporting_get_agentmodule_data_average ($row['id_agent_module'], $content['period']);
break;
}
//If the returned value from modules_get_agentmodule_data... is false it won't be stored.
//If the returned value from modules_get_agentmodule_data_max/min/avg is false it won't be stored.
if ($value !== false) {
$data_top[$key] = $value;
$id_agent_module[$key] = $row['id_agent_module'];
$agent_name[$key] = $row['agent_name'];
$module_name[$key] = $row['module_name'];
$agent_name[$key] = $ag_name;
$module_name[$key] = $mod_name;
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
}
@ -3212,7 +3314,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
if ($show_graph == 1 || $show_graph == 2) {
$data[0] = pie3d_graph($config['flash_charts'], $data_pie_graph,
600, 150, __("other"),"", $config['homedir'] . "/images/logo_vertical_water.png",
$config['fontpath'], $config['font_size']);
$config['fontpath'], $config['font_size']);
array_push ($table->data, $data);
//Display bars graph
@ -3290,10 +3392,8 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_push ($table->data, $data_desc);
}
//Get all the related data
$sql = sprintf("select a.id_agent_module, b.nombre as agent_name,
c.nombre as module_name from treport_content_item as a, tagente as b,
tagente_modulo as c where a.id_agent_module = c.id_agente_modulo and
c.id_agente = b.id_agente and id_report_content = %d", $content['id_rc']);
$sql = sprintf("select id_agent_module, server_name from treport_content_item
where id_report_content = %d", $content['id_rc']);
$exceptions = db_process_sql ($sql);
if ($exceptions === false) {
@ -3319,14 +3419,38 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
//Get the very first not null value
$i=0;
do {
//Metaconsole connection
$server_name = $exceptions[$i]['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
$min = reporting_get_agentmodule_data_average ($exceptions[$i]['id_agent_module'], $content['period']);
$i++;
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
} while ($min === false && $i < count($exceptions));
$max = $min;
$avg = 0;
$i=0;
foreach ($exceptions as $exc) {
//Metaconsole connection
$server_name = $exc['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection))
ui_print_error_message ("Error connecting to ".$server_name);
}
$ag_name = modules_get_agentmodule_agent_name ($exc ['id_agent_module']);
$mod_name = modules_get_agentmodule_name ($exc ['id_agent_module']);
$value = reporting_get_agentmodule_data_average ($exc['id_agent_module'], $content['period']);
if ($value !== false) {
if ($value > $max) $max = $value;
@ -3368,8 +3492,12 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$i++;
$data_exceptions[] = $value;
$id_agent_module[] = $exc['id_agent_module'];
$agent_name[] = $exc['agent_name'];
$module_name[] = $exc['module_name'];
$agent_name[] = $ag_name;
$module_name[] = $mod_name;
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
}
//$i <= 0 means that there are no rows on the table, therefore no modules under the conditions defined.
@ -3402,15 +3530,15 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
$avg = $avg / $i;
switch ($order_uptodown) {
//Descending
//Order descending
case 1:
array_multisort($data_exceptions, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC);
break;
//Ascending
//Order ascending
case 2:
array_multisort($data_exceptions, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC);
break;
//By agent name or without selection
//Order by agent name or without selection
case 0:
case 3:
array_multisort($agent_name, SORT_ASC, $data_exceptions, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC);
@ -3461,7 +3589,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
if ($show_graph == 1 || $show_graph == 2) {
$data[0] = pie3d_graph($config['flash_charts'], $data_graph,
600, 150, __("other"), "", $config['homedir'] . "/images/logo_vertical_water.png",
$config['fontpath'], $config['font_size']);
$config['fontpath'], $config['font_size']);
array_push ($table->data, $data);
//Display bars graph
$table->colspan[4][0] = 3;
@ -3695,6 +3823,10 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
array_push ($table->data, $data);
break;
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '') {
metaconsole_restore_db();
}
}
/**

View File

@ -388,7 +388,7 @@ function agent_changed_by_multiple_agents_id (event, id_agent, selected) {
* @param id_agent_id id of the hidden field to store the agent id
* @param id_agent_module_selector id of the selector for the modules of the agent.
*/
function agent_module_autocomplete (id_agent_name, id_agent_id, id_agent_module_selector, noneValue) {
function agent_module_autocomplete (id_agent_name, id_agent_id, id_agent_module_selector, id_server_name, noneValue) {
$(id_agent_name).autocomplete(
"ajax.php",
{
@ -415,11 +415,14 @@ function agent_module_autocomplete (id_agent_name, id_agent_id, id_agent_module_
function (e, data, formatted) {
$(id_agent_module_selector).attr('disabled', false);
agent_id = data[1];
server_name = data[2];
$(id_server_name).val(server_name);
$(id_agent_id).val(agent_id);
jQuery.post ('ajax.php',
{"page": "operation/agentes/ver_agente",
"get_agent_modules_json": 1,
"id_agent": agent_id,
"server_name": server_name,
"filter" : 'disabled=0 AND delete_pending=0',
"fields" : "id_agente_modulo,nombre"
},

View File

@ -23,10 +23,11 @@ require_once($config['homedir'] . "/include/functions_agents.php");
require_once($config['homedir'] . "/include/functions_groups.php");
require_once($config['homedir'] . "/include/functions_modules.php");
require_once($config['homedir'] . '/include/functions_users.php');
enterprise_include_once ('include/functions_metaconsole.php');
ui_require_javascript_file('openlayers.pandora');
enterprise_include ('operation/agentes/ver_agente.php');
enterprise_include_once ('operation/agentes/ver_agente.php');
check_login ();
@ -142,24 +143,69 @@ if (is_ajax ()) {
$enabled = 'disabled = 0';
break;
}
$nameModules = db_get_all_rows_sql('SELECT DISTINCT(nombre)
FROM tagente_modulo t1
WHERE ' . $enabled . '
AND delete_pending = 0
AND id_agente IN (' . implode(',', $idAgents) . ') AND (
SELECT count(nombre)
FROM tagente_modulo t2
WHERE delete_pending = 0 AND t1.nombre = t2.nombre
AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')');
if ($nameModules == false) {
if ($config ['metaconsole'] == 1) {
$result = array();
$nameModules = array();
$temp = array();
$first = true;
foreach ($idAgents as $idA) {
$row = explode ('|', $idA);
$server_name = $row[0];
$id_agent = $row [1];
//Metaconsole db connection
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection)) {
ui_print_error_message ("Error connecting to ".$server_name);
}
//Get agent's modules
$temp = agents_get_modules ($id_agent);
//Copy only the very first result to $nameModules
if (empty($nameModules) && $first == true) {
$first = false;
$nameModules = $temp;
}
//If there's only one agent selected, get out of this loop
if (count($idAgents) <= 1) {
//Restore db connection
metaconsole_restore_db();
break;
}
$nameModules = array_intersect ($nameModules, $temp);
//Restore db connection
metaconsole_restore_db();
}
foreach ($nameModules as $nameModule) {
$result[] = io_safe_output($nameModule);
}
}
else {
$result = array();
foreach($nameModules as $nameModule) {
$result[] = io_safe_output($nameModule['nombre']);
$nameModules = db_get_all_rows_sql('SELECT DISTINCT(nombre)
FROM tagente_modulo t1
WHERE ' . $enabled . '
AND delete_pending = 0
AND id_agente IN (' . implode(',', $idAgents) . ') AND (
SELECT count(nombre)
FROM tagente_modulo t2
WHERE delete_pending = 0 AND t1.nombre = t2.nombre
AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')');
if ($nameModules == false) {
$nameModules = array();
}
$result = array();
foreach($nameModules as $nameModule) {
$result[] = io_safe_output($nameModule['nombre']);
}
}
echo json_encode($result);
@ -172,6 +218,7 @@ if (is_ajax ()) {
$fields = (string) get_parameter ('fields');
$indexed = (bool) get_parameter ('indexed', true);
$agentName = (string) get_parameter ('agent_name', null);
$server_name = (string) get_parameter ('server_name', null);
if ($agentName != null) {
$search = array();
@ -180,13 +227,31 @@ if (is_ajax ()) {
else
$search = false;
/* Get all agents if no agent was given */
if ($id_agent == 0)
$id_agent = array_keys (agents_get_group_agents (array_keys (users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent,
($fields != '' ? explode (',', $fields) : "*"),
($filter != '' ? $filter : false), $indexed);
if ($config ['metaconsole'] == 1) {
if (enterprise_include_once ('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection)) {
/* Get all agents if no agent was given */
if ($id_agent == 0)
$id_agent = array_keys (agents_get_group_agents (array_keys (users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent,
($fields != '' ? explode (',', $fields) : "*"),
($filter != '' ? $filter : false), $indexed);
}
// Restore db connection
metaconsole_restore_db();
}
}
else {
/* Get all agents if no agent was given */
if ($id_agent == 0)
$id_agent = array_keys (agents_get_group_agents (array_keys (users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent,
($fields != '' ? explode (',', $fields) : "*"),
($filter != '' ? $filter : false), $indexed);
}
foreach($agent_modules as $key => $module) {
$agent_modules[$key]['nombre'] = io_safe_output($module['nombre']);