mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
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:
parent
79e2024ad0
commit
92605f13c8
@ -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>
|
2013-08-07 Miguel de Dios <miguel.dedios@artica.es>
|
||||||
|
|
||||||
* godmode/agentes/modificar_agente.php,
|
* godmode/agentes/modificar_agente.php,
|
||||||
|
@ -218,7 +218,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f
|
|||||||
INNER JOIN talert_templates t4
|
INNER JOIN talert_templates t4
|
||||||
ON talert_template_modules.id_alert_template = t4.id
|
ON talert_template_modules.id_alert_template = t4.id
|
||||||
WHERE id_agent_module in (%s) %s %s %s",
|
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);
|
$alerts = db_get_all_rows_sql ($sql);
|
||||||
|
|
||||||
if ($alerts === false)
|
if ($alerts === false)
|
||||||
|
@ -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.
|
* @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;
|
global $config;
|
||||||
|
|
||||||
require_once ($config["homedir"] . '/include/functions_agents.php');
|
|
||||||
|
|
||||||
$alerts = array ('simple' => array());
|
if (is_array($filter)) {
|
||||||
$agents = agents_get_group_agents ($id_group, false, "none");
|
$disabled = $filter['disabled'];
|
||||||
|
if (isset($filter['standby'])) {
|
||||||
foreach ($agents as $agent_id => $agent_name) {
|
$filter = ' AND talert_template_modules.standby = "'.$filter['standby'].'"';
|
||||||
$agent_alerts = agents_get_alerts ($agent_id);
|
}
|
||||||
|
else {
|
||||||
|
$filter = '';
|
||||||
if (!empty($agent_alerts['simple']))
|
}
|
||||||
$alerts['simple'] = array_merge ($alerts['simple'],
|
}
|
||||||
$agent_alerts['simple']);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +76,7 @@ if ($idAgent != 0) {
|
|||||||
$is_extra = enterprise_hook('policies_is_agent_extra_policy',
|
$is_extra = enterprise_hook('policies_is_agent_extra_policy',
|
||||||
array($id_agente));
|
array($id_agente));
|
||||||
|
|
||||||
if($is_extra === ENTERPRISE_NOT_HOOK) {
|
if ($is_extra === ENTERPRISE_NOT_HOOK) {
|
||||||
$is_extra = false;
|
$is_extra = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,6 @@ if ($idAgent != 0) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$agents = array($idAgent);
|
|
||||||
$idGroup = false;
|
$idGroup = false;
|
||||||
|
|
||||||
$print_agent = false;
|
$print_agent = false;
|
||||||
@ -276,18 +275,52 @@ else {
|
|||||||
|
|
||||||
if (defined('METACONSOLE')) {
|
if (defined('METACONSOLE')) {
|
||||||
require_once ($config['homedir'] . '/enterprise/meta/include/functions_alerts_meta.php');
|
require_once ($config['homedir'] . '/enterprise/meta/include/functions_alerts_meta.php');
|
||||||
|
if ($idAgent != 0) {
|
||||||
$alerts['alerts_simple'] = alerts_meta_get_alerts ($agents,
|
$alerts['alerts_simple'] = alerts_meta_get_alerts ($agents,
|
||||||
$filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup);
|
$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 {
|
else {
|
||||||
$alerts['alerts_simple'] = agents_get_alerts_simple ($agents,
|
if ($idAgent != 0) {
|
||||||
$filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup);
|
$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) {
|
if ($tab != null) {
|
||||||
$url = $url.'&tab='.$tab;
|
$url = $url.'&tab='.$tab;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user