diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index cafd60fb55..70ca34f050 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,42 @@ +2009-02-18 Esteban Sanchez + + * godmode/agentes/alert_manager.php: Removed from repository. Agent + alerts manager is now done in alerts/alert_list.php + + * godmode/agentes/manage_config.php, godmode/alerts/configure_alert, + godmode/agentes/configurar_agente.php: Use alerts/alert_list.php + instead of deleted agentes/alert_manager.php. + + * godmode/alerts/alert_list.php: It can handle now a list of agents or + be included by configurar_agente. Now it's a single page to manage all + the alerts defined in agents. + + * godmode/reporting/map_builder.php: Javascript style correction. + + * include/javascript/jquery.pandora.controls.js: Added + pandoraSelectAgent which allows the loading of a module list from an + agent list. + + * include/styles/pandora.css: Styles for alert_list. + + * include/functions_agents.php: Added options to + get_agent_alerts_compound() and get_agent_alerts_simple() to add extra + user filtering. + + * pandoradb.sql, pandoradb_migrate_20_to_21.sql, + include/functions_alerts.php: Actions in an alert module has now id or + they cannot be removed. + + * include/functions_db.php: format_array_to_where_clause_sql() can now + get limit and offset values. + + * include/functions_html.php: Removed select- prefix to print_select + elements because it was breaking javascript code. Needs more works on + that. + + * operation/agentes/estado_agente.php: Added + get_agent_module_last_value AJAX operation. + 2009-02-17 Evi Vanoost * general/login_ok.php, operation/visual_console/index.php, diff --git a/pandora_console/godmode/agentes/alert_manager.php b/pandora_console/godmode/agentes/alert_manager.php deleted file mode 100644 index b16a65aec8..0000000000 --- a/pandora_console/godmode/agentes/alert_manager.php +++ /dev/null @@ -1,454 +0,0 @@ -".__('Agent configuration')." > ".__('Alerts').""; - -$create_alert = (bool) get_parameter ('create_alert'); -$add_action = (bool) get_parameter ('add_action'); -$delete_action = (bool) get_parameter ('delete_action'); -$delete_alert = (bool) get_parameter ('delete_alert'); -$disable_alert = (bool) get_parameter ('disable_alert'); -$enable_alert = (bool) get_parameter ('enable_alert'); - -if ($create_alert) { - $id_alert_template = (int) get_parameter ('template'); - $id_agent_module = (int) get_parameter ('id_agent_module'); - - $id = create_alert_agent_module ($id_agent_module, $id_alert_template); - print_error_message ($id, __('Successfully created'), - __('Could not be created')); - if ($id !== false) { - $id_alert_action = (int) get_parameter ('action'); - $fires_min = (int) get_parameter ('fires_min'); - $fires_max = (int) get_parameter ('fires_max'); - $values = array (); - if ($fires_min != -1) - $values['fires_min'] = $fires_min; - if ($fires_max != -1) - $values['fires_max'] = $fires_max; - - add_alert_agent_module_action ($id, $id_alert_action, $values); - } -} - -if ($delete_alert) { - $id_alert_agent_module = (int) get_parameter ('id_alert'); - - $result = delete_alert_agent_module ($id_alert_agent_module); - print_error_message ($id, __('Successfully deleted'), - __('Could not be deleted')); -} - -if ($add_action) { - $id_action = (int) get_parameter ('action'); - $id_alert_module = (int) get_parameter ('id_alert_module'); - $fires_min = (int) get_parameter ('fires_min'); - $fires_max = (int) get_parameter ('fires_max'); - $values = array (); - if ($fires_min != -1) - $values['fires_min'] = $fires_min; - if ($fires_max != -1) - $values['fires_max'] = $fires_max; - - $result = add_alert_agent_module_action ($id_alert_module, $id_action, $values); - print_error_message ($id, __('Successfully added'), - __('Could not be added')); -} - -if ($delete_action) { - $id_action = (int) get_parameter ('id_action'); - $id_alert = (int) get_parameter ('id_alert'); - - $result = delete_alert_agent_module_action ($id_alert, $id_action); - print_error_message ($id, __('Successfully deleted'), - __('Could not be deleted')); -} - -if ($enable_alert) { - $id_alert = (int) get_parameter ('id_alert'); - - $result = set_alerts_agent_module_disable ($id_alert, false); - print_error_message ($id, __('Successfully enabled'), - __('Could not be enabled')); -} - -if ($disable_alert) { - $id_alert = (int) get_parameter ('id_alert'); - - $result = set_alerts_agent_module_disable ($id_alert, true); - print_error_message ($id, __('Successfully disabled'), - __('Could not be disabled')); -} - -$modules = get_agent_modules ($id_agente, - array ('id_tipo_modulo', 'nombre', 'id_agente')); - -echo "

".__('Alerts defined')."

"; - -$table->class = 'databox_color modules'; -$table->cellspacing = '0'; -$table->width = '90%'; -$table->data = array (); -$table->rowstyle = array (); -$table->style = array (); -$table->style[1] = 'vertical-align: top'; - -$table_alerts->class = 'listing'; -$table_alerts->width = '100%'; -$table_alerts->size = array (); -$table_alerts->size[0] = '50%'; -$table_alerts->size[1] = '50%'; -$table_alerts->style = array (); -$table_alerts->style[0] = 'vertical-align: top'; -$table_alerts->style[1] = 'vertical-align: top'; - -foreach ($modules as $id_agent_module => $module) { - $last_data = get_agent_module_last_value ($id_agent_module); - if ($last_data === false) - $last_data = ''.__('N/A').''; - - $table->data[0][0] = 'Module: '.$module['nombre'].''; - $table->data[0][0] .= ''; - $table->data[0][0] .= ''; - - - /* Alerts in module list */ - $table_alerts->id = 'alerts-'.$id_agent_module; - $table_alerts->data = array (); - - $alerts = get_alerts_agent_module ($id_agent_module, true); - if ($alerts === false) { - $alerts = array (); - $table->data[1][0] = ''; - $table->rowstyle[1] = 'display: none'; - } else { - $table->data[1][0] = '

'; - $table->data[1][0] .= __('Alerts assigned'); - $table->data[1][0] .= '

'; - $table->rowstyle[1] = ''; - } - - foreach ($alerts as $alert) { - $alert_data = array (); - - $alert_actions = get_alert_agent_module_actions ($alert['id']); - - $alert_data[0] = get_alert_template_name ($alert['id_alert_template']); - - if (empty ($alert_actions)) { - $alert_data[0] .= ''; - } else { - $alert_data[0] .= '
'; - if ($alert['disabled']) { - $alert_data[0] .= print_input_image ('enable', 'images/lightbulb_off.png', 1, '', true); - $alert_data[0] .= print_input_hidden ('enable_alert', 1, true); - } else { - $alert_data[0] .= print_input_image ('disable', 'images/lightbulb.png', 1, '', true); - $alert_data[0] .= print_input_hidden ('disable_alert', 1, true); - } - $alert_data[0] .= print_input_hidden ('id_alert', $alert['id'], true); - $alert_data[0] .= '
'; - } - - $alert_data[0] .= ''; - - $alert_data[1] = ''; - - $alert_data[1] .= ''; - - $table_alerts->data['alert-'.$alert['id']] = $alert_data; - } - - $table->data[1][0] .= print_table ($table_alerts, true); - - print_table ($table); - $table->data = array (); -} - -/* This hidden value is used in Javascript. It's a workaraound for IE because - it doesn't allow input elements creation. */ -print_input_hidden ('add_action', 1); -print_input_hidden ('id_alert_module', 0); - -echo ''; -$config['jquery'][] = 'cluetip'; -$config['css'][] = 'cluetip'; -?> - diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 5dd5a7204b..f4e81cf375 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -585,7 +585,8 @@ switch ($tab) { } break; case "alert": - require ("alert_manager.php"); + /* Because $id_agente is set, it will show only agent alerts */ + require ("godmode/alerts/alert_list.php"); break; case "template": require ("agent_template.php"); diff --git a/pandora_console/godmode/agentes/manage_config.php b/pandora_console/godmode/agentes/manage_config.php index 512ab602d2..491660e3d7 100644 --- a/pandora_console/godmode/agentes/manage_config.php +++ b/pandora_console/godmode/agentes/manage_config.php @@ -288,7 +288,7 @@ $(document).ready (function () { /* Get alerts */ jQuery.post ("ajax.php", - {"page" : "godmode/agentes/alert_manager", + {"page" : "godmode/alerts/alert_list", "get_agent_alerts_simple" : 1, "id_agent" : id_agent }, diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index dbdb4514ba..c4a83fbbdc 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -17,7 +17,80 @@ check_login (); -if (! give_acl ($config['id_user'], 0, "LM")) { +if (defined ('AJAX')) { + $get_agent_alerts_simple = (bool) get_parameter ('get_agent_alerts_simple'); + $disable_alert = (bool) get_parameter ('disable_alert'); + $enable_alert = (bool) get_parameter ('enable_alert'); + + if ($get_agent_alerts_simple) { + $id_agent = (int) get_parameter ('id_agent'); + if ($id_agent <= 0) { + echo json_encode (false); + return; + } + $id_group = get_agent_group ($id_agent); + + if (! give_acl ($config['id_user'], $id_group, "AR")) { + audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", + "Trying to access Alert Management"); + echo json_encode (false); + return; + } + + require_once ('include/functions_agents.php'); + require_once ('include/functions_alerts.php'); + + $alerts = get_agent_alerts_simple ($id_agent); + if (empty ($alerts)) { + echo json_encode (false); + return; + } + + $retval = array (); + foreach ($alerts as $alert) { + $alert['template'] = get_alert_template ($alert['id_alert_template']); + $alert['module_name'] = get_agentmodule_name ($alert['id_agent_module']); + $alert['agent_name'] = get_agentmodule_agent_name ($alert['id_agent_module']); + $retval[$alert['id']] = $alert; + } + + echo json_encode ($retval); + return; + } + + if ($enable_alert) { + $id_alert = (int) get_parameter ('id_alert'); + + $result = set_alerts_agent_module_disable ($id_alert, false); + if ($result) + echo __('Successfully enabled'); + else + echo __('Could not be enabled'); + return; + } + + if ($disable_alert) { + $id_alert = (int) get_parameter ('id_alert'); + + $result = set_alerts_agent_module_disable ($id_alert, true); + if ($result) + echo __('Successfully disabled'); + else + echo __('Could not be disabled'); + return; + } + return; +} + +$id_group = 0; +/* Check if this page is included from a agent edition */ +if (isset ($id_agente)) { + $id_group = get_agent_group ($id_agente); +} else { + $id_agente = 0; +} + +if (! give_acl ($config['id_user'], $id_group, "LM")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access Alert Management"); require ("general/noaccess.php"); @@ -27,112 +100,329 @@ if (! give_acl ($config['id_user'], 0, "LM")) { require_once ('include/functions_agents.php'); require_once ('include/functions_alerts.php'); - +$create_alert = (bool) get_parameter ('create_alert'); +$add_action = (bool) get_parameter ('add_action'); +$delete_action = (bool) get_parameter ('delete_action'); +$delete_alert = (bool) get_parameter ('delete_alert'); $disable_alert = (bool) get_parameter ('disable_alert'); $enable_alert = (bool) get_parameter ('enable_alert'); +if ($create_alert) { + $id_alert_template = (int) get_parameter ('template'); + $id_agent_module = (int) get_parameter ('id_agent_module'); + + $id = create_alert_agent_module ($id_agent_module, $id_alert_template); + print_error_message ($id, __('Successfully created'), + __('Could not be created')); + if ($id !== false) { + $actions = (array) get_parameter ('actions'); + $fires_min = (array) get_parameter ('fires_min'); + $fires_max = (array) get_parameter ('fires_max'); + + foreach ($actions as $id_action) { + $values = array (); + if (isset ($fires_min[$id_action])) + $values['fires_min'] = max ($fires_min[$id_action], 0); + if ($fires_max != -1) + $values['fires_max'] = max ($fires_max[$id_action], 0); + add_alert_agent_module_action ($id, $id_action, $values); + } + } +} + +if ($delete_alert) { + $id_alert_agent_module = (int) get_parameter ('id_alert'); + + $result = delete_alert_agent_module ($id_alert_agent_module); + print_error_message ($id, __('Successfully deleted'), + __('Could not be deleted')); +} + +if ($add_action) { + $id_action = (int) get_parameter ('action'); + $id_alert_module = (int) get_parameter ('id_alert_module'); + $fires_min = (int) get_parameter ('fires_min'); + $fires_max = (int) get_parameter ('fires_max'); + $values = array (); + if ($fires_min != -1) + $values['fires_min'] = $fires_min; + if ($fires_max != -1) + $values['fires_max'] = $fires_max; + + $result = add_alert_agent_module_action ($id_alert_module, $id_action, $values); + print_error_message ($id, __('Successfully added'), + __('Could not be added')); +} + +if ($delete_action) { + $id_action = (int) get_parameter ('id_action'); + $id_alert = (int) get_parameter ('id_alert'); + + $result = delete_alert_agent_module_action ($id_action); + print_error_message ($id, __('Successfully deleted'), + __('Could not be deleted')); +} + if ($enable_alert) { $id_alert = (int) get_parameter ('id_alert'); $result = set_alerts_agent_module_disable ($id_alert, false); - print_error_message ($id, __('Successfully enabled'), + print_error_message ($result, __('Successfully enabled'), __('Could not be enabled')); - if (defined ('AJAX')) - return; } if ($disable_alert) { $id_alert = (int) get_parameter ('id_alert'); $result = set_alerts_agent_module_disable ($id_alert, true); - print_error_message ($id, __('Successfully disabled'), + print_error_message ($result, __('Successfully disabled'), __('Could not be disabled')); - if (defined ('AJAX')) - return; } -echo '

'.__('Alerts').'

'; - -$groups = get_user_groups (); -$agents = get_group_agents (array_keys ($groups), false, "none"); - -$simple_alerts = array (); -$compound_alerts = array (); - -foreach ($agents as $agent_id => $agent_name) { - $agent_alerts = get_agent_alerts_simple ($agent_id); - if (! empty ($agent_alerts)) - $simple_alerts[$agent_id] = $agent_alerts; - - $compound_alerts = get_agent_alerts_compound ($agent_id); - if (! empty ($agent_alerts)) - $compound_alerts[$agent_id] = $compound_alerts; +if ($id_agente) { + echo '

'.__('Agent configuration').' > '.__('Alerts').'

'; + $agents = array ($id_agente => get_agent_name ($id_agente)); +} else { + echo '

'.__('Alerts').'

'; + $groups = get_user_groups (); + $agents = get_group_agents (array_keys ($groups), false, "none"); } -foreach ($simple_alerts as $agent_id => $alerts) { - if (empty ($alerts)) - continue; + +if ($id_agente) { + $simple_alerts = get_agent_alerts_simple (array_keys ($agents)); +} else { + $sql = sprintf ('SELECT COUNT(*) FROM talert_template_modules + WHERE id_agent_module IN (SELECT id_agente_modulo + FROM tagente_modulo WHERE id_agente IN (%s))', + implode (',', array_keys ($agents))); + $total = get_db_sql ($sql); - echo '

'.get_agent_name ($agent_id).' - '.__('Alerts defined').'

'; - - $table->class = 'alert_list'; - $table->width = '90%'; - $table->data = array (); - $table->head = array (); - $table->head[0] = ''; - $table->head[1] = __('Module'); - $table->head[2] = __('Template'); - $table->head[3] = __('Actions'); - $table->size = array (); + pagination ($total, 'index.php?sec=gagente&sec2=godmode/alerts/alert_list'); + $simple_alerts = get_agent_alerts_simple (array_keys ($agents), '', + array ('offset' => (int) get_parameter ('offset'), + 'limit' => $config['block_size'])); +} + +$table->class = 'alert_list'; +$table->width = '90%'; +$table->size = array (); +$table->head = array (); +$table->head[0] = ''; +if (! $id_agente) { + $table->style = array (); + $table->style[1] = 'font-weight: bold'; + $table->head[1] = __('Agent'); $table->size[0] = '20px'; + $table->size[1] = '15%'; + $table->size[2] = '20%'; + $table->size[3] = '15%'; + $table->size[4] = '50%'; +} else { + /* Different sizes or the layout screws up */ + $table->size[0] = '20px'; + $table->size[2] = '30%'; + $table->size[3] = '20%'; + $table->size[4] = '50%'; +} +$table->head[2] = __('Module'); +$table->head[3] = __('Template'); +$table->head[4] = __('Actions'); +$table->data = array (); + +foreach ($simple_alerts as $alert) { + $data = array (); - foreach ($alerts as $alert) { - $data = array (); - - $data[0] = '
'; - if ($alert['disabled']) { - $data[0] .= print_input_image ('enable', 'images/lightbulb_off.png', 1, '', true); - $data[0] .= print_input_hidden ('enable_alert', 1, true); - } else { - $data[0] .= print_input_image ('disable', 'images/lightbulb.png', 1, '', true); - $data[0] .= print_input_hidden ('disable_alert', 1, true); - } - $data[0] .= print_input_hidden ('id_alert', $alert['id'], true); - $data[0] .= '
'; - $data[1] = get_agentmodule_name ($alert['id_agent_module']); - $data[2] = get_alert_template_name ($alert['id_alert_template']); - $data[2] .= ' - '; - - $actions = get_alert_actions ($alert['id']); - $data[3] = ''; - - array_push ($table->data, $data); + $data[0] = '
'; + if ($alert['disabled']) { + $data[0] .= print_input_image ('enable', 'images/lightbulb_off.png', 1, '', true); + $data[0] .= print_input_hidden ('enable_alert', 1, true); + } else { + $data[0] .= print_input_image ('disable', 'images/lightbulb.png', 1, '', true); + $data[0] .= print_input_hidden ('disable_alert', 1, true); } + $data[0] .= print_input_hidden ('id_alert', $alert['id'], true); + $data[0] .= '
'; - print_table ($table); + if (! $id_agente) { + $id_agent = get_agentmodule_agent ($alert['id_agent_module']); + $data[1] = ''; + $data[1] .= get_agent_name ($id_agent); + $data[1] .= ''; + } + $data[2] = get_agentmodule_name ($alert['id_agent_module']); + $data[3] = get_alert_template_name ($alert['id_alert_template']); + $data[3] .= ' + '; + + $actions = get_alert_agent_module_actions ($alert['id']); + $data[4] = ''; + + $data[4] .= ''; + $data[4] .= print_image ('images/add.png', true); + $data[4] .= ' '.__('Add action'); + $data[4] .= ''; + + array_push ($table->data, $data); } -$config['css'][] = "cluetip"; //link tags can't go in body -$config['jquery'][] = "cluetip"; //make sure it doesn't get overwritten -$config['jquery'][] = "form"; +print_table ($table); + +echo '

'.__('Add alert').'

'; + +$table->id = 'add_alert_table'; +$table->class = 'databox'; +$table->head = array (); +$table->data = array (); +$table->size = array (); +$table->size = array (); +$table->size[0] = '10%'; +$table->size[1] = '90%'; +$table->style[0] = 'font-weight: bold; vertical-align: top;'; + +/* Add an agent selector */ +if (! $id_agente) { + $table->data['group'][0] = __('Group'); + $table->data['group'][1] = print_select ($groups, 'id_group', $id_group, + false, '', '', true); + + $table->data['agent'][0] = __('Agent'); + $table->data['agent'][1] = print_select (get_group_agents ($groups, false, "none"), + 'id_agent', 0, false, __('Select'), 0, true); + $table->data['agent'][1] .= ' '; +} + +$table->data[0][0] = __('Module'); +$modules = array (); +if ($id_agente) + $modules = get_agent_modules ($id_agente); +$table->data[0][1] = print_select ($modules, 'id_agent_module', 0, true, + __('Select'), 0, true, false, true, '', ($id_agente == 0)); +$table->data[0][1] .= ' '; +$table->data[0][1] .= ' '; + +$table->data[1][0] = __('Template'); +$templates = get_alert_templates (); +if (empty ($templates)) + $templates = array (); +$table->data[1][1] = print_select ($templates, 'template', '', '', __('Select'), + 0, true); +$table->data[1][1] .= ' '; + +$table->data[2][0] = __('Actions'); +$actions = get_alert_actions (); +if (empty ($actions)) + $actions = array (); +$table->data[2][1] = '
'; +foreach ($actions as $action_id => $action_name) { + $id = 'actions['.$action_id.']'; + $table->data[2][1] .= print_checkbox ($id, $action_id, false, true); + $table->data[2][1] .= print_label ($action_name, 'checkbox-'.$id, true); + $table->data[2][1] .= ' '; + $table->data[2][1] .= '
'; +} +$table->data[2][1] .= '
'; + +echo '
'; + +print_table ($table); + +echo '
'; +print_submit_button (__('Add'), 'add', false, 'class="sub next"'); +print_input_hidden ('create_alert', 1); +echo '
'; + +echo ''; + +$config['css'][] = 'cluetip'; +$config['jquery'][] = 'cluetip'; +$config['jquery'][] = 'pandora.controls'; ?> diff --git a/pandora_console/godmode/alerts/configure_alert_compound.php b/pandora_console/godmode/alerts/configure_alert_compound.php index d6fe967d44..b328067a74 100644 --- a/pandora_console/godmode/alerts/configure_alert_compound.php +++ b/pandora_console/godmode/alerts/configure_alert_compound.php @@ -710,7 +710,7 @@ $(document).ready (function () { $("#alerts_loading").show (); $("#alert_list tbody").empty (); jQuery.post ("ajax.php", - {"page" : "godmode/agentes/alert_manager", + {"page" : "godmode/alerts/alert_list", "get_agent_alerts_simple" : 1, "id_agent" : this.value }, diff --git a/pandora_console/godmode/reporting/map_builder.php b/pandora_console/godmode/reporting/map_builder.php index 79da33f5f4..3523e5cb26 100644 --- a/pandora_console/godmode/reporting/map_builder.php +++ b/pandora_console/godmode/reporting/map_builder.php @@ -448,9 +448,9 @@ function agent_changed (event, id_agent, selected) { $('#form_layout_data_editor #module').empty (); $('#form_layout_data_editor #module').append ($('').html ("...").attr ("value", 0)); jQuery.post ('ajax.php', - {page: "operation/agentes/ver_agente", - get_agent_modules_json: 1, - id_agent: id_agent + {"page": "operation/agentes/ver_agente", + "get_agent_modules_json": 1, + "id_agent": id_agent }, function (data) { $('#form_layout_data_editor #module').empty (); @@ -479,9 +479,9 @@ $(document).ready (function () { possible to kwown the image dimensions using javascript in some cases where the image was not loaded */ jQuery.post ('ajax.php', - {page: "godmode/reporting/map_builder", - get_background_info: 1, - background: background + {"page": "godmode/reporting/map_builder", + "get_background_info": 1, + "background": background }, function (data) { $("#layout_map").css ('backgroundImage', 'url(images/console/background/' + background + ')'); @@ -529,9 +529,9 @@ $(document).ready (function () { drop: function (ev, ui) { id = ui.draggable[0].id.split ("-").pop (); jQuery.post ('ajax.php', - {page: "godmode/reporting/map_builder", - get_layout_data: 1, - id_layout_data: id + {"page": "godmode/reporting/map_builder", + "get_layout_data": 1, + "id_layout_data": id }, function (data) { $("#form_layout_data_editor #text-label").attr ('value', data['label']); @@ -568,7 +568,7 @@ $(document).ready (function () { css ('margin-top', 0). attr ('id', 'delete-layout-data-' + id). appendTo ("#"+this.id + " #elements"); $(ui.draggable[0]).remove (); - $('').attr ('value', id). + $('').attr ('value', id). appendTo ($("#form_layout_data_trash")); $("#form_layout_data_trash #submit-delete_buttons").removeAttr ('disabled'); setTimeout (function() { refresh_lines (lines, 'layout_map'); }, 1000); @@ -577,10 +577,10 @@ $(document).ready (function () { $("#form_layout_data_editor #image").change (function () { $("#image_preview").empty (); if (this.value != '') { - $("#image_preview").append ($('').attr ('src', 'images/console/icons/' + this.value + '.png')); - $("#image_preview").append ($('').attr ('src', 'images/console/icons/' + this.value + '_ok.png')); - $("#image_preview").append ($('').attr ('src', 'images/console/icons/' + this.value + '_warning.png')); - $("#image_preview").append ($('').attr ('src', 'images/console/icons/' + this.value + '_bad.png')); + $("#image_preview").append ($('').attr ('src', 'images/console/icons/' + this.value + '.png')); + $("#image_preview").append ($('').attr ('src', 'images/console/icons/' + this.value + '_ok.png')); + $("#image_preview").append ($('').attr ('src', 'images/console/icons/' + this.value + '_warning.png')); + $("#image_preview").append ($('').attr ('src', 'images/console/icons/' + this.value + '_bad.png')); } }); $("#form_layout_data_editor #agent").change (agent_changed); diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 50e719fcd9..a34ec2f786 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -23,11 +23,13 @@ * @param int Agent id * @param string Filter on "fired", "notfired" or "disabled". Any other value * will not do any filter. + * @param array Extra filter options in an indexed array. See + * format_array_to_where_clause_sql() * * @return array All simple alerts defined for an agent. Empty array if no * alerts found. */ -function get_agent_alerts_simple ($id_agent, $filter = false) { +function get_agent_alerts_simple ($id_agent, $filter = '', $options = false) { switch ($filter) { case "notfired": $filter = ' AND times_fired = 0 AND disabled = 0'; @@ -42,10 +44,15 @@ function get_agent_alerts_simple ($id_agent, $filter = false) { $filter = ''; } + $id_agent = (array) $id_agent; $id_modules = array_keys (get_agent_modules ($id_agent)); if (empty ($id_modules)) return array (); + if (is_array ($options)) { + $filter .= format_array_to_where_clause_sql ($options); + } + $sql = sprintf ("SELECT talert_template_modules.* FROM talert_template_modules WHERE id_agent_module in (%s)%s", @@ -62,10 +69,13 @@ function get_agent_alerts_simple ($id_agent, $filter = false) { * Get all the combined alerts of an agent. * * @param int $id_agent Agent id + * @param string Special filter. Can be: "notfired", "fired" or "disabled". + * @param array Extra filter options in an indexed array. See + * format_array_to_where_clause_sql() * * @return array An array with all combined alerts defined for an agent. */ -function get_agent_alerts_compound ($id_agent, $filter = false) { +function get_agent_alerts_compound ($id_agent, $filter = '', $options = false) { switch ($filter) { case "notfired": $filter = ' AND times_fired = 0 AND disabled = 0'; @@ -80,9 +90,15 @@ function get_agent_alerts_compound ($id_agent, $filter = false) { $filter = ''; } + if (is_array ($options)) { + $filter .= format_array_to_where_clause_sql ($options); + } + + $id_agent = array ($id_agent); + $sql = sprintf ("SELECT * FROM talert_compound - WHERE id_agent = %d%s", - $id_agent, $filter); + WHERE id_agent in (%s)%s", + implode (',', $id_agent), $filter); $alerts = get_db_all_rows_sql ($sql); @@ -95,14 +111,16 @@ function get_agent_alerts_compound ($id_agent, $filter = false) { * Get all the alerts of an agent, simple and combined. * * @param int $id_agent Agent id + * @param string Special filter. Can be: "notfired", "fired" or "disabled". + * @param array Extra filter options in an indexed array. See + * format_array_to_where_clause_sql() * * @return array An array with all alerts defined for an agent. */ -function get_agent_alerts ($id_agent, $filter = false) { - $simple_alerts = get_agent_alerts_simple ($id_agent, $filter); - $combined_alerts = get_agent_alerts_compound ($id_agent, $filter); +function get_agent_alerts ($id_agent, $filter = false, $options = false) { + $simple_alerts = get_agent_alerts_simple ($id_agent, $filter, $options); + $combined_alerts = get_agent_alerts_compound ($id_agent, $filter, $options); return array ('simple' => $simple_alerts, 'compounds' => $combined_alerts); } - ?> diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 05f4796777..f3f8a7c7d6 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -680,31 +680,29 @@ function add_alert_agent_module_action ($id_alert_agent_module, $id_alert_action } $sql = sprintf ('INSERT INTO talert_template_module_actions + (id_alert_template_module, id_alert_action, fires_min, fires_max) VALUES (%d, %d, %d, %d)', $id_alert_agent_module, $id_alert_action, $fires_min, $fires_max); - return @process_sql ($sql) !== false; + return process_sql ($sql, 'insert_id'); } -function delete_alert_agent_module_action ($id_alert_agent_module, $id_alert_action) { - if (empty ($id_alert_agent_module)) - return false; - if (empty ($id_alert_action)) +function delete_alert_agent_module_action ($id_alert_agent_module_action) { + if (empty ($id_alert_agent_module_action)) return false; $sql = sprintf ('DELETE FROM talert_template_module_actions - WHERE id_alert_template_module = %d - AND id_alert_action = %d', - $id_alert_agent_module, $id_alert_action); + WHERE id = %d', + $id_alert_agent_module_action); - return @process_sql ($sql) !== false; + return process_sql ($sql) !== false; } function get_alert_agent_module_actions ($id_alert_agent_module) { if (empty ($id_alert_agent_module)) return false; - $sql = sprintf ('SELECT id_alert_action id, fires_min, fires_max + $sql = sprintf ('SELECT id, id_alert_action, fires_min, fires_max FROM talert_template_module_actions WHERE id_alert_template_module = %d', $id_alert_agent_module); @@ -714,10 +712,10 @@ function get_alert_agent_module_actions ($id_alert_agent_module) { $retval = array (); foreach ($actions as $element) { - $action = get_alert_action ($element['id']); + $action = get_alert_action ($element['id_alert_action']); $action['fires_min'] = $element['fires_min']; $action['fires_max'] = $element['fires_max']; - array_push ($retval, $action); + $retval[$element['id']] = $action; } return $retval; diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index cd3b31eeac..512ae11fed 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -1721,7 +1721,8 @@ function format_array_to_update_sql ($values) { $values = array (); $values['name'] = "Name"; $values['description'] = "Long description"; - $sql = 'SELECT * FROM table WHERE '.format_array_to_where_sql ($values).' LIMIT 20'; + $values['limit'] = $config['block_size']; // Assume it's 20 + $sql = 'SELECT * FROM table WHERE '.format_array_to_where_sql ($values); echo $sql; * Will return: @@ -1730,6 +1731,8 @@ function format_array_to_update_sql ($values) { * * * @param array Values to be formatted in an array indexed by the field name. + * There are special parameters such as 'limit' and 'offset' that will be used + * as LIMIT and OFFSET clauses respectively. * @param string Join operator. AND by default. * * @return string Values joined into an SQL string that can fits into the WHERE @@ -1743,6 +1746,8 @@ function format_array_to_where_clause_sql ($values, $join = 'AND') { } $query = ''; + $limit = ''; + $offset = ''; $i = 1; $max = count ($values); foreach ($values as $field => $value) { @@ -1750,6 +1755,16 @@ function format_array_to_where_clause_sql ($values, $join = 'AND') { /* Avoid numeric field names */ continue; + if ($field == 'limit') { + $limit = sprintf (' LIMIT %d', $value); + continue; + } + + if ($field == 'offset') { + $offset = sprintf (' OFFSET %d', $value); + continue; + } + if ($field[0] != "`") { $field = "`".$field."`"; } @@ -1770,7 +1785,7 @@ function format_array_to_where_clause_sql ($values, $join = 'AND') { $i++; } - return $query; + return $query.$limit.$offset; } /** diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 14749213f0..3178bb8222 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -53,7 +53,7 @@ function print_select ($fields, $name, $selected = '', $script = '', $nothing = $attributes .= ' disabled="disabled"'; } - $output .= ''; if ($nothing != '') { $output .= '") + .attr ("value", value['id_agente_modulo']) + .html (html_entity_decode (value['nombre'])); + config.callbackPost (i, value, option); + $("#"+config.moduleSelectId).append (option); + }); + $("#"+config.loadingId).hide (); + $select.enable (); + config.callbackAfter (); + }, + "json" + ); + }); + }); + }; + } + }); $.fn.extend({ - pandoraSelectGroup: $.pandoraSelectGroup.construct + pandoraSelectGroup: $.pandoraSelectGroup.construct, + pandoraSelectAgent: $.pandoraSelectAgent.construct, }); }); diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index b4173ea27a..3ee74c1339 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -879,13 +879,33 @@ fieldset { width: 90%; margin-bottom: 15px; } -fieldset legend span { +fieldset legend span, +span#latest_value { font-style:italic; - +} +span#latest_value span#value { + font-style:normal; } form#filter_form { margin-bottom: 15px; } +ul.action_list { + margin: 0; + list-style: none inside url(../../images/arrow.png); +} +ul.action_list li div { + margin-left: 15px; +} +div.actions_container { + overflow:auto; + width: 100%; + max-height: 200px; +} +div.actions_container label { + display: inline; + font-weight: normal; + font-style: italic; +} /* timeEntry styles */ .timeEntry_control { vertical-align: middle; diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index cf3055f131..96fb68648b 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -27,6 +27,24 @@ if (! give_acl ($config['id_user'], 0, "AR")) { exit; } +if (defined ('AJAX')) { + $get_agent_module_last_value = (bool) get_parameter ('get_agent_module_last_value'); + + if ($get_agent_module_last_value) { + $id_module = (int) get_parameter ('id_agent_module'); + + if (! give_acl ($config['id_user'], get_agentmodule_group ($id_module), "AR")) { + audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", + "Trying to access agent main list view"); + echo json_encode (false); + return; + } + echo json_encode (get_agent_module_last_value ($id_module)); + return; + } + return; +} + // Take some parameters (GET) $offset = get_parameter ("offset", 0); $group_id = get_parameter ("group_id", 0); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 447894e96d..90e81f52c9 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -274,10 +274,12 @@ CREATE TABLE IF NOT EXISTS `talert_template_modules` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `talert_template_module_actions` ( + `id` int(10) unsigned NOT NULL auto_increment, `id_alert_template_module` int(10) unsigned NOT NULL, `id_alert_action` int(10) unsigned NOT NULL, `fires_min` int(3) unsigned default 0, `fires_max` int(3) unsigned default 0, + PRIMARY KEY (`id`), FOREIGN KEY (`id_alert_template_module`) REFERENCES talert_template_modules(`id`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`) diff --git a/pandora_console/pandoradb_migrate_20_to_21.sql b/pandora_console/pandoradb_migrate_20_to_21.sql index 5aa0730a08..313a8f2649 100644 --- a/pandora_console/pandoradb_migrate_20_to_21.sql +++ b/pandora_console/pandoradb_migrate_20_to_21.sql @@ -105,10 +105,12 @@ CREATE TABLE IF NOT EXISTS `talert_template_modules` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `talert_template_module_actions` ( + `id` int(10) unsigned NOT NULL auto_increment, `id_alert_template_module` int(10) unsigned NOT NULL, `id_alert_action` int(10) unsigned NOT NULL, `fires_min` int(3) unsigned default 0, `fires_max` int(3) unsigned default 0, + PRIMARY KEY (`id`), FOREIGN KEY (`id_alert_template_module`) REFERENCES talert_template_modules(`id`) ON DELETE CASCADE ON UPDATE CASCADE,