2012-07-20 Juan Manuel Ramon <juanmanuel.ramon@artica.es>

* include/db/mysql.php
	 include/functions_groups.php
	 include/functions_agents.php: Added functions to count global 
	 elements (groups or agents), counting disabled elements too. 



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6796 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
juanmanuelr 2012-07-20 12:07:16 +00:00
parent 7daecf4533
commit 64ef168466
4 changed files with 86 additions and 7 deletions

View File

@ -1,3 +1,10 @@
2012-07-20 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* include/db/mysql.php
include/functions_groups.php
include/functions_agents.php: Added functions to count global
elements (groups or agents), counting disabled elements too.
2012-07-20 Hirofumi Kosaka <kosaka@rworks.jp>
* index.php: bug fix: 'Enforce https' led to wrong URL to

View File

@ -1046,4 +1046,5 @@ function mysql_db_get_table_count($sql, $search_history_db = false) {
return $count;
}
?>

View File

@ -1882,9 +1882,14 @@ function agents_get_count_incidents ($id_agent) {
return db_get_value('count(*)', 'tincidencia', 'id_agent', $id_agent);
}
// Get critical monitors by using the status code in modules.
/**
* Get critical monitors by using the status code in modules.
*
* @param int The agent id
* @param string Additional filters
*
* @return mixed The incidents attached or false
*/
function agents_monitor_critical ($id_agent, $filter="") {
if ($filter) {
@ -1927,6 +1932,34 @@ function agents_monitor_ok ($id_agent, $filter="") {
return db_get_sql ("SELECT COUNT( DISTINCT tagente_modulo.id_agente_modulo) 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 = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_agente = $id_agent".$filter);
}
/**
* Get all monitors of an specific agent.
*
* @param int The agent id
* @param string Additional filters
* @param bool Whether to retrieve disabled modules or not
*
* @return mixed Total module count or false
*/
function agents_monitor_total ($id_agent, $filter = '', $disabled = false) {
if ($filter) {
$filter = " AND ".$filter;
}
$sql = "SELECT COUNT( DISTINCT tagente_modulo.id_agente_modulo)
FROM tagente_estado, tagente, tagente_modulo
WHERE " . //tagente_estado.utimestamp != 0 AND
"tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_estado.id_agente = tagente.id_agente
AND tagente.id_agente = $id_agent".$filter;
if (!$disabled)
$sql .= " AND tagente.disabled = 0 AND tagente_modulo.disabled = 0";
return db_get_sql ($sql);
}
//Get alert fired for this agent
function agents_get_alerts_fired ($id_agent, $filter="") {

View File

@ -1248,9 +1248,16 @@ function groups_monitor_fired_alerts ($group_array) {
}
// Total agents in a group, except disabled ones
function groups_total_agents ($group_array) {
/**
* Total agents in a group, (by default except disabled ones)
*
* @param mixed Array or (comma separated) string with groups
* @param bool Whether to count disabled agents
*
* @return mixed Return group count or false if something goes wrong
*
*/
function groups_total_agents ($group_array, $disabled = false) {
if (empty ($group_array)) {
return 0;
@ -1262,7 +1269,38 @@ function groups_total_agents ($group_array) {
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE id_grupo IN $group_clause AND disabled = 0");
$sql = "SELECT COUNT(*) FROM tagente WHERE id_grupo IN $group_clause";
if (!$disabled)
$sql .= " AND disabled = 0";
html_debug_print($sql, "/tmp/pp");
return db_get_sql ($sql);
}
/**
* Number of disabled agents in a group
*
* @param mixed Array or (comma separated) string with groups
*
* @return mixed Return group count or false if something goes wrong
*
*/
function groups_agent_disabled ($group_array) {
if (empty ($group_array)) {
return 0;
} else if (!is_array ($group_array)){
$group_array = array($group_array);
}
$group_clause = implode (",", $group_array);
$group_clause = "(" . $group_clause . ")";
$sql = "SELECT COUNT(*) FROM tagente WHERE id_grupo IN $group_clause AND disabled = 1";
return db_get_sql ($sql);
}