diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 6ed413995a..85392c8c64 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,64 @@ +2009-02-11 Esteban Sanchez + + * general/main_menu.php, include/styles/menu.css: Selected menu style + is done with a CSS classs. Slide effect removed. Submenus have now + white background. + + * godmode/agentes/alert_manager.php: Allow creation of alerts without + actions which have sense in compound alerts. + + * include/javascript/jquery.pandora.js: Added showMessage() function. + + * godmode/agentes/module_manager_editor.php: Use new showMessage() + jQuery function. + + * godmode/alerts/configure_alert_compound.php: Added to repository. + New compound alert editor interface. + + * godmode/alerts/alert_compounds.php: Added to repository. Compound + alert list. + + * godmode/alerts/configure_alert_template.php: Better style for steps + of the editor. + + * godmode/menu.php: Added compound alerts option. Changed default page + on Manage alerts. + + * include/styles/pandora.css: Added style for editor steps. Added new + generic classes. + + * include/functions.php: Added a new line when creating script list. + + * include/functions_agents.php: Fixed alert tables fields. Renamed + get_agent_alerts_compound() and improved the returning value of + get_agent_alerts(). + + * include/functions_alerts.php: Added new functions to manage compound + alerts. Avoid SQL errors when using process_sql functions. + + * include/functions_reporting.php: Temporary disabled compound alert + reports. + + * include/functions_ui.php: Fixed format_alert_row() to fit compound + alerts. + + * operation/agentes/alerts_status.php: Allow compound alert + validation. Removed effect of cluetip. + + * pandoradb.sql, pandoradb_migrate_20_to_21.sql: New compound alert + tables (talert_compound, talert_compound_elements and + talert_compound_actions). + + * godmode/alerts/alert_list.php: Added to repository. Shows a list of + all the alerts defined. Would be improved in the future to allow + sorting and filtering. + + * index.php, godmode/snmpconsole/snmp_alert.php, + include/functions_db.php: Code style correction. + + * godmode/agentes/configurar_agente.php: Removed old compound alerts + code + 2009-02-11 Sancho Lerena * godmode/reporting/reporting_builder.php: Added 3-month period diff --git a/pandora_console/general/main_menu.php b/pandora_console/general/main_menu.php index 79b15f5eae..2a456ace70 100644 --- a/pandora_console/general/main_menu.php +++ b/pandora_console/general/main_menu.php @@ -97,22 +97,22 @@ function temp_print_menu ($menu, $classtype) { $link_add = ""; } $submenu_output .= ''; - $submenu_output .= ''.$sub["text"].''; + $submenu_output .= ''.$sub["text"].''; $submenu_output .= ''; } } //Print out the first level $output .= '
  • '; - $output .= ''.$main["text"].'toggle'; + $output .= ''.$main["text"].'toggle'; if ($submenu_output != '') { //WARNING: IN ORDER TO MODIFY THE VISIBILITY OF MENU'S AND SUBMENU'S (eg. with cookies) YOU HAVE TO ADD TO THIS ELSEIF. DON'T MODIFY THE CSS if ($visible || in_array ("selected", $classes)) { - $visible = true; + $visible = true; } $output .= ''; + $output .= ''; } $output .= '
  • '; echo $output; @@ -136,13 +136,13 @@ unset ($menu); require ("links_menu.php"); $config['jquery'][] = 'cookie'; -print_r ($_COOKIE); ?> diff --git a/pandora_console/godmode/agentes/alert_manager.php b/pandora_console/godmode/agentes/alert_manager.php index e3d7f1b59a..7da50d0993 100644 --- a/pandora_console/godmode/agentes/alert_manager.php +++ b/pandora_console/godmode/agentes/alert_manager.php @@ -323,9 +323,6 @@ $(document).ready (function () { return false; } - if ($("#action", this).attr ("value") == 0) { - return false; - } return true; }); diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index f3d3163d9f..bc96d9ad86 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -277,38 +277,6 @@ if (isset($_GET["fix_module"])){ } } -// Delete Alert component (from a combined) -// ========================================== -if (isset($_GET["delete_alert_comp"])) { // if modified some parameter - $id_borrar_modulo = get_parameter_get ("delete_alert_comp",0); - // get info about agent - $sql = sprintf ("DELETE FROM tcompound_alert WHERE id_aam = %d", $id_borrar_modulo); - $result = process_sql ($sql); - - if ($result === false) { - echo '

    '.__('There was a problem deleting alert').'

    '; - } else { - echo '

    '.__('Alert successfully deleted').'

    '; - } -} - -// Combined ALERT - Add component -// ================================ -if (isset($_POST["add_alert_combined"])) { // Update an existing alert - $alerta_id_aam = get_parameter ('update_alert', -1); - $component_item = get_parameter ('component_item', -1); - $component_operation = get_parameter ('component_operation', 'AND'); - $sql = sprintf ("INSERT INTO tcompound_alert (id, id_aam, operation) VALUES (%d, %d, '%s')", - $alerta_id_aam, $component_item, $component_operation); - $result = process_sql ($sql); - if ($result === false) { - echo '

    '.__('There was a problem creating the combined alert').'

    '; - } else { - echo '

    '.__('Combined alert successfully created').'

    '; - } - -} - // ================ // Update AGENT // ================ diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 1d96468e5e..7e63601fcd 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -327,9 +327,7 @@ $(document).ready (function () { $("form#module_form").submit (function () { if ($("#text-name").attr ("value") == "") { $("#text-name").pulsate ().focus (); - $("#message").hide ().empty () - .text ("") - .slideDown (); + $("#message").showMessage (""); return false; } @@ -339,9 +337,7 @@ $(document).ready (function () { /* Network module */ if ($("#text-ip_target").attr ("value") == "") { $("#text-ip_target").pulsate ().focus (); - $("#message").hide ().empty () - .text ("") - .slideDown (); + $("#message").showMessage (""); return false; } } @@ -349,9 +345,7 @@ $(document).ready (function () { if (snmp.in_array (module)) { if ($("#text-snmp_oid").attr ("value") == "") { if ($("#select_snmp_oid").attr ("value") == "") { - $("#message").hide ().empty () - .text ("") - .slideDown (); + $("#message").showMessage (""); return false; } } diff --git a/pandora_console/godmode/alerts/alert_compounds.php b/pandora_console/godmode/alerts/alert_compounds.php new file mode 100644 index 0000000000..387629a728 --- /dev/null +++ b/pandora_console/godmode/alerts/alert_compounds.php @@ -0,0 +1,69 @@ +'.__('Compound alerts').''; + +$groups = get_user_groups (); +$agents = get_group_agents (array_keys ($groups), false, "none"); + +$table->class = 'alert_list'; +$table->width = '90%'; + +foreach ($agents as $agent_id => $agent_name) { + $alerts = get_agent_alerts_compound ($agent_id); + if (empty ($alerts)) + continue; + + echo '

    '.$agent_name.' - '.__('Compound alerts').'

    '; + + $table->data = array (); + $table->head = array (); + $table->style = array (); + $table->style[0] = 'font-weight: bold'; + $table->head[0] = __('Name'); + + foreach ($alerts as $alert) { + $data = array (); + + $data[0] = ''; + $data[0] .= $alert['name']; + $data[0] .= ''; + + array_push ($table->data, $data); + } + + print_table ($table); +} + +echo '
    '; +echo '
    '; +print_submit_button (__('Create'), 'crtbtn', false, 'class="sub next"'); +print_input_hidden ('new_compound', 1); +echo '
    '; +echo '
    '; +?> diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php new file mode 100644 index 0000000000..28389feda9 --- /dev/null +++ b/pandora_console/godmode/alerts/alert_list.php @@ -0,0 +1,167 @@ +'.__('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; +} + +foreach ($simple_alerts as $agent_id => $alerts) { + if (empty ($alerts)) + continue; + + 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 (); + $table->size[0] = '20px'; + + 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] = '
      '; + foreach ($actions as $action) { + $data[3] .= '
    • '.$action.'
    • '; + } + $data[3] .= '
    '; + + array_push ($table->data, $data); + } + + print_table ($table); +} +?> + + + + + + diff --git a/pandora_console/godmode/alerts/configure_alert_compound.php b/pandora_console/godmode/alerts/configure_alert_compound.php new file mode 100644 index 0000000000..7332c3a162 --- /dev/null +++ b/pandora_console/godmode/alerts/configure_alert_compound.php @@ -0,0 +1,834 @@ +'; + + /* Step 1 */ + if ($step == 1) + echo '
  • '; + elseif ($step > 1) + echo '
  • '; + else + echo '
  • '; + + if ($id) { + echo ''; + echo __('Step').' 1 » '; + echo ''.__('Conditions').''; + echo ''; + } else { + echo __('Step').' 1 » '; + echo ''.__('Conditions').''; + } + echo '
  • '; + + /* Step 2 */ + if ($step == 2) + echo '
  • '; + elseif ($step > 2) + echo '
  • '; + else + echo '
  • '; + + if ($id) { + echo ''; + echo __('Step').' 2 » '; + echo ''.__('Firing').''; + echo ''; + } else { + echo __('Step').' 2 » '; + echo ''.__('Firing').''; + } + + /* Step 3 */ + if ($step == 3) + echo '
  • '; + elseif ($step > 3) + echo '
  • '; + else + echo '
  • '; + + if ($id) { + echo ''; + echo __('Step').' 3 » '; + echo ''.__('Recovery').''; + echo ''; + } else { + echo __('Step').' 3 » '; + echo ''.__('Recovery').''; + } + + echo ''; + echo '
    '; +} + +function update_compound ($step) { + $id = (int) get_parameter ('id'); + + if (empty ($id)) + return false; + + if ($step == 1) { + $id_agent = (int) get_parameter ('id_agent'); + $name = (string) get_parameter ('name'); + $description = (string) get_parameter ('description'); + + $result = update_alert_compound ($id, + array ('name' => $name, + 'description' => $description, + 'id_agent' => $id_agent)); + } elseif ($step == 2) { + $monday = (bool) get_parameter ('monday'); + $tuesday = (bool) get_parameter ('tuesday'); + $wednesday = (bool) get_parameter ('wednesday'); + $thursday = (bool) get_parameter ('thursday'); + $friday = (bool) get_parameter ('friday'); + $saturday = (bool) get_parameter ('saturday'); + $sunday = (bool) get_parameter ('sunday'); + $time_from = (string) get_parameter ('time_from'); + $time_from = date ("H:s:00", strtotime ($time_from)); + $time_to = (string) get_parameter ('time_to'); + $time_to = date ("H:s:00", strtotime ($time_to)); + $threshold = (int) get_parameter ('threshold'); + $max_alerts = (int) get_parameter ('max_alerts'); + $min_alerts = (int) get_parameter ('min_alerts'); + if ($threshold == -1) + $threshold = (int) get_parameter ('other_threshold'); + + $values = array ('monday' => $monday, + 'tuesday' => $tuesday, + 'wednesday' => $wednesday, + 'thursday' => $thursday, + 'friday' => $friday, + 'saturday' => $saturday, + 'sunday' => $sunday, + 'time_from' => $time_from, + 'time_to' => $time_to, + 'time_threshold' => $threshold, + 'max_alerts' => $max_alerts, + 'min_alerts' => $min_alerts + ); + + $result = update_alert_compound ($id, $values); + + /* Update actions */ + $actions = (array) get_parameter ('actions'); + foreach ($actions as $id_action) { + /* TODO: fires_min and fires_max missing */ + add_alert_compound_action ($id, (int) $id_action); + } + } elseif ($step == 3) { + $recovery_notify = (bool) get_parameter ('recovery_notify'); + $field2_recovery = (bool) get_parameter ('field2_recovery'); + $field3_recovery = (bool) get_parameter ('field3_recovery'); + + $result = update_alert_compound ($id, + array ('recovery_notify' => $recovery_notify, + 'field2_recovery' => $field2_recovery, + 'field3_recovery' => $field3_recovery)); + } else { + return false; + } + + return $result; +} + +/* We set here the number of steps */ +define ('LAST_STEP', 3); + +$step = (int) get_parameter ('step', 1); + +$create_compound = (bool) get_parameter ('create_compound'); +$update_compound = (bool) get_parameter ('update_compound'); + +$name = ''; +$description = ''; +$time_from = '12:00'; +$time_to = '12:00'; +$monday = true; +$tuesday = true; +$wednesday = true; +$thursday = true; +$friday = true; +$saturday = true; +$sunday = true; +$default_action = 0; +$field1 = ''; +$field2 = ''; +$field3 = ''; +$min_alerts = 0; +$max_alerts = 1; +$threshold = 300; +$recovery_notify = false; +$field2_recovery = ''; +$field3_recovery = ''; + +if ($id && ! $create_compound) { + $compound = get_alert_compound ($id); + $name = $compound['name']; + $description = $compound['description']; + $time_from = $compound['time_from']; + $time_to = $compound['time_to']; + $monday = (bool) $compound['monday']; + $tuesday = (bool) $compound['tuesday']; + $wednesday = (bool) $compound['wednesday']; + $thursday = (bool) $compound['thursday']; + $friday = (bool) $compound['friday']; + $saturday = (bool) $compound['saturday']; + $sunday = (bool) $compound['sunday']; + $max_alerts = $compound['max_alerts']; + $min_alerts = $compound['min_alerts']; + $threshold = $compound['time_threshold']; + $recovery_notify = $compound['recovery_notify']; + $field2_recovery = $compound['field2_recovery']; + $field3_recovery = $compound['field3_recovery']; + $id_agent = $compound['id_agent']; + $id_group = get_agent_group ($id_agent); + if (! give_acl ($config['id_user'], $id_group, "AW")) { + audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", + "Trying to access Alert Management"); + require ("general/noaccess.php"); + return; + } +} + +if ($create_compound) { + $name = (string) get_parameter ('name'); + $description = (string) get_parameter ('description'); + + $result = create_alert_compound ($name, $id_agent, + array ('description' => $description)); + + print_error_message ($result, __('Successfully created'), + __('Could not be created')); + /* Go to previous step in case of error */ + if ($result === false) + $step = $step - 1; + else { + $id = $result; + $alerts = (array) get_parameter ('conditions'); + $operations = (array) get_parameter ('operations'); + + foreach ($alerts as $id_alert) { + add_alert_compound_element ($id, (int) $id_alert, $operations[$id_alert]); + } + } +} + +if ($update_compound) { + $result = update_compound ($step - 1); + + print_error_message ($result, __('Successfully updated'), + __('Could not be updated')); + /* Go to previous step in case of error */ + if ($result === false) { + $step = $step - 1; + } +} + +echo '

    '.__('Configure compound alert').'

    '; + +print_alert_compound_steps ($step, $id); + +$table->id = 'compound'; +$table->width = '90%'; +$table->style = array (); +$table->style[0] = 'font-weight: bold; vertical-align: top'; +$table->style[2] = 'font-weight: bold'; +$table->size = array (); +$table->size[0] = '20%'; +$table->size[2] = '20%'; +if ($step == 2) { + /* Firing conditions and events */ + $threshold_values = get_alert_compound_threshold_values (); + if (in_array ($threshold, array_keys ($threshold_values))) { + $table->style['other_label'] = 'display:none; font-weight: bold'; + $table->style['other_input'] = 'display:none'; + $threshold_selected = $threshold; + } else { + $table->style['other_label'] = 'font-weight: bold'; + $threshold_selected = -1; + } + + if ($default_action == 0) { + $table->rowstyle = array (); + $table->rowstyle['field1'] = 'display: none'; + $table->rowstyle['field2'] = 'display: none'; + $table->rowstyle['field3'] = 'display: none'; + $table->rowstyle['preview'] = 'display: none'; + } + $table->colspan = array (); + $table->colspan[0][1] = 3; + $table->colspan[4][1] = 3; + $table->colspan['actions'][1] = 3; + $table->colspan['field1'][1] = 3; + $table->colspan['field2'][1] = 3; + $table->colspan['field3'][1] = 3; + $table->colspan['preview'][1] = 3; + + $table->data[0][0] = __('Days of week'); + $table->data[0][1] = __('Mon'); + $table->data[0][1] .= print_checkbox ('monday', 1, $monday, true); + $table->data[0][1] .= __('Tue'); + $table->data[0][1] .= print_checkbox ('tuesday', 1, $tuesday, true); + $table->data[0][1] .= __('Wed'); + $table->data[0][1] .= print_checkbox ('wednesday', 1, $wednesday, true); + $table->data[0][1] .= __('Thu'); + $table->data[0][1] .= print_checkbox ('thursday', 1, $thursday, true); + $table->data[0][1] .= __('Fri'); + $table->data[0][1] .= print_checkbox ('friday', 1, $friday, true); + $table->data[0][1] .= __('Sat'); + $table->data[0][1] .= print_checkbox ('saturday', 1, $saturday, true); + $table->data[0][1] .= __('Sun'); + $table->data[0][1] .= print_checkbox ('sunday', 1, $sunday, true); + + $table->data[1][0] = __('Time from'); + $table->data[1][1] = print_input_text ('time_from', $time_from, '', 7, 7, + true); + $table->data[1][2] = __('Time to'); + $table->data[1][3] = print_input_text ('time_to', $time_to, '', 7, 7, + true); + + $table->data['threshold'][0] = __('Time threshold'); + $table->data['threshold'][1] = print_select ($threshold_values, + 'threshold', $threshold_selected, '', '', '', true, false, false); + $table->data['threshold']['other_label'] = __('Other value'); + $table->data['threshold']['other_input'] = print_input_text ('other_threshold', + $threshold, '', 5, 7, true); + $table->data['threshold']['other_input'] .= ' '.__('seconds'); + + $table->data[3][0] = __('Min. number of alerts'); + $table->data[3][1] = print_input_text ('min_alerts', $min_alerts, '', + 5, 7, true); + $table->data[3][2] = __('Max. number of alerts'); + $table->data[3][3] = print_input_text ('max_alerts', $max_alerts, '', + 5, 7, true); + + $table->data[4][0] = __('Actions'); + $table->data[4][1] = print_select_from_sql ('SELECT id, name FROM talert_actions ORDER BY name', + 'action', '', '', __('Select'), 0, true, false, false).' '; + $table->data[4][1] .= print_button (__('Add'), 'add_action', false, '', + 'class="sub next"', true); + $table->data[4][1] .= '
    '; + $table->data[4][1] .= ''.__('Advanced options').' » '; + $table->data[4][1] .= ''; + + $table->data['actions'][0] = __('Assigned actions'); + $table->data['actions'][1] = '
      '; + if ($id) { + $actions = get_alert_compound_actions ($id); + if (empty ($actions)) + $table->rowstyle['actions'] = 'display: none'; + foreach ($actions as $action) { + $table->data['actions'][1] .= '
    • '; + $table->data['actions'][1] .= $action['name']; + $table->data['actions'][1] .= ' ('; + if ($action['fires_min'] == $action['fires_max']) { + if ($action['fires_min'] == 0) + $table->data['actions'][1] .= __('Always'); + else + $table->data['actions'][1] .= __('On').' '.$action['fires_min']; + } else { + if ($action['fires_min'] == 0) + $table->data['actions'][1] .= __('Until').' '.$action['fires_max']; + else + $table->data['actions'][1] .= __('From').' '.$action['fires_min']. + ' '.__('to').' '.$action['fires_max']; + } + $table->data['actions'][1] .= ')
    • '; + } + } + $table->data['actions'][1] .= '
    '; + +} else if ($step == 3) { + /* Alert recover */ + if (! $recovery_notify) { + $table->rowstyle = array (); + $table->rowstyle['field2'] = 'display:none;'; + $table->rowstyle['field3'] = 'display:none'; + } + $table->data[0][0] = __('Alert recovery'); + $values = array (false => __('Disabled'), true => __('Enabled')); + $table->data[0][1] = print_select ($values, + 'recovery_notify', $recovery_notify, '', '', '', true, false, + false); + + $table->data['field2'][0] = __('Field 2'); + $table->data['field2'][1] = print_input_text ('field2_recovery', + $field2_recovery, '', 35, 255, true); + + $table->data['field3'][0] = __('Field 3'); + $table->data['field3'][1] = print_textarea ('field3_recovery', 30, 30, + $field3_recovery, '', true); +} else { + /* Step 1 by default */ + $table->size = array (); + $table->size[0] = '20%'; + $table->data = array (); + $table->rowstyle = array (); + $table->rowstyle['value'] = 'display: none'; + $table->rowstyle['max'] = 'display: none'; + $table->rowstyle['min'] = 'display: none'; + $table->rowstyle['conditions'] = 'display: none'; + + $show_matches = false; + if ($id) { + $table->rowstyle['conditions'] = ''; + } + + $table->data[0][0] = __('Name'); + $table->data[0][1] = print_input_text ('name', $name, '', 35, 255, true); + + $table->data[1][0] = __('Assigned to'); + $groups = get_user_groups (); + $table->data[1][1] = print_select (get_group_agents (), + 'id_agent', $id_agent, '', __('Select'), 0, true); + $table->data[2][0] = __('Description'); + $table->data[2][1] = print_textarea ('description', 30, 30, + $description, '', true); + + $table->data[3][0] = __('Condition'); + $table->data[3][0] .= ''; + $table->colspan[3][0] = 2; + + $table_alerts->id = 'conditions_list'; + $table_alerts->width = '100%'; + $table_alerts->data = array (); + $table_alerts->head = array (); + $table_alerts->head[0] = ''; + $table_alerts->head[1] = __('Module'); + $table_alerts->head[2] = __('Alert'); + $table_alerts->head[3] = __('Operator'); + $table_alerts->size = array (); + $table_alerts->size[0] = '20px'; + $table_alerts->size[1] = '45%'; + $table_alerts->size[2] = '45%'; + $table_alerts->size[3] = '10%'; + + if ($id) { + $conditions = get_alert_compound_elements ($id); + if ($conditions === false) + $conditions = array (); + foreach ($conditions as $condition) { + $data = array (); + + $alert = get_alert_agent_module ($condition['id_alert_template_module']); + $data[0] = ''; + $data[0] .= ''; + $data[0] .= ''; + $data[1] = get_alert_template_name ($alert['id_alert_template']); + $data[2] = get_agentmodule_name ($alert['id_agent_module']); + $data[3] = print_select (get_alert_compound_operations (), + 'operations['.$id.']', $condition['operation'], '', '', '', true); + $data[3] .= print_input_hidden ("conditions[]", $alert['id']); + + array_push ($table_alerts->data, $data); + } + } + + $table->data['conditions'][1] = print_table ($table_alerts, true); + $table->colspan['conditions'][1] = 2; +} + +/* If it's the last step it will redirect to compound lists */ +if ($step >= LAST_STEP) { + echo '
    '; +} else { + echo ''; +} +print_table ($table); + +echo ''; +echo '
    '; +if ($id) { + print_input_hidden ('id', $id); + print_input_hidden ('update_compound', 1); +} else { + print_input_hidden ('create_compound', 1); +} + +if ($step >= LAST_STEP) { + print_submit_button (__('Finish'), 'finish', false, 'class="sub upd"'); +} else { + print_input_hidden ('step', $step + 1); + print_submit_button (__('Next'), 'next', false, 'class="sub next"'); +} +echo '
    '; +echo '
    '; + +/* Show alert search when we're on the first step */ +if ($step == 1) { + echo '

    '.__('Add condition').'

    '; + + $id_group = (int) get_parameter ('id_group'); + + $table->id = 'alert_search'; + $table->data = array (); + $table->head = array (); + $table->size = array (); + $table->size[0] = '10%'; + $table->size[1] = '40%'; + $table->size[2] = '10%'; + $table->size[3] = '40%'; + + $table->data[0][0] = __('Group'); + $table->data[0][1] = print_select ($groups, 'search_id_group', $id_group, + false, '', '', true); + $table->data[0][2] = __('Agent'); + $table->data[0][3] = print_select (get_group_agents ($id_group, false, "none"), + 'search_id_agent', $id_agent, false, __('Select'), 0, true); + $table->data[0][3] .= ''; + + print_table ($table); + echo ''; + + /* Rest of fields are reused */ + $table_alerts->id = 'alert_list'; + $table_alerts->width = '80%'; + $table_alerts->data = array (); + unset ($table_alerts->head[3]); + + if (! $id_agent) { + $table_alerts->class = 'invisible'; + } else { + $alerts = get_agent_alerts_simple ($id_agent); + + foreach ($alerts as $alert) { + $data = array (); + + $data[0] = ''; + $data[0] .= ''; + $data[0] .= ''; + $data[1] = get_agentmodule_name ($alert['id_agent_module']); + $data[2] = get_alert_template_name ($alert['id_alert_template']); + + array_push ($table_alerts->data, $data); + } + } + + print_table ($table_alerts); + + /* Pager for alert list using Javascript */ + echo '
    '; + echo '
    '; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
    '; + echo '
    '; + + echo ''; +} +?> + + + + + + + + + + + diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index 54eb74325d..8863881066 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -30,52 +30,66 @@ if (! give_acl ($config['id_user'], 0, "LM")) { } function print_alert_template_steps ($step, $id) { - echo '
    '; + echo '
      '; /* Step 1 */ if ($step == 1) - echo ''; + echo '
    1. '; + elseif ($step > 1) + echo '
    2. '; + else + echo '
    3. '; + if ($id) { echo ''; - echo __('Step').' 1 : '.__('Conditions'); + echo __('Step').' 1 » '; + echo ''.__('Conditions').''; echo ''; } else { - echo __('Step').' 1 : '.__('Conditions'); + echo __('Step').' 1 » '; + echo ''.__('Conditions').''; } - if ($step == 1) - echo ''; + echo '
    4. '; /* Step 2 */ - echo ' » '; - if ($step == 2) - echo ''; + echo '
    5. '; + elseif ($step > 2) + echo '
    6. '; + else + echo '
    7. '; + if ($id) { echo ''; - echo __('Step').' 2 : '.__('Firing'); + echo __('Step').' 2 » '; + echo ''.__('Firing').''; echo ''; } else { - echo __('Step').' 2 : '.__('Firing'); + echo __('Step').' 2 » '; + echo ''.__('Firing').''; } - if ($step == 2) - echo ''; + echo '
    8. '; /* Step 3 */ - echo ' » '; - if ($step == 3) - echo ''; + echo '
    9. '; + elseif ($step > 3) + echo '
    10. '; + else + echo '
    11. '; + if ($id) { echo ''; - echo __('Step').' 3 : '.__('Recovery'); + echo __('Step').' 3 » '; + echo ''.__('Recovery').''; echo ''; } else { - echo __('Step').' 3 : '.__('Recovery'); + echo __('Step').' 3 » '; + echo ''.__('Recovery').''; } - if ($step == 3) - echo ''; - echo '
    '; + echo ''; + echo '
    '; } function update_template ($step) { @@ -85,7 +99,6 @@ function update_template ($step) { return false; if ($step == 1) { - $type = (string) get_parameter ('type'); $name = (string) get_parameter ('name'); $description = (string) get_parameter ('description'); $type = (string) get_parameter ('type'); @@ -95,7 +108,8 @@ function update_template ($step) { $matches = (bool) get_parameter ('matches_value'); $result = update_alert_template ($id, - array ('type' => $type, + array ('name' => $name, + 'type' => $type, 'description' => $description, 'value' => $value, 'max_value' => $max, @@ -550,13 +564,8 @@ function render_example () { } $(document).ready (function () { + render_example (); - $("#text-time_from, #text-time_to").timeEntry ({ - spinnerImage: 'images/time-entry.png', - spinnerSize: [20, 20, 0] - } - ); - $("input#text-value").keyup (render_example); $("input#text-max").keyup (render_example); $("input#text-min").keyup (render_example); @@ -641,6 +650,13 @@ $(document).ready (function () { }); $("#text-value").keyup (check_regex); + + $("#text-time_from, #text-time_to").timeEntry ({ + spinnerImage: 'images/time-entry.png', + spinnerSize: [20, 20, 0] + } + ); + $("#threshold").change (function () { if (this.value == -1) { $("#text-other_threshold").attr ("value", ""); @@ -652,14 +668,6 @@ $(document).ready (function () { } }); - $("#recovery_notify").change (function () { - if (this.value == 1) { - $("#template-field2, #template-field3").show (); - } else { - $("#template-field2, #template-field3").hide (); - } - }); - $("#default_action").change (function () { if (this.value != 0) { values = Array (); @@ -691,5 +699,14 @@ $(document).ready (function () { $("#text-field1").keyup (render_command_preview); $("#text-field2").keyup (render_command_preview); $("#text-field3").keyup (render_command_preview); + + $("#recovery_notify").change (function () { + if (this.value == 1) { + $("#template-field2, #template-field3").show (); + } else { + $("#template-field2, #template-field3").hide (); + } + }); + }) diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 9df6a814a4..6504705e61 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -61,7 +61,7 @@ if (give_acl ($config['id_user'], 0, "PM")) { if (give_acl ($config['id_user'], 0, "LM")) { $menu["galertas"]["text"] = __('Manage alerts'); - $menu["galertas"]["sec2"] = "godmode/alerts/alert_templates"; + $menu["galertas"]["sec2"] = "godmode/alerts/alert_list"; $menu["galertas"]["id"] = "god-alerts"; $sub = array (); @@ -71,6 +71,8 @@ if (give_acl ($config['id_user'], 0, "LM")) { $sub["godmode/alerts/alert_commands"]["text"] = __('Commands'); + $sub["godmode/alerts/alert_compounds"]["text"] = __('Compounds'); + $menu["galertas"]["sub"] = $sub; } diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index 14142557b7..4c93b15772 100644 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -392,10 +392,8 @@ $(document).ready (function () { $('#alert_trigger').change (function () { trigger_changed (this.value) }); - + + trigger_changed (""); + }); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index fcfdb78340..00974d098e 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1077,7 +1077,7 @@ function process_page_head ($string, $bitfield) { continue; } array_push ($loaded, $style); - $output .= ''; + $output .= ''."\n"; } } @@ -1089,7 +1089,7 @@ function process_page_head ($string, $bitfield) { continue; } array_push ($loaded, $javascript); - $output .= ''; + $output .= ''."\n"; } } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index b0ef21ec46..50e719fcd9 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -30,13 +30,13 @@ function get_agent_alerts_simple ($id_agent, $filter = false) { switch ($filter) { case "notfired": - $filter = ' AND times_fired = 0 AND disable = 0'; + $filter = ' AND times_fired = 0 AND disabled = 0'; break; case "fired": - $filter = ' AND times_fired > 0 AND disable = 0'; + $filter = ' AND times_fired > 0 AND disabled = 0'; break; case "disabled": - $filter = ' AND disable = 1'; + $filter = ' AND disabled = 1'; break; default: $filter = ''; @@ -65,30 +65,25 @@ function get_agent_alerts_simple ($id_agent, $filter = false) { * * @return array An array with all combined alerts defined for an agent. */ -function get_agent_alerts_combined ($id_agent, $filter = false) { - /* TODO: Combined alerts */ - return array (); +function get_agent_alerts_compound ($id_agent, $filter = false) { switch ($filter) { - case "notfired": - $filter = ' AND times_fired = 0 AND disable = 0'; - break; - case "fired": - $filter = ' AND times_fired > 0 AND disable = 0'; - break; - case "disabled": - $filter = ' AND disable = 1'; - break; - default: - $filter = ''; + case "notfired": + $filter = ' AND times_fired = 0 AND disabled = 0'; + break; + case "fired": + $filter = ' AND times_fired > 0 AND disabled = 0'; + break; + case "disabled": + $filter = ' AND disabled = 1'; + break; + default: + $filter = ''; } - $id_modules = array_keys (get_agent_modules ($id_agent)); - if (empty ($id_modules)) - return array (); + $sql = sprintf ("SELECT * FROM talert_compound + WHERE id_agent = %d%s", + $id_agent, $filter); - $sql = sprintf ("SELECT * FROM talert_template_modules - WHERE id_agent_module IN (%s)%s", - implode (',', $id_modules), $filter); $alerts = get_db_all_rows_sql ($sql); if ($alerts === false) @@ -105,9 +100,9 @@ function get_agent_alerts_combined ($id_agent, $filter = false) { */ function get_agent_alerts ($id_agent, $filter = false) { $simple_alerts = get_agent_alerts_simple ($id_agent, $filter); - $combined_alerts = get_agent_alerts_combined ($id_agent, $filter); + $combined_alerts = get_agent_alerts_compound ($id_agent, $filter); - return array_merge ($simple_alerts, $combined_alerts); + 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 93c37f01a8..ca47d44126 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -44,7 +44,7 @@ function create_alert_command ($name, $command, $values = false) { $sql = sprintf ('INSERT talert_commands (name, command, description) VALUES ("%s", "%s", "%s")', $name, $command, $values['description']); - return process_sql ($sql, 'insert_id'); + return @process_sql ($sql, 'insert_id'); } function update_alert_command ($id_alert_command, $name, $command, $description = '', $values = false) { @@ -61,7 +61,7 @@ function update_alert_command ($id_alert_command, $name, $command, $description $sql = sprintf ('UPDATE talert_commands SET name = "%s", command = "%s", description = "%s" WHERE id = %d', $name, $command, $values['description'], $id_alert_command); - return process_sql ($sql) !== false; + return @process_sql ($sql) !== false; } function delete_alert_command ($id_alert_command) { @@ -150,7 +150,7 @@ function create_alert_action ($name, $id_alert_command, $values = false) { $name, $id_alert_command, $values['field1'], $values['field2'], $values['field3']); - return process_sql ($sql, 'insert_id'); + return @process_sql ($sql, 'insert_id'); } function update_alert_action ($id_alert_action, $id_alert_command, $name, $values = false) { @@ -171,7 +171,7 @@ function update_alert_action ($id_alert_action, $id_alert_command, $name, $value $name, $id_alert_command, $values['field1'], $values['field2'], $values['field3'], $id_alert_action); - return process_sql ($sql) !== false; + return @process_sql ($sql) !== false; } function delete_alert_action ($id_alert_action) { @@ -375,7 +375,7 @@ function create_alert_template ($name, $type, $values = false) { $values['time_threshold'], $values['max_alerts'], $values['min_alerts'], $values['matches_value']); - return process_sql ($sql, 'insert_id'); + return @process_sql ($sql, 'insert_id'); } function update_alert_template ($id_alert_template, $values = false) { @@ -390,7 +390,7 @@ function update_alert_template ($id_alert_template, $values = false) { WHERE id = %d', format_array_to_update_sql ($values), $id_alert_template); - return process_sql ($sql) !== false; + return @process_sql ($sql) !== false; } function delete_alert_template ($id_alert_template) { @@ -571,7 +571,7 @@ function create_alert_agent_module ($id_agent_module, $id_alert_template, $value $values['times_fired'], $values['disabled'], $values['priority'], $values['force_execution']); - return process_sql ($sql, 'insert_id'); + return @process_sql ($sql, 'insert_id'); } function update_alert_agent_module ($id_alert_agent_module, $values = false) { @@ -587,7 +587,7 @@ function update_alert_agent_module ($id_alert_agent_module, $values = false) { WHERE id = %d', format_array_to_update_sql ($values), $id_alert_agent_module); - return process_sql ($sql) !== false; + return @process_sql ($sql) !== false; } function delete_alert_agent_module ($id_alert_agent_module) { @@ -598,7 +598,7 @@ function delete_alert_agent_module ($id_alert_agent_module) { WHERE id = %d', $id_alert_agent_module); - return process_sql ($sql) !== false; + return @process_sql ($sql) !== false; } function get_alert_agent_module ($id_alert_agent_module) { @@ -636,7 +636,7 @@ function set_alerts_agent_module_force_execution ($id_alert_agent_module) { WHERE id = %d', $id_alert_agent_module); - return process_sql ($sql) !== false; + return @process_sql ($sql) !== false; } function set_alerts_agent_module_disable ($id_alert_agent_module, $disabled) { @@ -646,7 +646,7 @@ function set_alerts_agent_module_disable ($id_alert_agent_module, $disabled) { WHERE id = %d', $disabled ? 1 : 0, $id_alert_agent_module); - return process_sql ($sql) !== false; + return @process_sql ($sql) !== false; } function get_alerts_agent_module_last_fired ($id_alert_agent_module) { @@ -679,7 +679,7 @@ function add_alert_agent_module_action ($id_alert_agent_module, $id_alert_action 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) !== false; } function delete_alert_agent_module_action ($id_alert_agent_module, $id_alert_action) { @@ -693,7 +693,7 @@ function delete_alert_agent_module_action ($id_alert_agent_module, $id_alert_act AND id_alert_action = %d', $id_alert_agent_module, $id_alert_action); - return process_sql ($sql) !== false; + return @process_sql ($sql) !== false; } function get_alert_agent_module_actions ($id_alert_agent_module) { @@ -740,16 +740,8 @@ function validate_alert_agent_module ($id_alert_agent_module) { foreach ($alerts as $id) { $alert = get_alert_agent_module ($id); - - if (! empty ($alert["id_agent_module"])) { - //Simple alert - $agent_id = get_agentmodule_agent ($alert["id_agent_module"]); - $group_id = get_agentmodule_group ($agent_id); - } else { - //Combined alert - $agent_id = $alert["id_agent"]; - $group_id = get_agent_group ($agent_id); - } + $agent_id = get_agentmodule_agent ($alert["id_agent_module"]); + $group_id = get_agentmodule_group ($agent_id); if (! give_acl ($config['id_user'], $group_id, "AW")) { continue; @@ -771,4 +763,253 @@ function validate_alert_agent_module ($id_alert_agent_module) { } return true; } + +/* Compound alerts */ + +function get_alert_compound_threshold_values () { + /* At this moment we don't need different threshold values */ + return get_alert_template_threshold_values (); +} + +function get_alert_compound_operations () { + $operations = array (); + + $operations['OR'] = 'OR'; + $operations['AND'] = 'AND'; + $operations['NOR'] = 'NOR'; + $operations['NAND'] = 'NAND'; + $operations['NXOR'] = 'NXOR'; + + return $operations; +} + +function clean_alert_compound_values ($values, $set_empty = true) { + $retvalues = array (); + + if ($set_empty) { + $retvalues['description'] = ''; + $retvalues['time_threshold'] = 0; + $retvalues['max_alerts'] = 0; + $retvalues['min_alerts'] = 0; + $retvalues['monday'] = 0; + $retvalues['tuesday'] = 0; + $retvalues['wednesday'] = 0; + $retvalues['thursday'] = 0; + $retvalues['friday'] = 0; + $retvalues['saturday'] = 0; + $retvalues['sunday'] = 0; + $retvalues['time_from'] = '00:00'; + $retvalues['time_to'] = '00:00'; + $retvalues['time_threshold'] = '300'; + $retvalues['recovery_notify'] = ''; + $retvalues['field2_recovery'] = ''; + $retvalues['field2_recovery'] = ''; + } + + if (empty ($values)) + return $retvalues; + + if (isset ($values['name'])) + $retvalues['name'] = (string) $values['name']; + if (isset ($values['description'])) + $retvalues['description'] = (string) $values['description']; + if (isset ($values['id_agent'])) + $retvalues['id_agent'] = (int) $values['id_agent']; + if (isset ($values['time_threshold'])) + $retvalues['time_threshold'] = (int) $values['time_threshold']; + if (isset ($values['max_alerts'])) + $retvalues['max_alerts'] = (int) $values['max_alerts']; + if (isset ($values['min_alerts'])) + $retvalues['min_alerts'] = (int) $values['min_alerts']; + /* Ensure max an min orders */ + if (isset ($values['min_alerts']) && isset ($values['max_alerts'])) { + $max = max ($retvalues['max_alerts'], $retvalues['min_alerts']); + $min = min ($retvalues['max_alerts'], $retvalues['min_alerts']); + $retvalues['max_alerts'] = $max; + $retvalues['min_alerts'] = $min; + } + if (isset ($values['monday'])) + $retvalues['monday'] = (bool) $values['monday']; + if (isset ($values['tuesday'])) + $retvalues['tuesday'] = (bool) $values['tuesday']; + if (isset ($values['wednesday'])) + $retvalues['wednesday'] = (bool) $values['wednesday']; + if (isset ($values['thursday'])) + $retvalues['thursday'] = (bool) $values['thursday']; + if (isset ($values['friday'])) + $retvalues['friday'] = (bool) $values['friday']; + if (isset ($values['saturday'])) + $retvalues['saturday'] = (bool) $values['saturday']; + if (isset ($values['sunday'])) + $retvalues['sunday'] = (bool) $values['sunday']; + if (isset ($values['time_from'])) + $retvalues['time_from'] = (string) $values['time_from']; + if (isset ($values['time_to'])) + $retvalues['time_to'] = (string) $values['time_to']; + if (isset ($values['time_threshold'])) + $retvalues['time_threshold'] = (int) $values['time_threshold']; + if (isset ($values['recovery_notify'])) + $retvalues['recovery_notify'] = (bool) $values['recovery_notify']; + if (isset ($values['field2_recovery'])) + $retvalues['field2_recovery'] = (string) $values['field2_recovery']; + if (isset ($values['field3_recovery'])) + $retvalues['field3_recovery'] = (string) $values['field3_recovery']; + + return $retvalues; +} + +function create_alert_compound ($name, $id_agent, $values = false) { + if (empty ($name)) + return false; + + $values = clean_alert_compound_values ($values); + $values['name'] = $name; + $values['id_agent'] = $id_agent; + + return @process_sql_insert ('talert_compound', $values); +} + +function update_alert_compound ($id_alert_compound, $values = false) { + if (empty ($id_alert_compound)) + return false; + $values = clean_alert_compound_values ($values, false); + + return @process_sql_update ('talert_compound', $values, + array ('id' => $id_alert_compound)) !== false; +} + +function add_alert_compound_element ($id_alert_compound, $id_alert_template_module, $operation) { + if (empty ($id_alert_compound)) + return false; + if (empty ($id_alert_template_module)) + return false; + if (empty ($operation)) + return false; + + $values = array (); + $values['id_alert_compound'] = $id_alert_compound; + $values['id_alert_template_module'] = $id_alert_template_module; + $values['operation'] = $operation; + + return @process_sql_insert ('talert_compound_elements', $values); +} + +function get_alert_compound ($id_alert_compound) { + return get_db_row ('talert_compound', 'id', $id_alert_compound); +} + +function get_alert_compound_actions ($id_alert_compound) { + if (empty ($id_alert_compound)) + return false; + + $sql = sprintf ('SELECT id_alert_action id, fires_min, fires_max + FROM talert_compound_actions + WHERE id_alert_compound = %d', + $id_alert_compound); + $actions = get_db_all_rows_sql ($sql); + if ($actions === false) + return array (); + + $retval = array (); + foreach ($actions as $element) { + $action = get_alert_action ($element['id']); + $action['fires_min'] = $element['fires_min']; + $action['fires_max'] = $element['fires_max']; + array_push ($retval, $action); + } + + return $retval; +} + +function get_alert_compound_name ($id_alert_compound) { + return (string) get_db_value ('name', 'talert_compund', 'id', $id_alert_compound); +} + +function get_alert_compound_elements ($id_alert_compound) { + return get_db_all_rows_field_filter ('talert_compound_elements', + 'id_alert_compound', $id_alert_compound); +} + +function add_alert_compound_action ($id_alert_compound, $id_alert_action, $options = false) { + if (empty ($id_alert_compound)) + return false; + if (empty ($id_alert_action)) + return false; + + $fires_max = 0; + $fires_min = 0; + if ($options) { + $max = 0; + $min = 0; + if (isset ($options['fires_max'])) + $max = (int) $options['fires_max']; + if (isset ($options['fires_min'])) + $min = (int) $options['fires_min']; + + $fires_max = max ($max, $min); + $fires_min = min ($max, $min); + } + + $sql = sprintf ('INSERT INTO talert_compound_actions + VALUES (%d, %d, %d, %d)', + $id_alert_compound, $id_alert_action, $fires_min, $fires_max); + + return @process_sql ($sql) !== false; +} + +function set_alerts_compound_disable ($id_alert_compound, $disabled) { + $id_alert_agent_module = safe_int ($id_alert_compound, 0); + $sql = sprintf ('UPDATE talert_compound + SET disabled = %d + WHERE id = %d', + $disabled ? 1 : 0, $id_alert_compound); + + return @process_sql ($sql) !== false; +} + +/** + * Validates a compound alert id or an array of alert id's + * + * @param mixed Array of compound alert ids or single id + * + * @return bool True if it was successful, false otherwise. + */ +function validate_alert_compound ($id_alert_compound) { + global $config; + require_once ("include/functions_events.php"); + + $alerts = safe_int ($id_alert_compound, 1); + + if (empty ($alerts)) { + return false; + } + + $alerts = (array) $alerts; + + foreach ($alerts as $id) { + $alert = get_alert_compound ($id); + + $agent_id = $alert["id_agent"]; + $group_id = get_agent_group ($agent_id); + + if (! give_acl ($config['id_user'], $group_id, "AW")) { + continue; + } + $result = process_sql_update ('talert_compound', + array ('times_fired' => 0, + 'internal_counter' => 0), + array ('id' => $id)); + + if ($result > 0) { + create_event ("Manual validation of compound alert for ". + $alert["name"], + $group_id, $agent_id, 1, $config["id_user"], + "alert_manual_validation", 1, $alert["id"], + $id); + } elseif ($result === false) { + return false; + } + } + return true; +} ?> diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 808fe3dd48..1f634ff9d3 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -352,9 +352,8 @@ $modules = get_agent_modules ($id_agent, '*', 'disabled = 0 AND history_data = 0 function get_agent_modules ($id_agent, $details = false, $filter = false) { $id_agent = safe_int ($id_agent, 1); - if (empty ($id_agent)) { - $where = ''; - } else { + $where = ''; + if (! empty ($id_agent)) { $where = sprintf (' WHERE id_agente IN (%s)', implode (",", (array) $id_agent)); } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index b8595948ee..3f1ed423e9 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -538,7 +538,8 @@ function get_agent_alerts_reporting_table ($id_agent, $period = 0, $date = 0) { $table->head[5] = __('Times Fired'); $alerts = get_agent_alerts ($id_agent); - foreach ($alerts as $alert) { + /* FIXME: Add compound alerts to the report. Some extra code is needed here */ + foreach ($alerts['simple'] as $alert) { $fires = get_alert_fires_in_period ($alert['id'], $period, $date); if (! $fires) { continue; diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index d058349aca..975328d505 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -231,21 +231,26 @@ function print_agent_name ($id_agent, $return = false, $cutoff = 0) { * * @return array A formatted array with proper html for use in $table->data (6 columns) */ -function format_alert_row ($alert, $combined = false, $agent = true, $url = '') { +function format_alert_row ($alert, $compound = false, $agent = true, $url = '') { require_once ("include/functions_alerts.php"); if (empty ($alert)) return array ("", "", "", "", "", "", ""); // Get agent id - $id_agente = get_agentmodule_agent ($alert["id_agent_module"]); - $template = get_alert_template ($alert['id_alert_template']); - + if ($compound) { + $id_agent = $alert['id_agent']; + $description = $alert['description']; + } else { + $id_agent = get_agentmodule_agent ($alert['id_agent_module']); + $template = get_alert_template ($alert['id_alert_template']); + $description = $template['description']; + } $data = array (); // Force alert execution $data[0] = ''; - if (! $combined) { + if (! $compound) { if ($alert["force_execution"] == 0) { $data[0] = ''; } else { @@ -253,8 +258,8 @@ function format_alert_row ($alert, $combined = false, $agent = true, $url = '') } } - if ($combined == 1) { - $data[1] = print_agent_name ($id_agente, true, 20); + if ($compound) { + $data[1] = print_agent_name ($id_agent, true, 20); } elseif ($agent == 0) { $data[1] = mb_substr (get_agentmodule_name ($alert["id_agent_module"]), 0, 20); } else { @@ -262,17 +267,20 @@ function format_alert_row ($alert, $combined = false, $agent = true, $url = '') } $data[2] = ''; - $data[2] .= mb_substr (safe_input ($template["description"]), 0, 35); - $data[2] .= ' '; - $data[2] .= ''; - $data[2] .= ''; - $data[2] .= ''; + $data[2] .= mb_substr (safe_input ($description), 0, 35); + $data[2] .= ''; + if (! $compound) { + $data[2] .= ' '; + $data[2] .= ''; + $data[2] .= ''; + $data[2] .= ''; + } $data[3] = print_timestamp ($alert["last_fired"], true); $options = array (); - $options["height"] = 9; - $options["width"] = 20; + $options["height"] = 18; + $options["width"] = 40; if ($alert["times_fired"] > 0) { $options["src"] = "images/pixel_red.png"; @@ -287,7 +295,11 @@ function format_alert_row ($alert, $combined = false, $agent = true, $url = '') $data[4] = print_image ($options["src"], true, $options); - $data[5] = print_checkbox ("validate[]", $alert["id"], false, true); + if ($compound) { + $data[5] = print_checkbox ("validate_compound[]", $alert["id"], false, true); + } else { + $data[5] = print_checkbox ("validate[]", $alert["id"], false, true); + } return $data; } diff --git a/pandora_console/include/javascript/jquery.pandora.js b/pandora_console/include/javascript/jquery.pandora.js index 9de1fbe70f..cdf7b60000 100644 --- a/pandora_console/include/javascript/jquery.pandora.js +++ b/pandora_console/include/javascript/jquery.pandora.js @@ -28,5 +28,10 @@ $(document).ready (function () { }); }); }; - + + $.fn.showMessage = function (msg) { + return $(this).hide ().empty () + .text (msg) + .slideDown (); + }; }); diff --git a/pandora_console/include/styles/menu.css b/pandora_console/include/styles/menu.css index 38646285b5..ea3bd1d145 100644 --- a/pandora_console/include/styles/menu.css +++ b/pandora_console/include/styles/menu.css @@ -36,7 +36,9 @@ border-bottom: 1px solid #d4d4d4; margin: 0; } - +.menu li.selected { + background-color: #D3F389 !important; +} .menu li a { background-color: inherit; color: #000000; @@ -57,11 +59,11 @@ width:155px; } .submenu li a { - background-color: #E9F3D2; + background-color: #fff; margin-left: 0px; padding-left: 29px; display:block; - border-width: 1px 0 0 1px; + border-width: 1px 1px 0 1px; border-style: solid; border-color: #dadbdc; } @@ -69,18 +71,23 @@ visibility: hidden; float:right; margin: -20px 2px 0 0; /* Positions it back where it should be */ + border-left: 1px; } -.menu li.has_submenu.selected > img.toggle, .menu li:hover.has_submenu > img.toggle { +.menu li.has_submenu.selected > img.toggle, +.menu li:hover.has_submenu > img.toggle { visibility: visible; z-index: 1; /* Positions it on top of the rest */ } - +.menu li.submenu_selected a { + font-weight: bold; +} .menu li.links { background: #E9F3D2 url(../../images/link.png) no-repeat 4px 8px; border-width: 1px 0 0 1px; border-style: solid; border-color: #dadbdc; } + /* Icons specified here */ #icon_oper-agents { background: #E9F3D2 url(../../images/bricks.png) no-repeat 4px 4px; @@ -148,4 +155,4 @@ } #icon_oper-inventory { background: #E9F3D2 url(../../images/page_white_text.png) no-repeat 4px 4px; -} \ No newline at end of file +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index ee014cca09..725ac8c4a0 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -719,19 +719,6 @@ a.big_data { border-bottom: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; } -.left { - float: left; - text-align: left; -} -.right { - float: right; - text-align: right; -} -.top { - vertical-align: top; - margin-top: 0; - padding-top: 0; -} ul { list-style-type: none; padding-left: 0; @@ -755,7 +742,9 @@ select#template, select#action { input[type=image] { border:0px; } -table#simple select#id_module_type { +table#simple select#id_module_type, +table#alert_search select#id_agent, +table#alert_search select#id_group { width: 200px; } table#simple select#select_snmp_oid, @@ -770,6 +759,100 @@ table#simple select#prediction_module { .clickable { cursor: pointer; } -table#agent_list tr { +table#agent_list tr, table.alert_list tr { vertical-align: top; } +ul.actions_list { + list-style-image: url(../../images/arrow.png); + list-style-position: inside; + margin-top: 0; +} +div.loading { + background-color: #FFF1A8; + margin-left: auto; + margin-right: auto; + padding: 5px; + text-align: center; + font-style: italic; + width: 95%; +} +div.loading img { + float: right; +} +/* Tablesorter jQuery pager */ +div.pager { + margin-left: 10px; + margin-top: 5px; +} +div.pager img{ + position: relative; + top: 4px; + padding-left: 5px; +} +div.pager input { + padding-left: 5px; +} +.pagedisplay { + border: 0; + width: 35px; +} +/* Steps style */ +ol.steps { + margin-bottom: 15px; + padding: 0; + list-style-type: none; + list-style-position: outline; +} +ol.steps li { + float: left; + background-color: #efefef; + padding: 5px; + margin-left: 5px; + width: 150px; +} +ol.steps li a { + color: #000; +} +ol.steps li.visited a { + color: #999; +} +ol.steps li span { + font-weight: normal; + display: block; +} +ol.steps li span { + color: #777; +} +ol.steps li.visited span { + color: #999; +} +ol.steps li.current { + border-left: 5px solid #778866; + margin-left: 0; + font-weight: bold; + background-color: #E9F3D2; +} +ol.steps li.visited { + color: #999 !important; +} + +/* Common useful styles */ +.left { clear: left; } +.right { clear: right; } +.clear { clear:both; } +.top { + vertical-align: top; + margin-top: 0; + padding-top: 0; +} +img.left { + margin-right:1em; + margin-bottom:1.8em; +} +img.right { + margin-left:1em; + margin-bottom:1.8em; +} +.text-right { + text-align:right; +} diff --git a/pandora_console/index.php b/pandora_console/index.php index b9124b2c42..aa796c3da4 100644 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -53,13 +53,13 @@ if ($develop_bypass != 1) { } } -if ((! file_exists("include/config.php")) || (! is_readable("include/config.php"))) { +if ((! file_exists ("include/config.php")) || (! is_readable ("include/config.php"))) { include ("general/error_noconfig.php"); exit; } // Real start -session_start(); +session_start (); require_once ("include/config.php"); require_once ("include/functions.php"); require_once ("include/functions_db.php"); @@ -99,17 +99,19 @@ if (!empty ($config["https"]) && empty ($_SERVER['HTTPS'])) { echo ''; -ob_start ('process_page_head'); //This starts the page head. In the call back function, things from $page['head'] array will be processed into the head + //This starts the page head. In the call back function, things from $page['head'] array will be processed into the head +ob_start ('process_page_head'); // Pure mode (without menu, header and footer). -$config["pure"] = (bool) get_parameter ("pure", 0); +$config["pure"] = (bool) get_parameter ("pure"); // Auto Refresh page (can now be disabled anywhere in the script) -$config["refr"] = (int) get_parameter ("refr", 0); +$config["refr"] = (int) get_parameter ("refr"); enterprise_include ('index.php'); enterprise_hook ('load_html_header'); -echo ''; //This tag is included in the buffer passed to process_page_head so technically it can be stripped +//This tag is included in the buffer passed to process_page_head so technically it can be stripped +echo ''; ob_start ('process_page_body'); @@ -137,10 +139,9 @@ if (! isset ($_SESSION['id_usuario']) && isset ($_GET["loginhash"])) { audit_db ("system", $REMOTE_ADDR, "Logon Failed (loginhash", ""); exit; } -} - -// Login process -elseif (! isset ($_SESSION['id_usuario']) && isset ($_GET["login"])) { +} elseif (! isset ($_SESSION['id_usuario']) && isset ($_GET["login"])) { + // Login process + $config["auth_error"] = ""; //Set this to the error message from the authorization mechanism $nick = get_parameter_post ("nick"); //This is the variable with the login $pass = get_parameter_post ("pass"); //This is the variable with the password @@ -187,7 +188,7 @@ if (isset ($_GET["bye"])) { // http://es2.php.net/manual/en/ref.session.php#64525 // Session locking concurrency speedup! -session_write_close(); +session_write_close (); // Header if ($config["pure"] == 0) { @@ -219,7 +220,7 @@ if ($page != "") { } } } else { - echo '
    '.__('Sorry! I can\'t find the page!').''; + echo '
    '.__('Sorry! I can\'t find the page!').''; } } else { if (enterprise_hook ('load_logon_ok') === ENTERPRISE_NOT_HOOK) { @@ -241,6 +242,6 @@ if ($config["pure"] == 0) { echo ''; } echo ''; //container div -while (@ob_end_flush()); +while (@ob_end_flush ()); echo ''; -?> \ No newline at end of file +?> diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 0443ef825b..4adb7ba534 100644 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -54,13 +54,13 @@ if (isset ($_GET["id_agente"])) { } $alerts_simple = get_agent_alerts_simple ($id_agent, $filter); - $alerts_combined = get_agent_alerts_combined ($id_agent, $filter); + $alerts_combined = get_agent_alerts_compound ($id_agent, $filter); $print_agent = false; } else { - if (give_acl ($config["id_user"], $id_group, "AR") == 0) { + if (! give_acl ($config["id_user"], $id_group, "AR")) { audit_db ($config["id_user"], $config["remote_addr"], "ACL Violation","Trying to access alert view"); require ("general/noaccess.php"); - exit; + return; } $alerts_simple = array (); @@ -70,7 +70,7 @@ if (isset ($_GET["id_agente"])) { foreach ($agents as $id_agent) { $simple = get_agent_alerts_simple ($id_agent, $filter); - $combined = get_agent_alerts_combined ($id_agent, $filter); + $combined = get_agent_alerts_compound ($id_agent, $filter); $alerts_simple = array_merge ($alerts_simple, $simple); $alerts_combined = array_merge ($alerts_combined, $combined); @@ -88,9 +88,13 @@ echo "

    ".__('Pandora Agents')." > ".__('Alerts').'

    '; if (get_parameter ('alert_validate')) { $ids = (array) get_parameter_post ("validate", array ()); - if (! empty ($ids)) { + $compound_ids = (array) get_parameter_post ("validate_compound", array ()); + + if (! empty ($ids) || ! empty ($compound_ids)) { require_once ("include/functions_alerts.php"); - $result = validate_alert_agent_module ($ids); + $result1 = validate_alert_agent_module ($ids); + $result2 = validate_alert_compound ($compound_ids); + $result == $result1 || $result2; print_error_message ($result, __('Alert(s) validated'), __('Error processing alert(s)')); @@ -159,7 +163,7 @@ foreach ($alerts_simple as $alert) { continue; } $printed++; - array_push ($table->data, format_alert_row ($alert, 0, $print_agent, $url)); + array_push ($table->data, format_alert_row ($alert, false, $print_agent, $url)); } if (!empty ($table->data)) { @@ -169,8 +173,9 @@ if (!empty ($table->data)) { echo '
    '.__('No simple alerts found').'
    '; } -$table->title = __('Combined alerts'); +$table->title = __('Compound alerts'); $table->head[1] = __('Agent'); +$table->head[2] = __('Name'); $table->data = array (); $combined_total = 0; @@ -181,7 +186,7 @@ foreach ($alerts_combined as $alert) { continue; } $combined_printed++; - array_push ($table->data, format_alert_row ($alert, 1, $print_agent)); + array_push ($table->data, format_alert_row ($alert, true, $print_agent)); } if (!empty ($table->data)) { @@ -205,8 +210,7 @@ $(document).ready (function () { $("a.template_details").cluetip ({ arrows: true, attribute: 'href', - cluetipClass: 'default', - fx: { open: 'fadeIn', openSpeed: 'slow' }, + cluetipClass: 'default' }).click (function () { return false; }); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index d417ee0a3a..2aad030eff 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -284,11 +284,58 @@ CREATE TABLE IF NOT EXISTS `talert_template_module_actions` ( ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE IF NOT EXISTS `tcompound_alert` ( +CREATE TABLE IF NOT EXISTS `talert_compound` ( `id` int(10) unsigned NOT NULL auto_increment, - `id_aam` int(10) unsigned NOT NULL default '0', + `name` varchar(255) default '', + `description` mediumtext, + `id_agent` int(10) unsigned NOT NULL, + `time_threshold` int(10) NOT NULL default '0', + `max_alerts` int(4) unsigned NOT NULL default '1', + `min_alerts` int(4) unsigned NOT NULL default '0', + `time_from` time default '00:00:00', + `time_to` time default '00:00:00', + `monday` tinyint(1) default 1, + `tuesday` tinyint(1) default 1, + `wednesday` tinyint(1) default 1, + `thursday` tinyint(1) default 1, + `friday` tinyint(1) default 1, + `saturday` tinyint(1) default 1, + `sunday` tinyint(1) default 1, + `recovery_notify` tinyint(1) default '0', + `field2_recovery` varchar(255) NOT NULL default '', + `field3_recovery` mediumtext NOT NULL, + `internal_counter` int(4) default '0', + `last_fired` bigint(20) NOT NULL default '0', + `last_reference` bigint(20) NOT NULL default '0', + `times_fired` int(3) NOT NULL default '0', + `disabled` tinyint(1) default '0', + `priority` tinyint(4) default '0', + PRIMARY KEY (`id`), + FOREIGN KEY (`id_agent`) REFERENCES tagente(`id_agente`) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `talert_compound_elements` ( + `id_alert_compound` int(10) unsigned NOT NULL, + `id_alert_template_module` int(10) unsigned NOT NULL, `operation` enum('NOP', 'AND','OR','XOR','NAND','NOR','NXOR'), - PRIMARY KEY (`id`, `id_aam`) + `order` tinyint(2) unsigned default 0, + UNIQUE (`id_alert_compound`, `id_alert_template_module`, `operation`), + FOREIGN KEY (`id_alert_compound`) REFERENCES talert_compound(`id`) + ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (`id_alert_template_module`) REFERENCES talert_template_modules(`id`) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `talert_compound_actions` ( + `id_alert_compound` 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, + FOREIGN KEY (`id_alert_compound`) REFERENCES talert_compound(`id`) + ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`) + ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- Priority : 0 - Maintance (grey) diff --git a/pandora_console/pandoradb_migrate_20_to_21.sql b/pandora_console/pandoradb_migrate_20_to_21.sql index 13c8a12160..d8433bec54 100644 --- a/pandora_console/pandoradb_migrate_20_to_21.sql +++ b/pandora_console/pandoradb_migrate_20_to_21.sql @@ -181,3 +181,58 @@ ALTER TABLE `tusuario` ADD `middlename` VARCHAR( 255 ) NOT NULL AFTER `lastna ALTER TABLE `tusuario` CHANGE `direccion` `email` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL; ALTER TABLE `tusuario` CHANGE `telefono` `phone` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL; ALTER TABLE `tusuario` CHANGE `nivel` `is_admin` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'; + + +CREATE TABLE IF NOT EXISTS `talert_compound` ( + `id` int(10) unsigned NOT NULL auto_increment, + `name` varchar(255) default '', + `description` mediumtext, + `id_agent` int(10) unsigned NOT NULL, + `time_threshold` int(10) NOT NULL default '0', + `max_alerts` int(4) unsigned NOT NULL default '1', + `min_alerts` int(4) unsigned NOT NULL default '0', + `time_from` time default '00:00:00', + `time_to` time default '00:00:00', + `monday` tinyint(1) default 1, + `tuesday` tinyint(1) default 1, + `wednesday` tinyint(1) default 1, + `thursday` tinyint(1) default 1, + `friday` tinyint(1) default 1, + `saturday` tinyint(1) default 1, + `sunday` tinyint(1) default 1, + `recovery_notify` tinyint(1) default '0', + `field2_recovery` varchar(255) NOT NULL default '', + `field3_recovery` mediumtext NOT NULL, + `internal_counter` int(4) default '0', + `last_fired` bigint(20) NOT NULL default '0', + `last_reference` bigint(20) NOT NULL default '0', + `times_fired` int(3) NOT NULL default '0', + `disabled` tinyint(1) default '0', + `priority` tinyint(4) default '0', + PRIMARY KEY (`id`), + FOREIGN KEY (`id_agent`) REFERENCES tagente(`id_agente`) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `talert_compound_elements` ( + `id_alert_compound` int(10) unsigned NOT NULL, + `id_alert_template_module` int(10) unsigned NOT NULL,:w + `operation` enum('NOP', 'AND','OR','XOR','NAND','NOR','NXOR'), + `order` tinyint(2) unsigned default 0, + UNIQUE (`id_alert_compound`, `id_alert_template_module`, `operation`), + FOREIGN KEY (`id_alert_compound`) REFERENCES talert_compound(`id`) + ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (`id_alert_template_module`) REFERENCES talert_template_modules(`id`) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `talert_compound_actions` ( + `id_alert_compound` 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, + FOREIGN KEY (`id_alert_compound`) REFERENCES talert_compound(`id`) + ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8;