2012-06-07 Dario Rodriguez <dario.rodriguez@artica.es>

* include/functions_os.php: Created this file.
        include/functions_groups,
        operation/tree.php: Fixed a bug related to search
        improved performance of OS tab for tree view.

	MERGED FROM 4.0.2



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6441 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
darode 2012-06-07 11:44:08 +00:00
parent 0a8d926336
commit a3d94759dd
4 changed files with 129 additions and 61 deletions

View File

@ -1,3 +1,12 @@
2012-06-07 Dario Rodriguez <dario.rodriguez@artica.es>
* include/functions_os.php: Created this file.
include/functions_groups,
operation/tree.php: Fixed a bug related to search
improved performance of OS tab for tree view.
MERGED FROM 4.0.2
2012-06-07 Hirofumi Kosaka <kosaka@rworks.jp>
* include/functions_ui.php: Merged from 4.0.x: Fixed bug:

View File

@ -852,6 +852,8 @@ function groups_agent_unknown ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT( DISTINCT tagente_estado.id_agente) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 3 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_grupo IN $group_clause");
}
@ -877,6 +879,8 @@ function groups_agent_ok ($group_array) {
//If MAX(estado) is 0 it means all modules has status 0 => OK
//Then we count the agents of the group selected to know how many agents are in OK status
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(max_estado) FROM (SELECT MAX(tagente_estado.estado) as max_estado FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_grupo IN $group_clause GROUP BY tagente.id_agente HAVING max_estado = 0) AS S1");
}
@ -901,6 +905,8 @@ function groups_agent_critical ($group_array) {
//If estado = 1 it means at leas 1 module is in critical status so the agent is critical
//Then we count the agents of the group selected to know how many agents are in critical status
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT( DISTINCT tagente_estado.id_agente) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 1 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_grupo IN $group_clause");
}
@ -926,6 +932,8 @@ function groups_agent_warning ($group_array) {
//If MIN(estado) is 2 it means at least one module is warning and there is no critical modules
//Then we count the agents of the group selected to know how many agents are in warning status
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(min_estado) FROM (SELECT MIN(tagente_estado.estado) as min_estado FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_grupo IN $group_clause GROUP BY tagente.id_agente HAVING min_estado = 2) AS S1");
}
@ -947,6 +955,8 @@ function groups_monitor_not_init ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado)
FROM tagente_estado, tagente, tagente_modulo
WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0
@ -973,6 +983,8 @@ function groups_monitor_ok ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado)
FROM tagente_estado, tagente, tagente_modulo
WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0
@ -996,6 +1008,8 @@ function groups_monitor_critical ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado)
FROM tagente_estado, tagente, tagente_modulo
WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0
@ -1020,6 +1034,8 @@ function groups_monitor_warning ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado)
FROM tagente_estado, tagente, tagente_modulo
WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0
@ -1044,6 +1060,8 @@ function groups_monitor_unknown ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado)
FROM tagente_estado, tagente, tagente_modulo
WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0
@ -1068,6 +1086,8 @@ function groups_monitor_alerts ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(talert_template_modules.id)
FROM talert_template_modules, tagente_modulo, tagente_estado, tagente
WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente
@ -1094,6 +1114,8 @@ function groups_monitor_fired_alerts ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(talert_template_modules.id)
FROM talert_template_modules, tagente_modulo, tagente_estado, tagente
WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente

View File

@ -0,0 +1,69 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2011 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 Lesser 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.
// Get critical agents by using the status code in modules.
function os_agents_critical ($id_os) {
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT( DISTINCT tagente_estado.id_agente) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 1 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_os = $id_os");
}
// Get ok agents by using the status code in modules.
function os_agents_ok($id_os) {
//!!!Query explanation!!!
//An agent is OK if all its modules are OK
//The status values are: 0 OK; 1 Critical; 2 Warning; 3 Unkown
//This query grouped all modules by agents and select the MAX value for status which has the value 0
//If MAX(estado) is 0 it means all modules has status 0 => OK
//Then we count the agents of the group selected to know how many agents are in OK status
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(max_estado) FROM (SELECT MAX(tagente_estado.estado) as max_estado FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_os = $id_os GROUP BY tagente.id_agente HAVING max_estado = 0) AS S1");
}
// Get warning agents by using the status code in modules.
function os_agents_warning ($id_os) {
//!!!Query explanation!!!
//An agent is Warning when has at least one module in warning status and nothing more in critical status
//The status values are: 0 OK; 1 Critical; 2 Warning; 3 Unkown
//This query grouped all modules by agents and select the MIN value for status which has the value 0
//If MIN(estado) is 2 it means at least one module is warning and there is no critical modules
//Then we count the agents of the group selected to know how many agents are in warning status
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(min_estado) FROM (SELECT MIN(tagente_estado.estado) as min_estado FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_os = $id_os GROUP BY tagente.id_agente HAVING min_estado = 2) AS S1");
}
// Get unknown agents by using the status code in modules.
function os_agents_unknown ($id_os) {
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT( DISTINCT tagente_estado.id_agente) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 3 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_os = $id_os");
}
?>

View File

@ -248,7 +248,7 @@ if (is_ajax ())
$groups_sql = implode(', ', $avariableGroupsIds);
if ($search_free != '') {
$search_sql = " AND nombre LIKE '%$search_free%'";
$search_sql = " AND nombre COLLATE utf8_general_ci LIKE '%$search_free%'";
} else {
$search_sql = '';
}
@ -289,7 +289,7 @@ if (is_ajax ())
WHERE id_agente IN (
SELECT id_agente
FROM tagente_modulo
WHERE nombre LIKE \'%s\'
WHERE nombre COLLATE utf8_general_ci LIKE \'%s\'
)
AND (%s id_grupo IN (%s))', $name, $extra_sql, $groups_sql);
break;
@ -321,6 +321,7 @@ if (is_ajax ())
$count++;
switch ($type) {
case 'group':
case 'os':
$agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"]);
$agent_info["monitor_critical"] = agents_monitor_critical ($row["id_agente"]);
@ -336,11 +337,6 @@ if (is_ajax ())
//Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
break;
case 'os':
$agent_info = reporting_get_agent_module_info ($row["id_agente"]);
break;
case 'module_group':
$agent_info = reporting_get_agent_module_info ($row["id_agente"], ' id_module_group = ' . $id);
@ -355,11 +351,11 @@ if (is_ajax ())
case 'module':
switch ($config["dbtype"]) {
case "mysql":
$agent_info = reporting_get_agent_module_info ($row["id_agente"], ' nombre LIKE "' . $name . '"');
$agent_info = reporting_get_agent_module_info ($row["id_agente"], ' nombre COLLATE utf8_general_ci LIKE "' . $name . '"');
break;
case "postgresql":
case "oracle":
$agent_info = reporting_get_agent_module_info ($row["id_agente"], ' nombre LIKE \'' . $name . '\'');
$agent_info = reporting_get_agent_module_info ($row["id_agente"], ' nombre COLLATE utf8_general_ci LIKE \'' . $name . '\'');
break;
}
break;
@ -487,14 +483,14 @@ if (is_ajax ())
$sql = 'SELECT *
FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id . ' AND nombre LIKE \'' . io_safe_input($name) . '\'';
WHERE t1.id_agente = ' . $id . ' AND nombre COLLATE utf8_general_ci LIKE \'' . io_safe_input($name) . '\'';
break;
case "postgresql":
case "oracle":
$sql = 'SELECT *
FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id . ' AND nombre LIKE \'' . io_safe_input($name) . '\'';
WHERE t1.id_agente = ' . $id . ' AND nombre COLLATE utf8_general_ciLIKE \'' . io_safe_input($name) . '\'';
break;
}
break;
@ -635,6 +631,7 @@ if (is_ajax ())
include_once($config['homedir'] . "/include/functions_groups.php");
include_once($config['homedir'] . "/include/functions_os.php");
include_once($config['homedir'] . "/include/functions_servers.php");
include_once($config['homedir'] . "/include/functions_reporting.php");
include_once($config['homedir'] . "/include/functions_ui.php");
@ -674,10 +671,10 @@ function printTree_($type) {
if ($search_free != '') {
$sql = "SELECT * FROM tconfig_os
WHERE id_os IN (SELECT id_os FROM tagente
WHERE nombre LIKE '%$search_free%')";
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
$list = db_get_all_rows_sql($sql);
} else {
$list = db_get_all_rows_in_table('tconfig_os', 'name');
$list = db_get_all_rows_sql("SELECT DISTINCT (tagente.id_os), tconfig_os.name FROM tagente, tconfig_os WHERE tagente.id_os = tconfig_os.id_os");
}
break;
case 'group':
@ -690,7 +687,7 @@ function printTree_($type) {
);
if ($search_free != '') {
$sql_search = " AND id_grupo IN (SELECT id_grupo FROM tagente
WHERE nombre LIKE '%$search_free%')";
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
} else {
$sql_search ='';
}
@ -709,7 +706,7 @@ function printTree_($type) {
$sql = "SELECT * FROM tmodule_group
WHERE id_mg IN (SELECT id_module_group FROM tagente_modulo
WHERE id_agente IN (SELECT id_agente FROM tagente
WHERE nombre LIKE '%$search_free%'))";
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%'))";
$list = db_get_all_rows_sql($sql);
} else {
$list = db_get_all_rows_in_table('tmodule_group', 'name');
@ -725,7 +722,7 @@ function printTree_($type) {
WHERE id_group IN ($groups)
AND id IN (SELECT id_policy FROM tpolicy_agents
WHERE id_agent IN (SELECT id_agente FROM tagente
WHERE nombre LIKE '%$search_free%'))";
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%'))";
$list = db_get_all_rows_sql($sql);
} else {
$list = db_get_all_rows_filter('tpolicies', array('id_group' => array_keys($avariableGroups)));
@ -736,7 +733,7 @@ function printTree_($type) {
case 'module':
if ($search_free != '') {
$sql_search = " AND t1.id_agente IN (SELECT id_agente FROM tagente
WHERE nombre LIKE '%$search_free%')";
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
} else {
$sql_search ='';
}
@ -774,34 +771,10 @@ function printTree_($type) {
$id = $item['id_os'];
$name = $item['name'];
$iconImg = html_print_image(str_replace('.png' ,'_small.png', ui_print_os_icon ($item['id_os'], false, true, false)) . " ", true);
$agentes = db_get_all_rows_sql("SELECT id_agente FROM tagente WHERE id_os=$id");
if ($agentes === false) {
$agentes = array();
}
$num_ok = 0;
$num_critical = 0;
$num_warning = 0;
$num_unknown = 0;
foreach ($agentes as $agente) {
$stat = reporting_get_agent_module_info ($agente["id_agente"]);
switch ($stat['status']) {
case 'agent_ok.png':
$num_ok++;
break;
case 'agent_critical.png':
$num_critical++;
break;
case 'agent_warning.png':
$num_warning++;
break;
case 'agent_down.png':
$num_unknown++;
break;
}
}
$num_ok = os_agents_ok($id);
$num_critical = os_agents_critical($id);
$num_warning = os_agents_warning($id);
$num_unknown = os_agents_unknown($id);
break;
case 'group':
$id = $item['id_grupo'];
@ -882,7 +855,7 @@ function printTree_($type) {
$name_sql = io_safe_input($item['nombre']);
$agentes = db_get_all_rows_sql("SELECT id_agente FROM tagente
WHERE id_agente IN (SELECT id_agente FROM tagente_modulo
WHERE nombre LIKE '$name_sql')");
WHERE nombre COLLATE utf8_general_ci LIKE '%$name_sql%')");
if ($agentes === false) {
$agentes = array();
}
@ -932,21 +905,16 @@ function printTree_($type) {
}
}
//skip if there is a empty OS or group!
if (($type == 'os' || $type == 'group') && ($num_ok == 0) && ($num_critical == 0) && ($num_warning == 0) && ($num_unknown == 0)) {
continue;
} else {
echo "<li style='margin: 0px 0px 0px 0px;'>
<a onfocus='JavaScript: this.blur()' href='javascript: loadSubTree(\"" . $type . "\",\"" . $id . "\", " . $lessBranchs . ", \"\")'>" .
$img . $iconImg ."&nbsp;" . __($name) . ' ('.
'<span class="green">'.'<b>'.$num_ok.'</b>'.'</span>'.
' : <span class="red">'.$num_critical.'</span>' .
' : <span class="yellow">'.$num_warning.'</span>'.
' : <span class="grey">'.$num_unknown.'</span>'.') '. "</a>";
echo "<div hiddenDiv='1' loadDiv='0' style='margin: 0px; padding: 0px;' class='tree_view' id='tree_div_" . $type . "_" . $id . "'></div>";
echo "</li>\n";
}
echo "<li style='margin: 0px 0px 0px 0px;'>
<a onfocus='JavaScript: this.blur()' href='javascript: loadSubTree(\"" . $type . "\",\"" . $id . "\", " . $lessBranchs . ", \"\")'>" .
$img . $iconImg ."&nbsp;" . __($name) . ' ('.
'<span class="green">'.'<b>'.$num_ok.'</b>'.'</span>'.
' : <span class="red">'.$num_critical.'</span>' .
' : <span class="yellow">'.$num_warning.'</span>'.
' : <span class="grey">'.$num_unknown.'</span>'.') '. "</a>";
echo "<div hiddenDiv='1' loadDiv='0' style='margin: 0px; padding: 0px;' class='tree_view' id='tree_div_" . $type . "_" . $id . "'></div>";
echo "</li>\n";
}
echo "</ul>\n";
echo '</td>';