2013-01-10 Juan Manuel Ramon <juanmanuel.ramon@artica.es>

* include/functions_agents.php
	 include/functions_treeview.php
	 extensions/net_tools.php
	 extensions/module_groups.php
	 operation/agentes/status_monitor.php
	 operation/agentes/sla_view.php
	 operation/messages/message_list.php
	 godmode/agentes/fields_manager.php
	 godmode/alerts/alert_list.builder.php
	 godmode/massive/massive_delete_agents.php
	 godmode/massive/massive_edit_agents.php
	 godmode/massive/massive_delete_modules.php
	 godmode/massive/massive_delete_alerts.php
	 godmode/massive/massive_edit_modules.php: Merged fixes from 
	 branches.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7414 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
juanmanuelr 2013-01-10 12:18:13 +00:00
parent 2280aa6f06
commit b715cc4618
15 changed files with 204 additions and 68 deletions

View File

@ -1,3 +1,21 @@
2013-01-10 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* include/functions_agents.php
include/functions_treeview.php
extensions/net_tools.php
extensions/module_groups.php
operation/agentes/status_monitor.php
operation/agentes/sla_view.php
operation/messages/message_list.php
godmode/agentes/fields_manager.php
godmode/alerts/alert_list.builder.php
godmode/massive/massive_delete_agents.php
godmode/massive/massive_edit_agents.php
godmode/massive/massive_delete_modules.php
godmode/massive/massive_delete_alerts.php
godmode/massive/massive_edit_modules.php: Merged fixes from
branches.
2012-01-09 Sancho Lerena <slerena@artica.es>
* godmode/setup/setup.php: Fixed warning on enabling EACL.

View File

@ -130,9 +130,9 @@ function mainModuleGroups() {
//The big query
switch ($config["dbtype"]) {
case "mysql":
$sql = "SELECT COUNT(id_agente) AS count, estado
$sql = "SELECT COUNT(id_agente) AS count, case utimestamp when 0 then 5 else estado end as estado
FROM tagente_estado
WHERE utimestamp != 0 AND id_agente IN
WHERE id_agente IN
(SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled IS FALSE)
AND id_agente_modulo IN
(SELECT id_agente_modulo
@ -141,9 +141,9 @@ function mainModuleGroups() {
GROUP BY estado";
break;
case "postgresql":
$sql = "SELECT COUNT(id_agente) AS count, estado
$sql = "SELECT COUNT(id_agente) AS count, case utimestamp when 0 then 5 else estado end as estado
FROM tagente_estado
WHERE utimestamp != 0 AND id_agente IN
WHERE id_agente IN
(SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled = 0)
AND id_agente_modulo IN
(SELECT id_agente_modulo
@ -152,9 +152,9 @@ function mainModuleGroups() {
GROUP BY estado";
break;
case "oracle":
$sql = "SELECT COUNT(id_agente) AS count, estado
$sql = "SELECT COUNT(id_agente) AS count, case when utimestamp = 0 then 5 else estado end estado
FROM tagente_estado
WHERE utimestamp != 0 AND id_agente IN
WHERE id_agente IN
(SELECT id_agente FROM tagente WHERE id_grupo = %d AND (disabled IS NOT NULL AND disabled <> 0))
AND id_agente_modulo IN
(SELECT id_agente_modulo
@ -258,6 +258,9 @@ function mainModuleGroups() {
elseif (array_key_exists(0, $states)) {
$color = '#8ae234'; //Green when the cell for this model group and agent has OK state all modules.
}
elseif (array_key_exists(5, $states)) {
$color = '#729fcf'; // Blue when the cell for this module group and all modules have not init value.
}
$alinkStart = '<a class="info_cell" rel="ajax.php?page=extensions/module_groups&get_info_alert_module_group=1&module_group=' . $idModelGroup . '&id_agent_group=' . $idAgentGroup . '"
@ -303,6 +306,10 @@ function mainModuleGroups() {
<div style="float: left; background: #babdb6; height: 20px; width: 80px;margin-right: 5px; margin-bottom: 5px;">&nbsp;</div>' .
__("Grey cell when the module group and agent have at least one in unknown status and the others in green status") .
'</li>' .
'<li style="clear: both;">
<div style="float: left; background: #729fcf; height: 20px; width: 80px;margin-right: 5px; margin-bottom: 5px;">&nbsp;</div>' .
__("Blue cell when the module group and agent have all modules in not init status.") .
'</li>' .
"</ul>" .
"</p>";
}

View File

@ -43,7 +43,7 @@ function main_net_tools () {
$id_agente = get_parameter ("id_agente");
$ip = db_get_sql ("SELECT direccion FROM tagente WHERE id_agente = $id_agente");
if ($ip == "") {
echo "<h3 class=error>The agent hasn't got IP</h3>";
echo "<div class='error' style='margin-top:5px'>The agent hasn't got IP</div>";
return;
}
echo "<div>";

View File

@ -99,7 +99,7 @@ else {
echo '<div class="nf">'. __('No fields defined') .'</div>';
}
if($fields === false) $fields = array();
if ($fields === false) $fields = array();
foreach ($fields as $field) {

View File

@ -42,6 +42,12 @@ $table->size[1] = '80%';
$table->style[0] = 'font-weight: bold; vertical-align: top;';
$table->align[0] = 'left';
$table->align[1] = 'left';
// This is because if this view is reused after list alert view then
// styles in the previous view can affect this table.
$table->rowstyle[0] = '';
$table->rowstyle[1] = '';
$table->rowstyle[2] = '';
$table->rowstyle[3] = '';
/* Add an agent selector */

View File

@ -30,7 +30,7 @@ require_once ('include/functions_users.php');
function process_manage_delete ($id_agents) {
if (empty ($id_agents)) {
echo '<h3 class="error">'.__('No agents selected').'</h3>';
ui_print_error_message(__('No agents selected'));
return false;
}
@ -42,21 +42,28 @@ function process_manage_delete ($id_agents) {
db_process_sql_begin ();
$error = false;
$count_deleted = 0;
$agent_id_restore = 0;
foreach ($id_agents as $id_agent) {
$success = agents_delete_agent ($id_agent);
if (! $success)
if (! $success) {
$agent_id_restore = $id_agent;
break;
}
$count_deleted++;
}
if (! $success) {
echo '<h3 class="error">'.__('There was an error deleting the agent, the operation has been cancelled').'</h3>';
echo '<h4>'.__('Could not delete agent').' '.agents_get_name ($id_agent).'</h4>';
ui_print_error_message(__('There was an error deleting the agent, the operation has been cancelled') . '.&nbsp;' . __('Could not delete agent').' '.agents_get_name ($agent_id_restore));
//echo '<h3 class="error">'.__('There was an error deleting the agent, the operation has been cancelled').'</h3>';
//echo '<h4>'.__('Could not delete agent').' '.agents_get_name ($id_agent).'</h4>';
db_process_sql_rollback ();
return false;
}
else {
echo '<h3 class="suc">'.__('Successfully deleted').'</h3>';
ui_print_success_message(__('Successfully deleted') . '&nbsp;(' . $count_deleted . ')');
db_process_sql_commit ();
return true;

View File

@ -61,24 +61,52 @@ if (is_ajax ()) {
function process_manage_delete ($id_alert_template, $id_agents, $module_names) {
if (empty ($id_alert_template)) {
echo '<h3 class="error">'.__('No alert selected').'</h3>';
ui_print_error_message(__('No alert selected'));
return false;
}
if (empty ($id_agents) || $id_agents[0] == 0) {
echo '<h3 class="error">'.__('No agents selected').'</h3>';
ui_print_error_message(__('No agents selected'));
return false;
}
$module_selection_mode = get_parameter('modules_selection_mode');
foreach($module_names as $module){
foreach($id_agents as $id_agent) {
$module_id = modules_get_agentmodule_id($module, $id_agent);
$modules_id[] = $module_id['id_agente_modulo'];
}
}
if(count($module_names) == 1 && $module_names[0] == '0'){
$modules_id = agents_common_modules_with_alerts ($id_agents, false, true);
// If is selected "ANY" option then we need the module selection mode: common or all modules
if (count($module_names) == 1 && $module_names[0] == '0') {
if ($module_selection_mode == 'common')
$modules_id = agents_common_modules_with_alerts ($id_agents, false, true);
else {
// For agents selected
$modules_id = array();
foreach ($id_agents as $id_agent) {
$current_modules_agent = agents_get_modules($id_agent, 'id_agente_modulo', array ('disabled' => 0));
if ($current_modules_agent != false) {
// And their modules
foreach ($current_modules_agent as $current_module) {
$module_alerts = alerts_get_alerts_agent_module($current_module);
if ($module_alerts != false) {
// And for all alert in modules
foreach ($module_alerts as $module_alert) {
// Find the template in module
if ($module_alert['id_alert_template'] == $id_alert_template)
$modules_id[] = $module_alert['id_agent_module'];
}
}
}
}
}
}
}
$conttotal = 0;

View File

@ -50,12 +50,12 @@ if (is_ajax ()) {
function process_manage_delete ($module_name, $id_agents) {
if (empty ($module_name)) {
echo '<h3 class="error">'.__('No module selected').'</h3>';
ui_print_error_message(__('No module selected'));
return false;
}
if (empty ($id_agents)) {
echo '<h3 class="error">'.__('No agents selected').'</h3>';
ui_print_error_message(__('No agents selected'));
return false;
}
@ -63,19 +63,40 @@ function process_manage_delete ($module_name, $id_agents) {
$module_name = (array)$module_name;
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
sprintf('nombre IN ("%s")', implode('","',$module_name)), true);
// We are selecting "any" agent for the selected modules
if (($id_agents[0] == 0) and (is_array($id_agents)) and (count($id_agents) == 1))
$id_agents = NULL;
$selection_delete_mode = get_parameter('selection_mode', 'modules');
// Selection mode by Agents
if ($selection_delete_mode == 'agents') {
// We are selecting "any" module for the selecteds agents
if (($module_name[0] == 0) and (is_array($module_name)) and (count($module_name) == 1))
$filter_for_module_deletion = false;
else
$filter_for_module_deletion = sprintf('nombre IN ("%s")', implode('","',$module_name));
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
$filter_for_module_deletion, true);
}
else {
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
sprintf('nombre IN ("%s")', implode('","',$module_name)), true);
}
$count_deleted_modules = count($modules);
$success = modules_delete_agent_module ($modules);
if (! $success) {
echo '<h3 class="error">'.__('There was an error deleting the modules, the operation has been cancelled').'</h3>';
echo '<h4>'.__('Could not delete modules').'</h4>';
ui_print_error_message(__('There was an error deleting the modules, the operation has been cancelled'));
db_process_sql_rollback ();
return false;
}
else {
echo '<h3 class="suc">'.__('Successfully deleted').'</h3>';
ui_print_success_message(__('Successfully deleted') . '&nbsp;(' . $count_deleted_modules . ')');
db_process_sql_commit ();
return true;
@ -128,11 +149,11 @@ if ($delete) {
$agents_ = db_get_all_rows_sql('SELECT DISTINCT(t1.id_agente)
FROM tagente t1, tagente_modulo t2
WHERE t1.id_agente = t2.id_agente');
foreach ($agents_ as $id_agent) {
$module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent, 'id_tipo_modulo' => $module_type),'nombre');
if ($module_name == false) {
WHERE t1.id_agente = t2.id_agente AND t2.delete_pending = 0 ' . $condition);
foreach($agents_ as $id_agent) {
$module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent['id_agente'], 'id_tipo_modulo' => $module_type, 'delete_pending' => 0),'nombre');
if($module_name == false) {
$module_name = array();
}
foreach ($module_name as $mod_name) {
@ -149,11 +170,10 @@ if ($delete) {
if($module_name == false) {
$module_name = array();
}
foreach($module_name as $mod_name) {
$result = process_manage_delete ($mod_name['nombre'], $id_agent);
$count ++;
$success += (int)$result;
else {
$result = process_manage_delete (array(0 => 0), $id_agent);
}
$success += (int)$result;
}
}
@ -161,7 +181,9 @@ if ($delete) {
$agents_ = array();
}
$result = process_manage_delete ($modules_, $agents_);
if (!$force)
$result = process_manage_delete ($modules_, $agents_);
if ($result) {
db_pandora_audit("Massive management", "Delete module ", false, false,
'Agent: ' . json_encode($agents_) . ' Module: ' . $module_name);

View File

@ -352,8 +352,8 @@ $table->data[4][1] = html_print_select($arraySelectIcon, "icon_path", $icon_path
if ($config['activate_gis']) {
$table->data[5][0] = __('Ignore new GIS data:');
$table->data[5][1] = __('No change').' '.html_print_radio_button_extended ("update_gis_data", -1, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true);
$table->data[5][1] .= __('Disabled').' '.html_print_radio_button_extended ("update_gis_data", 0, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true);
$table->data[5][1] .= __('Active').' '.html_print_radio_button_extended ("update_gis_data", 1, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true);
$table->data[5][1] .= __('Disabled').' '.html_print_radio_button_extended ("update_gis_data", 1, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true);
$table->data[5][1] .= __('Active').' '.html_print_radio_button_extended ("update_gis_data", 0, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true);
}
$table->data[6][0] = __('Quiet');

View File

@ -80,11 +80,11 @@ if ($update) {
$agents_ = db_get_all_rows_sql('SELECT DISTINCT(t1.id_agente)
FROM tagente t1, tagente_modulo t2
WHERE t1.id_agente = t2.id_agente');
foreach ($agents_ as $id_agent) {
$module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent, 'id_tipo_modulo' => $module_type),'nombre');
if ($module_name == false) {
WHERE t1.id_agente = t2.id_agente AND t2.delete_pending = 0 ' . $condition);
foreach($agents_ as $id_agent) {
$module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent, 'id_tipo_modulo' => $module_type, 'delete_pending' => 0),'nombre');
if($module_name == false) {
$module_name = array();
}
foreach ($module_name as $mod_name) {
@ -321,7 +321,10 @@ $table->data['edit4'][1] .= html_print_input_text ('min', '', '', 5, 15, true);
$table->data['edit4'][1] .= '<br /><em>'.__('Max.').'</em>';
$table->data['edit4'][1] .= html_print_input_text ('max', '', '', 5, 15, true);
$table->data['edit4'][2] = __('Module group');
$module_groups = array_merge(array(0 => 'Not assigned'), modules_get_modulegroups());
// Create module groups values for select
$module_groups = modules_get_modulegroups();
$module_groups[0] = __('Not assigned');
$table->data['edit4'][3] = html_print_select ($module_groups,
'id_module_group', '', '', __('No change'), '', true, false, false);
@ -583,10 +586,13 @@ $(document).ready (function () {
<?php
function process_manage_edit ($module_name, $agents_select = null) {
if (is_int ($module_name) && $module_name < 0) {
echo '<h3 class="error">'.__('No modules selected').'</h3>';
ui_print_error_message(__('No modules selected'));
return false;
}
if (!is_array($agents_select))
$agents_select = array($agents_select);
/* List of fields which can be updated */
$fields = array ('min_warning', 'max_warning', 'str_warning', 'min_critical', 'max_critical', 'str_critical', 'min_ff_event', 'module_interval',
@ -620,6 +626,11 @@ function process_manage_edit ($module_name, $agents_select = null) {
if (get_parameter('quiet_select', -1) != -1) {
$values['quiet'] = get_parameter('quiet_select');
}
$filter_modules = false;
if (!is_numeric($module_name) or ($module_name != 0))
$filter_modules['nombre'] = $module_name;
// Whether to update module tag info
$update_tags = get_parameter('id_tag', false);
@ -627,7 +638,7 @@ function process_manage_edit ($module_name, $agents_select = null) {
if (array_search(0, $agents_select) !== false) {
//Apply at All agents.
$modules = db_get_all_rows_filter ('tagente_modulo',
array ('nombre' => $module_name),
$filter_modules,
array ('id_agente_modulo'));
}
else {

View File

@ -782,16 +782,8 @@ function agents_get_next_contact($idAgent, $maxModules = false) {
*/
function agents_common_modules_with_alerts ($id_agent, $filter = false, $indexed = true, $get_not_init_modules = true) {
$id_agent = safe_int ($id_agent, 1);
$where = '';
if (! empty ($id_agent)) {
$where = sprintf (' WHERE t2.id_agent_module = t1.id_agente_modulo AND delete_pending = 0
AND id_agente IN (%s) AND (
SELECT count(nombre)
FROM tagente_modulo t3, talert_template_modules t4
WHERE t4.id_agent_module = t3.id_agente_modulo AND delete_pending = 0
AND t1.nombre = t3.nombre AND id_agente IN (%s)) = (%s)', implode (",", (array) $id_agent), implode (",", (array) $id_agent), count($id_agent));
}
if (! empty ($filter)) {
$where .= ' AND ';
@ -804,14 +796,59 @@ function agents_common_modules_with_alerts ($id_agent, $filter = false, $indexed
} else {
$where .= $filter;
}
}
}
$sql = sprintf ('SELECT DISTINCT(t1.id_agente_modulo)
FROM tagente_modulo t1, talert_template_modules t2
%s
ORDER BY nombre',
$where);
$result = db_get_all_rows_sql ($sql);
if (! empty ($id_agent)) {
// Get module_name-template repetitions over agents selected
// Group by if there is more than one agent
$group_by = '';
if (count((array)$id_agent) > 1)
$group_by = 'having count(*) > 1';
$sql = sprintf ('SELECT t1.nombre, t2.id_alert_template, count(*)
FROM tagente_modulo t1, talert_template_modules t2
WHERE t2.id_agent_module = t1.id_agente_modulo
AND delete_pending = 0
AND id_agente IN (%s) %s group by nombre, id_alert_template %s'
, implode (",", (array) $id_agent)
, $where
,$group_by);
$result_tmp = db_get_all_rows_sql ($sql);
$result = array();
if ($result_tmp != false) {
foreach ($result_tmp as $module_template) {
$sql_modules = sprintf ('SELECT t1.id_agente_modulo
FROM tagente_modulo t1, talert_template_modules t2
WHERE t1.id_agente_modulo = t2.id_agent_module
AND delete_pending = 0
AND t1.nombre = \'%s\' AND t2.id_alert_template = %s'
, $module_template['nombre']
, $module_template['id_alert_template']);
$id_modules_template = db_get_all_rows_sql ($sql_modules);
if ($id_modules_template != false)
foreach ($id_modules_template as $id_module_template)
$result[] = $id_module_template;
}
}
}
else {
$sql = sprintf ('SELECT DISTINCT(t1.id_agente_modulo)
FROM tagente_modulo t1, talert_template_modules t2
%s
ORDER BY nombre',
$where);
$result = db_get_all_rows_sql ($sql);
}
if (empty ($result)) {
return array ();

View File

@ -277,7 +277,7 @@ function treeview_printTree($type) {
}
if ($list === false) {
ui_print_error_message("There aren't agents in this agrupation");
echo '<h3 class="error">'.__('There aren\'t agents in this agrupation').'</h3>';
echo '</td></tr>';
echo '</table>';
}
@ -423,6 +423,7 @@ function treeview_getData ($type, $server=false) {
// If there are not groups display error and return
if (empty($avariableGroups)) {
echo '<h3 class="error">'.__('There aren\'t agents in this agrupation').'</h3>';
return array ();
}
}

View File

@ -43,7 +43,7 @@ $offset = get_parameter ("offset", 0);
// Get all module from agent
ui_pagination (count ($modules), "index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=sla&id_agente=".$id_agent, $offset);
ui_pagination (count ($modules), "index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=sla&id_agente=".$id_agent);
$table->width = '95%';
$table->cellpadding = 4;
@ -115,7 +115,7 @@ $sql = "SELECT id_agent_module, sla_max, sla_min, sla_limit
WHERE id_agent_module IN (".implode (",",array_keys ($modules)).")";
$result = db_get_all_rows_sql ($sql);
if ($result !== false) {
echo "<h3>".__('User-defined SLA items')." - ".human_time_description_raw ($config["sla_period"])."</h3>";
echo "<h4>".__('User-defined SLA items')." - ".human_time_description_raw ($config["sla_period"])."</h4>";
$table->width = '95%';
$table->cellpadding = 4;
$table->cellspacing = 4;

View File

@ -1035,8 +1035,7 @@ if (!empty ($table->data)) {
html_print_table ($table);
}
else {
ui_print_error_message(
__('This group doesn\'t have any monitor') );
echo "<div class='nf'>".__('This group doesn\'t have any monitor')."</div>";
}
?>
<script type="text/javascript">

View File

@ -214,7 +214,7 @@ else {
}
echo '<form method="post" action="index.php?sec=workspace&sec2=operation/messages/message_edit">';
echo '<div class="action-buttons" style="width: 98%;">';
echo '<div class="action-buttons" style="width: 98%; margin-top: 5px;">';
html_print_submit_button (__('Create message'), 'create', false, 'class="sub next"');
echo "</div>";
echo "</form>";