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

* include/functions_agents.php, include/functions_alerts.php,
	operation/agentes/alerts_status.php: improved the function
	"get_group_alerts" to use in the places that there were a foreach
	loop with all agents for any group.
	
	Fixes: #2060




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8641 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-08-08 09:00:34 +00:00
parent a3dad1b227
commit faa29e0c03
4 changed files with 189 additions and 24 deletions

View File

@ -1,3 +1,12 @@
2013-08-08 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_agents.php, include/functions_alerts.php,
operation/agentes/alerts_status.php: improved the function
"get_group_alerts" to use in the places that there were a foreach
loop with all agents for any group.
Fixes: #2060
2013-08-07 Miguel de Dios <miguel.dedios@artica.es>
* godmode/agentes/modificar_agente.php,

View File

@ -218,7 +218,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f
INNER JOIN talert_templates t4
ON talert_template_modules.id_alert_template = t4.id
WHERE id_agent_module in (%s) %s %s %s",
$selectText, $subQuery, $where, $filter, $orderbyText);
$selectText, $subQuery, $where, $filter, $orderbyText);
$alerts = db_get_all_rows_sql ($sql);
if ($alerts === false)

View File

@ -1522,24 +1522,147 @@ function get_alert_fires_in_period ($id_alert_module, $period, $date = 0) {
*
* @return array An array with alerts dictionaries defined in a group.
*/
function get_group_alerts ($id_group) {
function get_group_alerts($id_group, $filter = '', $options = false,
$where = '', $allModules = false, $orderby = false,
$idGroup = false, $count = false) {
global $config;
require_once ($config["homedir"] . '/include/functions_agents.php');
$alerts = array ('simple' => array());
$agents = agents_get_group_agents ($id_group, false, "none");
foreach ($agents as $agent_id => $agent_name) {
$agent_alerts = agents_get_alerts ($agent_id);
if (!empty($agent_alerts['simple']))
$alerts['simple'] = array_merge ($alerts['simple'],
$agent_alerts['simple']);
if (is_array($filter)) {
$disabled = $filter['disabled'];
if (isset($filter['standby'])) {
$filter = ' AND talert_template_modules.standby = "'.$filter['standby'].'"';
}
else {
$filter = '';
}
}
else {
$filter = '';
$disabled = $filter;
}
return $alerts;
switch ($disabled) {
case "notfired":
$filter .= ' AND times_fired = 0 AND talert_template_modules.disabled = 0';
break;
case "fired":
$filter .= ' AND times_fired > 0 AND talert_template_modules.disabled = 0';
break;
case "disabled":
$filter .= ' AND talert_template_modules.disabled = 1';
break;
case "all_enabled":
$filter .= ' AND talert_template_modules.disabled = 0';
break;
default:
$filter .= '';
break;
}
if (is_array ($options)) {
$filter .= db_format_array_where_clause_sql ($options);
}
if ($id_group !== false) {
$where_tags = tags_get_acl_tags($config['id_user'],
$idGroup, 'AR', 'module_condition', 'AND', 'tagente_modulo');
if ($id_group != 0) {
if (is_array($id_group)) {
if (in_array(0, $id_group)) {
$id_group = 0;
}
}
if (is_array($id_group)) {
if (empty($id_group)) {
$subQuery = 'SELECT id_agente_modulo
FROM tagente_modulo
WHERE 1 = 0';
}
else {
$subQuery = 'SELECT id_agente_modulo
FROM tagente_modulo
WHERE delete_pending = 0
AND id_agente IN (SELECT id_agente
FROM tagente
WHERE
id_grupo IN (' . implode(',', $id_group) . '))';
}
}
else {
$subQuery = 'SELECT id_agente_modulo
FROM tagente_modulo
WHERE delete_pending = 0
AND id_agente IN (SELECT id_agente
FROM tagente WHERE id_grupo = ' . $idGroup . ')';
}
}
else {
//ALL GROUP
$subQuery = 'SELECT id_agente_modulo
FROM tagente_modulo WHERE delete_pending = 0';
}
// If there are any errors add imposible condition
if (in_array($where_tags, array(ERR_WRONG_PARAMETERS, ERR_ACL))) {
$subQuery .= ' AND 1 = 0';
}
else {
$subQuery .= $where_tags;
}
}
else {
if ($allModules)
$disabled = '';
else
$disabled = 'WHERE disabled = 0';
$subQuery = 'SELECT id_agente_modulo
FROM tagente_modulo ' . $disabled;
}
$orderbyText = '';
if ($orderby !== false) {
if (is_array($orderby)) {
$orderbyText = sprintf("ORDER BY %s", $orderby['field'], $orderby['order']);
}
else {
$orderbyText = sprintf("ORDER BY %s", $orderby);
}
}
$selectText = 'talert_template_modules.*, t2.nombre AS agent_module_name, t3.nombre AS agent_name, t4.name AS template_name';
if ($count !== false) {
$selectText = 'COUNT(talert_template_modules.id) AS count';
}
$sql = sprintf ("SELECT %s
FROM talert_template_modules
INNER JOIN tagente_modulo t2
ON talert_template_modules.id_agent_module = t2.id_agente_modulo
INNER JOIN tagente t3
ON t2.id_agente = t3.id_agente
INNER JOIN talert_templates t4
ON talert_template_modules.id_alert_template = t4.id
WHERE id_agent_module in (%s) %s %s %s",
$selectText, $subQuery, $where, $filter, $orderbyText);
$alerts = db_get_all_rows_sql ($sql);
if ($alerts === false)
return array ();
if ($count !== false) {
return $alerts[0]['count'];
}
else {
return $alerts;
}
}
/**

View File

@ -76,7 +76,7 @@ if ($idAgent != 0) {
$is_extra = enterprise_hook('policies_is_agent_extra_policy',
array($id_agente));
if($is_extra === ENTERPRISE_NOT_HOOK) {
if ($is_extra === ENTERPRISE_NOT_HOOK) {
$is_extra = false;
}
@ -86,7 +86,6 @@ if ($idAgent != 0) {
exit;
}
$agents = array($idAgent);
$idGroup = false;
$print_agent = false;
@ -276,18 +275,52 @@ else {
if (defined('METACONSOLE')) {
require_once ($config['homedir'] . '/enterprise/meta/include/functions_alerts_meta.php');
$alerts['alerts_simple'] = alerts_meta_get_alerts ($agents,
$filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup);
if ($idAgent != 0) {
$alerts['alerts_simple'] = alerts_meta_get_alerts ($agents,
$filter_alert, $options_simple, $whereAlertSimple, false, false,
$idGroup);
$countAlertsSimple = alerts_meta_get_alerts ($agents, $filter_alert,
false, $whereAlertSimple, false, false, $idGroup, true);
}
else {
$id_groups = array_keys(
users_get_groups($config["id_user"], 'AR', false));
$alerts['alerts_simple'] = alerts_meta_get_group_alerts($id_groups,
$filter_alert, $options_simple, $whereAlertSimple, false,
false, $idGroup);
$countAlertsSimple = alerts_meta_get_group_alerts($id_groups,
$filter_alert, false, $whereAlertSimple, false, false,
$idGroup, true);
}
}
else {
$alerts['alerts_simple'] = agents_get_alerts_simple ($agents,
$filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup);
if ($idAgent != 0) {
$alerts['alerts_simple'] = agents_get_alerts_simple ($idAgent,
$filter_alert, $options_simple, $whereAlertSimple, false, false,
$idGroup);
$countAlertsSimple = agents_get_alerts_simple ($idAgent,
$filter_alert, false, $whereAlertSimple, false, false,
$idGroup, true);
}
else {
$id_groups = array_keys(
users_get_groups($config["id_user"], 'AR', false));
$alerts['alerts_simple'] = get_group_alerts($id_groups,
$filter_alert, $options_simple, $whereAlertSimple, false,
false, $idGroup);
$countAlertsSimple = get_group_alerts($id_groups,
$filter_alert, false, $whereAlertSimple, false, false,
$idGroup, true);
}
}
$countAlertsSimple = agents_get_alerts_simple ($agents, $filter_alert,
false, $whereAlertSimple, false, false, $idGroup, true);
if ($tab != null) {
$url = $url.'&tab='.$tab;
}