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

* include/functions_api.php, operation/agentes/alerts_status.php:
	improved the style code.
	
	* include/functions_alerts.php: in function "get_group_alerts" fixed
	the get all alerts, sometimes set empty the return array.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7712 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-02-25 13:21:24 +00:00
parent 83fb4e3e14
commit eb145f1d29
4 changed files with 103 additions and 83 deletions

View File

@ -1,3 +1,11 @@
2013-02-25 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_api.php, operation/agentes/alerts_status.php:
improved the style code.
* include/functions_alerts.php: in function "get_group_alerts" fixed
the get all alerts, sometimes set empty the return array.
2013-02-25 Sergio Martin <sergio.martin@artica.es>
* include/functions_reports.php

View File

@ -1410,14 +1410,18 @@ function get_alert_fires_in_period ($id_alert_module, $period, $date = 0) {
function get_group_alerts ($id_group) {
global $config;
require_once ($config["homedir"].'/include/functions_agents.php');
require_once ($config["homedir"] . '/include/functions_agents.php');
$alerts = array ();
$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);
$alerts = array_merge ($alerts, $agent_alerts);
if (!empty($agent_alerts['simple']))
$alerts['simple'] = array_merge ($alerts['simple'],
$agent_alerts['simple']);
}
return $alerts;
@ -1444,7 +1448,8 @@ function get_alerts_fired ($alerts, $period = 0, $date = 0) {
foreach ($alerts as $alert) {
if (isset($alert['id'])) {
$fires = get_alert_fires_in_period ($alert['id'], $period, $date);
$fires = get_alert_fires_in_period($alert['id'],
$period, $date);
if (! $fires) {
continue;
}

View File

@ -2485,7 +2485,7 @@ function api_set_create_module_template($id, $thrash1, $other, $thrash3) {
return;
}
if ($other['data'][1] == ""){
if ($other['data'][1] == "") {
returnError('error_module_to_template', __('Error assigning module to template. Id_agent cannot be left blank.'));
return;
}
@ -2502,14 +2502,14 @@ function api_set_create_module_template($id, $thrash1, $other, $thrash3) {
$result_agent = agents_get_name($id_agent);
if (!$result_agent){
if (!$result_agent) {
returnError('error_module_to_template', __('Error assigning module to template. Id_agent doesn\'t exists.'));
return;
}
$result_module = db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', (int) $id_module);
if (!$result_module){
if (!$result_module) {
returnError('error_module_to_template', __('Error assigning module to template. Id_module doesn\'t exists.'));
return;
}
@ -2547,7 +2547,7 @@ function api_set_delete_module_template($id, $thrash1, $other, $thrash3) {
$result_module_template = alerts_get_alert_agent_module($id);
if (!$result_module_template){
if (!$result_module_template) {
returnError('error_delete_module_template', __('Error deleting module template. Id_module_template doesn\'t exists.'));
return;
}
@ -2608,14 +2608,14 @@ function api_set_validate_all_alerts($id, $thrash1, $other, $thrash3) {
$agents_string = implode(',', $result_agents);
$sql = sprintf ("SELECT talert_template_modules.id
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)", $agents_string);
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)", $agents_string);
$alerts = db_get_all_rows_sql($sql);
@ -2633,7 +2633,7 @@ function api_set_validate_all_alerts($id, $thrash1, $other, $thrash3) {
$errors = $total_alerts - $count_results;
returnError('error_validate_all_alerts', __('Error validate all alerts. Failed ' . $errors . '.'));
}
else{
else {
returnData('string', array('type' => 'string', 'data' => __('Correct validating of all alerts.')));
}
}
@ -2665,7 +2665,7 @@ function api_set_validate_all_policy_alerts($id, $thrash1, $other, $thrash3) {
$total_alerts = 0;
$count_results = 0;
// Check all policies
foreach ($policies as $policy){
foreach ($policies as $policy) {
$policy_alerts = array();
$policy_alerts = enterprise_hook('policies_get_alerts', array($policy['id'], false, false));
@ -2686,7 +2686,7 @@ function api_set_validate_all_policy_alerts($id, $thrash1, $other, $thrash3) {
$id_pol_alerts = implode(',', $result_pol_alerts);
// If the policy has alerts
if (count($result_pol_alerts) != 0){
if (count($result_pol_alerts) != 0) {
$sql = sprintf ("SELECT id
FROM talert_template_modules
WHERE id_policy_alerts IN (%s)",
@ -2695,7 +2695,7 @@ function api_set_validate_all_policy_alerts($id, $thrash1, $other, $thrash3) {
$id_alerts = db_get_all_rows_sql($sql);
$result_alerts = array();
foreach ($id_alerts as $id_alert){
foreach ($id_alerts as $id_alert) {
$result_alerts[] = $id_alert['id'];
}
@ -2712,7 +2712,7 @@ function api_set_validate_all_policy_alerts($id, $thrash1, $other, $thrash3) {
}
// Check results
if ($total_alerts > $count_results){
if ($total_alerts > $count_results) {
$errors = $total_alerts - $count_results;
returnError('error_validate_all_alerts', __('Error validate all policy alerts. Failed ' . $errors . '.'));
}
@ -2829,12 +2829,12 @@ function api_set_add_agent_policy($id, $thrash1, $other, $thrash3) {
* @param $thrash3 Don't use
*/
function api_set_add_data_module_policy($id, $thrash1, $other, $thrash3) {
if ($id == ""){
if ($id == "") {
returnError('error_add_data_module_policy', __('Error adding data module to policy. Id_policy cannot be left blank.'));
return;
}
if ($other['data'][0] == ""){
if ($other['data'][0] == "") {
returnError('error_add_data_module_policy', __('Error adding data module to policy. Module_name cannot be left blank.'));
return;
}
@ -2864,8 +2864,8 @@ function api_set_add_data_module_policy($id, $thrash1, $other, $thrash3) {
$values['history_data'] = $other['data'][14];
$values['configuration_data'] = $other['data'][15];
if ($name_module_policy !== false){
if ($name_module_policy[0]['name'] == $other['data'][0]){
if ($name_module_policy !== false) {
if ($name_module_policy[0]['name'] == $other['data'][0]) {
returnError('error_add_data_module_policy', __('Error adding data module to policy. The module is already in the policy.'));
return;
}
@ -2899,12 +2899,12 @@ function api_set_add_data_module_policy($id, $thrash1, $other, $thrash3) {
* @param $thrash3 Don't use
*/
function api_set_update_data_module_policy($id, $thrash1, $other, $thrash3) {
if ($id == ""){
if ($id == "") {
returnError('error_update_data_module_policy', __('Error updating data module in policy. Id_policy cannot be left blank.'));
return;
}
if ($other['data'][0] == ""){
if ($other['data'][0] == "") {
returnError('error_update_data_module_policy', __('Error updating data module in policy. Id_policy_module cannot be left blank.'));
return;
}
@ -2917,7 +2917,7 @@ function api_set_update_data_module_policy($id, $thrash1, $other, $thrash3) {
return;
}
if ($module_policy[0]['id_module'] != 1){
if ($module_policy[0]['id_module'] != 1) {
returnError('error_update_network_module_policy', __('Error updating network module in policy. Module type is not network type.'));
return;
}

View File

@ -64,11 +64,12 @@ $idAgent = get_parameter_get('id_agente', 0);
// Show alerts for specific agent
if ($idAgent != 0) {
$url = $url.'&id_agente='.$idAgent;
$url = $url . '&id_agente=' . $idAgent;
$id_group = agents_get_agent_group ($idAgent);
$is_extra = enterprise_hook('policies_is_agent_extra_policy', array($id_agente));
$is_extra = enterprise_hook('policies_is_agent_extra_policy',
array($id_agente));
if($is_extra === ENTERPRISE_NOT_HOOK) {
$is_extra = false;
@ -165,11 +166,13 @@ switch ($sortField) {
switch ($sort) {
case 'up':
$selectModuleUp = $selected;
$order = array('field' => 'agent_module_name', 'order' => 'ASC');
$order = array('field' => 'agent_module_name',
'order' => 'ASC');
break;
case 'down':
$selectModuleDown = $selected;
$order = array('field' => 'agent_module_name', 'order' => 'DESC');
$order = array('field' => 'agent_module_name',
'order' => 'DESC');
break;
}
break;
@ -177,11 +180,13 @@ switch ($sortField) {
switch ($sort) {
case 'up':
$selectTemplateUp = $selected;
$order = array('field' => 'template_name', 'order' => 'ASC');
$order = array('field' => 'template_name',
'order' => 'ASC');
break;
case 'down':
$selectTemplateDown = $selected;
$order = array('field' => 'template_name', 'order' => 'DESC');
$order = array('field' => 'template_name',
'order' => 'DESC');
break;
}
break;
@ -195,7 +200,8 @@ switch ($sortField) {
$selectModuleDown = '';
$selectTemplateUp = '';
$selectTemplateDown = '';
$order = array('field' => 'agent_module_name', 'order' => 'ASC');
$order = array('field' => 'agent_module_name',
'order' => 'ASC');
}
else {
$selectDisabledUp = '';
@ -206,7 +212,8 @@ switch ($sortField) {
$selectModuleDown = '';
$selectTemplateUp = '';
$selectTemplateDown = '';
$order = array('field' => 'agent_module_name', 'order' => 'ASC');
$order = array('field' => 'agent_module_name',
'order' => 'ASC');
}
break;
}