diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f7dfdf30fb..0e484b4f1f 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,20 @@ +2013-01-03 Miguel de Dios + + * extensions/resource_registration.php, + extensions/resource_exportation.php, + operation/events/event_statistics.php, + operation/events/events_list.php, + operation/reporting/reporting_viewer.php, + godmode/reporting/reporting_builder.php, + godmode/reporting/reporting_builder.item_editor.php, + include/functions_alerts.php, include/functions_reports.php, + include/functions_events.php, include/graphs/fgraph.php, + include/functions_graph.php, include/styles/pandora.css, + include/functions_reporting.php, include/functions_agents.php: a lot + of changes and fixes from the branch for the reports. + + MERGED FROM PANDORA_4.0 + 2013-01-02 Juan Manuel Ramon * extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql diff --git a/pandora_console/extensions/resource_exportation.php b/pandora_console/extensions/resource_exportation.php index 6c3ab94c97..fa4f3cff06 100644 --- a/pandora_console/extensions/resource_exportation.php +++ b/pandora_console/extensions/resource_exportation.php @@ -209,6 +209,8 @@ function output_xml_report($id) { break; case 'alert_report_agent': break; + case 'alert_report_group': + break; case 'url': echo ""; break; diff --git a/pandora_console/extensions/resource_registration.php b/pandora_console/extensions/resource_registration.php index 3872449f17..0a77928765 100644 --- a/pandora_console/extensions/resource_registration.php +++ b/pandora_console/extensions/resource_registration.php @@ -173,7 +173,7 @@ function process_upload_xml_report($xml, $group_filter = 0) { case 'simple_baseline_graph': break; case 2: - case 'custom_graph': + case 'custom_graph': case 'automatic_custom_graph': $group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($item['graph'])); $values['id_gs'] = $group; @@ -301,6 +301,8 @@ function process_upload_xml_report($xml, $group_filter = 0) { break; case 'alert_report_agent': break; + case 'alert_report_group': + break; case 'url': $values["external_source"] = io_safe_input($item['url']); break; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 42af5feb12..f64b96cae0 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -78,6 +78,16 @@ $sla_sorted_by = 0; $id_agents = ''; $inventory_modules = array(); $date = null; + +//Added for events items +$filter_event_validated = false; +$filter_event_critical = false; +$filter_event_warning = false; + +$event_graph_by_agent = false; +$event_graph_by_user_validator = false; +$event_graph_by_criticity = false; +$event_graph_validated_vs_unvalidated = false; $netflow_filter = 0; $max_values = 0; $resolution = 0; @@ -85,7 +95,6 @@ $resolution = 0; switch ($action) { case 'new': $actionParameter = 'save'; - $type = get_parameter('type', 'SLA'); $description = null; $sql = null; @@ -93,10 +102,10 @@ switch ($action) { $show_in_landscape = 0; $server_name = ''; break; - case 'save': + case 'save': default: - $actionParameter = 'update'; - + $actionParameter = 'update'; + // If we are creating a new report item then clean interface and display creation view $type = get_parameter('type', 'SLA'); switch ($type) { @@ -118,11 +127,11 @@ switch ($action) { $server_name = ''; $get_data_editor = false; break; - } - + } + // Get data to fill editor if type is not SLA, top_n, exception, general if ($get_data_editor) { - + $item = db_get_row_filter('treport_content', array('id_rc' => $idItem)); $server_name = $item ['server_name']; @@ -308,15 +317,40 @@ switch ($action) { $idAgent = db_get_value_filter('id_agente', 'tagente_modulo', array('id_agente' => $item['id_agent'])); $period = $item['period']; break; + case 'alert_report_group': + $description = $item['description']; + $period = $item['period']; + $group = $item['id_group']; + break; case 'event_report_agent': $description = $item['description']; $idAgent = $item['id_agent']; $period = $item['period']; + + //Added for events items + $filter_event_validated = $style['filter_event_validated']; + $filter_event_critical = $style['filter_event_critical']; + $filter_event_warning = $style['filter_event_warning']; + + $event_graph_by_agent = $style['event_graph_by_agent']; + $event_graph_by_user_validator = $style['event_graph_by_user_validator']; + $event_graph_by_criticity = $style['event_graph_by_criticity']; + $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; break; case 'event_report_group': $description = $item['description']; $period = $item['period']; $group = $item['id_group']; + + //Added for events items + $filter_event_validated = $style['filter_event_validated']; + $filter_event_critical = $style['filter_event_critical']; + $filter_event_warning = $style['filter_event_warning']; + + $event_graph_by_agent = $style['event_graph_by_agent']; + $event_graph_by_user_validator = $style['event_graph_by_user_validator']; + $event_graph_by_criticity = $style['event_graph_by_criticity']; + $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; break; case 'event_report_module': $description = $item['description']; @@ -333,6 +367,7 @@ switch ($action) { $show_graph = $item['show_graph']; break; case 'group_report': + $description = $item['description']; $group = $item['id_group']; break; case 'top_n': @@ -364,6 +399,9 @@ switch ($action) { $date = $es['date']; $inventory_modules = $es['inventory_modules']; $id_agents = $es['id_agents']; + + $idAgent = $es['id_agents']; + $idAgentModule = $inventory_modules; break; case 'inventory_changes': $period = $item['period']; @@ -511,7 +549,7 @@ html_print_input_hidden('id_item', $idItem); html_print_input_text('max_interval', $max_interval, '', 5, 10); echo " " . __('Min') . " "; html_print_input_text('min_interval', $min_interval, '', 5, 10); - ?> + ?> @@ -548,7 +586,8 @@ html_print_input_hidden('id_item', $idItem); - + @@ -618,7 +657,7 @@ html_print_input_hidden('id_item', $idItem); if ($agent_name_temp === false) $agent_name_temp = array(); - + $result_select = array(); foreach ($agent_name_temp as $module_element) { $result_select[$module_element['id_agente_modulo']] = $module_element['nombre']; @@ -652,7 +691,7 @@ html_print_input_hidden('id_item', $idItem); if ((empty($agents)) || $agents == -1) $agents = array(); $agents_select = array(); - foreach($agents as $a) { + foreach ($agents as $a) { $agents_select[$a['id_agente']] = $a['nombre']; } html_print_select($agents_select, 'id_agents[]', $id_agents, $script = '', __('All'), -1, false, true, true, '', false, "min-width: 180px"); @@ -664,7 +703,13 @@ html_print_input_hidden('id_item', $idItem); 0); + } + else { + $array_inventory_modules = implode(',', $inventory_modules); + } + html_print_input_hidden('inventory_modules_selected', $array_inventory_modules); ?> @@ -672,8 +717,11 @@ html_print_input_hidden('id_item', $idItem); + + + + + + + + + + + + + - + + + @@ -1527,7 +1609,7 @@ function addGeneralRow() { $(".delete_button", row).attr('href', 'javascript: deleteGeneralRow(' + data['id'] + ');'); $("#list_general").append($(row).html()); - + $("input[name=id_agent_general]").val(''); $("input[name=server_name_general]").val(''); $("input[name=agent_general]").val(''); @@ -1584,6 +1666,8 @@ function chooseType() { $("#row_date").hide(); $("#row_agent_multi").hide(); $("#row_module_multi").hide(); + $("#row_event_filter").hide(); + $("#row_event_graphs").hide(); $("#row_netflow_filter").hide(); $("#row_max_values").hide(); $("#row_resolution").hide(); @@ -1595,6 +1679,8 @@ function chooseType() { $("#row_servers").show(); $("#row_group").show(); $("#row_show_in_two_columns").show(); + $("#row_event_filter").show(); + $("#row_event_graphs").show(); break; case 'simple_graph': case 'simple_baseline_graph': @@ -1622,7 +1708,7 @@ function chooseType() { $("#row_interval").show(); $("#row_show_in_two_columns").show(); break; - case 'custom_graph': + case 'custom_graph': case 'automatic_custom_graph': $("#row_description").show(); $("#row_period").show(); @@ -1772,6 +1858,12 @@ function chooseType() { $("#row_period").show(); $("#row_show_in_two_columns").show(); break; + case 'alert_report_group': + $("#row_description").show(); + $("#row_period").show(); + $("#row_show_in_two_columns").show(); + $("#row_group").show(); + break; case 'alert_report_agent': $("#row_description").show(); $("#row_agent").show(); @@ -1783,6 +1875,8 @@ function chooseType() { $("#row_agent").show(); $("#row_period").show(); $("#row_show_in_two_columns").show(); + $("#row_event_filter").show(); + $("#row_event_graphs").show(); break; case 'event_report_module': $("#row_description").show(); @@ -1803,6 +1897,7 @@ function chooseType() { case 'group_report': $("#row_group").show(); $("#row_servers").show(); + $("#row_description").show(); break; case 'top_n': $("#row_description").show(); @@ -1874,7 +1969,8 @@ function chooseType() { updateInventoryDates(); }); - updateInventoryDates(); + if (!$("#hidden-date_selected").val()) + updateInventoryDates(); break; case 'inventory_changes': break; diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 4e7318f553..c12e434e35 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -382,6 +382,7 @@ switch ($action) { } foreach ($reports as $report) { + if (!is_user_admin ($config["id_user"])){ if ($report["private"] && $report["id_user"] != $config['id_user']) if (!check_acl ($config["id_user"], $report["id_group"], "RR")) @@ -414,7 +415,7 @@ switch ($action) { $next = 6; } - + if ($report["private"] == 1) $data[$next] = __('Yes'); else @@ -462,10 +463,10 @@ switch ($action) { } html_print_table ($table); } - + if (check_acl ($config['id_user'], 0, "RW")) { echo '
'; - echo '
'; + echo '
'; html_print_submit_button (__('Create report'), 'create', false, 'class="sub next"'); echo "
"; echo ""; @@ -485,7 +486,8 @@ switch ($action) { break; case 'item_editor': $resultOperationDB = null; - $report = db_get_row_filter('treport', array('id_report' => $idReport)); + $report = db_get_row_filter('treport', + array('id_report' => $idReport)); $reportName = $report['name']; $idGroupReport = $report['id_group']; @@ -658,7 +660,7 @@ switch ($action) { $values['top_n_value'] = get_parameter('max_values'); $good_format = true; break; - default: + default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('radiobutton_max_min_avg',0); $values['top_n_value'] = get_parameter('quantity'); @@ -705,6 +707,14 @@ switch ($action) { $resultOperationDB = false; break; } + $filter_event_validated = get_parameter('filter_event_validated', 0); + $filter_event_critical = get_parameter('filter_event_critical', 0); + $filter_event_warning = get_parameter('filter_event_warning', 0); + + $event_graph_by_agent = get_parameter('event_graph_by_agent', 0); + $event_graph_by_user_validator = get_parameter('event_graph_by_user_validator', 0); + $event_graph_by_criticity = get_parameter('event_graph_by_criticity', 0); + $event_graph_validated_vs_unvalidated = get_parameter('event_graph_validated_vs_unvalidated', 0); // If metaconsole is activated if ($config['metaconsole'] == 1 && defined('METACONSOLE')) { @@ -732,8 +742,9 @@ switch ($action) { // Will update server_name variable $values['server_name'] = trim($server_name); $agent_name = substr($agent_name_server, 0, $separator_pos); - + } + } } @@ -757,9 +768,25 @@ switch ($action) { $style = array(); $style['show_in_two_columns'] = get_parameter('show_in_two_columns', 0); $style['show_in_landscape'] = get_parameter('show_in_landscape', 0); + + switch ($values['type']) { + case 'event_report_agent': + case 'event_report_group': + //Added for events items + $style['filter_event_validated'] = $filter_event_validated; + $style['filter_event_critical'] = $filter_event_critical; + $style['filter_event_warning'] = $filter_event_warning; + + $style['event_graph_by_agent'] = $event_graph_by_agent; + $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; + $style['event_graph_by_criticity'] = $event_graph_by_criticity; + $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; + break; + } + $values['style'] = io_safe_input(json_encode($style)); - if ($good_format){ + if ($good_format) { $resultOperationDB = db_process_sql_update('treport_content', $values, array('id_rc' => $idItem)); } else{ @@ -856,7 +883,7 @@ switch ($action) { break; case "oracle": $only_display_wrong_tmp = get_parameter('checkbox_only_display_wrong'); - if (empty($only_display_wrong_tmp)){ + if (empty($only_display_wrong_tmp)) { $values['only_display_wrong'] = 0; } else{ @@ -932,10 +959,35 @@ switch ($action) { $style = array(); $style['show_in_two_columns'] = get_parameter('show_in_two_columns', 0); $style['show_in_landscape'] = get_parameter('show_in_landscape', 0); + + switch ($values['type']) { + case 'event_report_agent': + case 'event_report_group': + $filter_event_validated = get_parameter('filter_event_validated', 0); + $filter_event_critical = get_parameter('filter_event_critical', 0); + $filter_event_warning = get_parameter('filter_event_warning', 0); + + $event_graph_by_agent = get_parameter('event_graph_by_agent', 0); + $event_graph_by_user_validator = get_parameter('event_graph_by_user_validator', 0); + $event_graph_by_criticity = get_parameter('event_graph_by_criticity', 0); + $event_graph_validated_vs_unvalidated = get_parameter('event_graph_validated_vs_unvalidated', 0); + //Added for events items + $style['filter_event_validated'] = $filter_event_validated; + $style['filter_event_critical'] = $filter_event_critical; + $style['filter_event_warning'] = $filter_event_warning; + + $style['event_graph_by_agent'] = $event_graph_by_agent; + $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; + $style['event_graph_by_criticity'] = $event_graph_by_criticity; + $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; + break; + } + $values['style'] = io_safe_input(json_encode($style)); if ($good_format) { - $result = db_process_sql_insert('treport_content', $values); + $result = db_process_sql_insert( + 'treport_content', $values); if ($result === false) { $resultOperationDB = false; @@ -945,13 +997,17 @@ switch ($action) { switch ($config["dbtype"]) { case "mysql": - $max = db_get_all_rows_sql('SELECT max(`order`) AS max - FROM treport_content WHERE id_report = ' . $idReport . ';'); + $max = db_get_all_rows_sql( + 'SELECT max(`order`) AS max + FROM treport_content + WHERE id_report = ' . $idReport . ';'); break; case "postgresql": case "oracle": - $max = db_get_all_rows_sql('SELECT max("order") AS max - FROM treport_content WHERE id_report = ' . $idReport); + $max = db_get_all_rows_sql( + 'SELECT max("order") AS max + FROM treport_content + WHERE id_report = ' . $idReport); break; } if ($max === false) { @@ -980,7 +1036,6 @@ switch ($action) { } break; default: - if ($enterpriseEnable and $activeTab != 'advanced') { $resultOperationDB = reporting_enterprise_update_action(); } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 47855fd545..703720d798 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -42,6 +42,17 @@ function agents_check_agent_exists($id_agent, $show_disabled = true) { } } +/** + * Get agent id from a module id that it has. + * + * @param int $id_module Id module is list modules this agent. + * + * @return int Id from the agent of the given id module. + */ +function agents_get_agent_id_by_module_id ($id_agente_modulo) { + return (int) db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_agente_modulo); +} + /** * Creates an agent * diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 7c54651a6f..f4dce8a0eb 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1699,6 +1699,7 @@ function get_agent_alert_fired ($id_agent, $id_alert, $period, $date = 0) { * @return array An array with all the events happened. */ function get_module_alert_fired ($id_agent_module, $id_alert, $period, $date = 0) { + if (!is_numeric ($date)) { $date = strtotime ($date); } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 73b8dec1ed..c9c16e023c 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -170,7 +170,7 @@ function events_get_similar_ids ($id) { function events_delete_event ($id_event, $similar = true, $meta = false) { global $config; - if($meta) { + if ($meta) { $table_event = 'tmetaconsole_event'; } else { @@ -190,22 +190,22 @@ function events_delete_event ($id_event, $similar = true, $meta = false) { $errors = 0; - foreach ($id_event as $event) { - if($meta) { + foreach ($id_event as $event) { + if ($meta) { $event_group = events_meta_get_group ($event); } else { $event_group = events_get_group ($event); } - if (check_acl ($config["id_user"], $event_group, "EM") == 0) { + if (check_acl ($config["id_user"], $event_group, "EM") == 0) { //Check ACL db_pandora_audit("ACL Violation", "Attempted deleting event #".$event); $errors++; } else { $ret = db_process_sql_delete($table_event, array('id_evento' => $event)); - + if(!$ret) { $errors++; } @@ -221,7 +221,8 @@ function events_delete_event ($id_event, $similar = true, $meta = false) { if ($errors > 0) { return false; - } else { + } + else { return true; } } @@ -239,7 +240,7 @@ function events_delete_event ($id_event, $similar = true, $meta = false) { function events_validate_event ($id_event, $similars = true, $new_status = 1, $meta = false) { global $config; - if($meta) { + if ($meta) { $table_event = 'tmetaconsole_event'; } else { @@ -249,7 +250,7 @@ function events_validate_event ($id_event, $similars = true, $new_status = 1, $m //Cleans up the selection for all unwanted values also casts any single values as an array $id_event = (array) safe_int ($id_event, 1); - if($new_status) { + if ($new_status) { $ack_utimestamp = time(); $ack_user = $config['id_user']; } @@ -266,7 +267,7 @@ function events_validate_event ($id_event, $similars = true, $new_status = 1, $m $id_event = array_unique($id_event); } - switch($new_status) { + switch ($new_status) { case 0: $status_string = 'New'; break; @@ -288,7 +289,7 @@ function events_validate_event ($id_event, $similars = true, $new_status = 1, $m $alerts = array(); foreach ($id_event as $event) { - if($meta) { + if ($meta) { $event_group = events_meta_get_group ($event); $event = events_meta_get_event ($event); $server_id = $event['server_id']; @@ -312,7 +313,7 @@ function events_validate_event ($id_event, $similars = true, $new_status = 1, $m 'estado' => $new_status, 'id_usuario' => $ack_user, 'ack_utimestamp' => $ack_utimestamp); - + $ret = db_process_sql_update($table_event, $values, array('id_evento' => $event), 'AND', false); @@ -324,13 +325,13 @@ function events_validate_event ($id_event, $similars = true, $new_status = 1, $m db_process_sql_commit (); - if($meta && !empty($alerts)) { + if ($meta && !empty($alerts)) { $server = metaconsole_get_connection_by_id ($server_id); metaconsole_connect($server); } - + // Put the alerts in standby or not depends the new status - foreach($alerts as $alert) { + foreach ($alerts as $alert) { switch($new_status) { case EVENT_NEW: case EVENT_VALIDATE: @@ -342,7 +343,7 @@ function events_validate_event ($id_event, $similars = true, $new_status = 1, $m } } - if($meta && !empty($alerts)) { + if ($meta && !empty($alerts)) { metaconsole_restore_db(); } @@ -362,7 +363,7 @@ function events_validate_event ($id_event, $similars = true, $new_status = 1, $m function events_change_status ($id_event, $new_status, $meta) { global $config; - if($meta) { + if ($meta) { $event_table = 'tmetaconsole_event'; } else { @@ -373,7 +374,7 @@ function events_change_status ($id_event, $new_status, $meta) { $id_event = (array) safe_int ($id_event, 1); // Update ack info if the new status is validated - if($new_status == EVENT_STATUS_VALIDATED) { + if ($new_status == EVENT_STATUS_VALIDATED) { $ack_utimestamp = time(); $ack_user = $config['id_user']; } @@ -396,9 +397,9 @@ function events_change_status ($id_event, $new_status, $meta) { $status_string = ''; break; } - + $alerts = array(); - + foreach ($id_event as $k => $id) { if($meta) { $event_group = events_meta_get_group ($id); @@ -421,7 +422,7 @@ function events_change_status ($id_event, $new_status, $meta) { } } - if(empty($id_event)) { + if (empty($id_event)) { return false; } @@ -439,14 +440,14 @@ function events_change_status ($id_event, $new_status, $meta) { events_comment($id_event, '', "Change status to $status_string"); - if($meta && !empty($alerts)) { + if ($meta && !empty($alerts)) { $server = metaconsole_get_connection_by_id ($server_id); metaconsole_connect($server); } - + // Put the alerts in standby or not depends the new status - foreach($alerts as $alert) { - switch($new_status) { + foreach ($alerts as $alert) { + switch ($new_status) { case EVENT_NEW: case EVENT_VALIDATE: alerts_agent_module_standby ($alert, 0); @@ -457,7 +458,7 @@ function events_change_status ($id_event, $new_status, $meta) { } } - if($meta && !empty($alerts)) { + if ($meta && !empty($alerts)) { metaconsole_restore_db(); } @@ -477,7 +478,7 @@ function events_change_status ($id_event, $new_status, $meta) { function events_change_owner ($id_event, $new_owner = false, $force = false, $meta = false) { global $config; - if($meta) { + if ($meta) { $event_table = 'tmetaconsole_event'; } else { @@ -486,7 +487,7 @@ function events_change_owner ($id_event, $new_owner = false, $force = false, $me //Cleans up the selection for all unwanted values also casts any single values as an array $id_event = (array) safe_int ($id_event, 1); - + foreach ($id_event as $k => $id) { if($meta) { $event_group = events_meta_get_group ($id); @@ -515,7 +516,7 @@ function events_change_owner ($id_event, $new_owner = false, $force = false, $me } $values = array('owner_user' => $new_owner); - + $where = array('id_evento' => $id_event); // If not force, add to where if owner_user <> '' @@ -529,7 +530,7 @@ function events_change_owner ($id_event, $new_owner = false, $force = false, $me if (($ret === false) || ($ret === 0)) { return false; } - + return true; } @@ -545,8 +546,8 @@ function events_change_owner ($id_event, $new_owner = false, $force = false, $me */ function events_comment ($id_event, $comment = '', $action = 'Added comment', $meta = false) { global $config; - - if($meta) { + + if ($meta) { $event_table = 'tmetaconsole_event'; } else { @@ -557,7 +558,7 @@ function events_comment ($id_event, $comment = '', $action = 'Added comment', $m $id_event = (array) safe_int ($id_event, 1); foreach ($id_event as $k => $id) { - if($meta) { + if ($meta) { $event_group = events_meta_get_group ($id); } else { @@ -570,13 +571,13 @@ function events_comment ($id_event, $comment = '', $action = 'Added comment', $m } } - if(empty($id_event)) { + if (empty($id_event)) { return false; } // If the event hasn't owner, assign the user as owner events_change_owner ($id_event, $similars); - + // Give old ugly format to comment. TODO: Change this method for aux table or json $comment = str_replace(array("\r\n", "\r", "\n"), '
', $comment); @@ -587,32 +588,32 @@ function events_comment ($id_event, $comment = '', $action = 'Added comment', $m $commentbox = ''; } - $comment = '-- ' . $action . ' by '.$config['id_user'].' '.'['.date ($config["date_format"]).'] --
'.$commentbox.'
'; + $comment = '-- ' . $action . ' ' . __('by') . ' '.$config['id_user'].' '.'['.date ($config["date_format"]).'] --
'.$commentbox.'
'; // Update comment switch ($config['dbtype']) { // Oldstyle SQL to avoid innecesary PHP foreach case 'mysql': $sql_validation = "UPDATE $event_table - SET user_comment = concat('" . $comment . "', user_comment) - WHERE id_evento in (" . implode(',', $id_event) . ")"; - - $ret = db_process_sql($sql_validation); - break; + SET user_comment = concat('" . $comment . "', user_comment) + WHERE id_evento in (" . implode(',', $id_event) . ")"; + + $ret = db_process_sql($sql_validation); + break; case 'postgresql': case 'oracle': $sql_validation = "UPDATE $event_table - SET user_comment='" . $comment . "' || user_comment) - WHERE id_evento in (" . implode(',', $id_event) . ")"; - - $ret = db_process_sql($sql_validation); + SET user_comment='" . $comment . "' || user_comment) + WHERE id_evento in (" . implode(',', $id_event) . ")"; + + $ret = db_process_sql($sql_validation); break; } if (($ret === false) || ($ret === 0)) { return false; } - + return true; } @@ -707,17 +708,18 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret case "oracle": if ($filter == "") { $sql = sprintf ("SELECT * FROM tevento WHERE rownum <= %d ORDER BY timestamp DESC", $limit); - } + } else { $sql = sprintf ("SELECT * FROM tevento %s AND rownum <= %d ORDER BY timestamp DESC", $filter, $limit); - } + } break; } $result = db_get_all_rows_sql ($sql); if ($result === false) { echo '
'.__('No events').'
'; - } else { + } + else { $table->cellpadding = 4; $table->cellspacing = 4; $table->width = $width; @@ -742,7 +744,7 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret $table->head[3] = __('Event name'); $table->head[4] = __('Agent name'); - + $table->head[5] = __('Timestamp'); $table->headclass[5] = "datos3 f9"; $table->align[5] = "right"; @@ -768,7 +770,7 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret $title = __('Event in process'); break; } - + $data[0] = html_print_image ($img, true, array ("class" => "image_status", "width" => 16, @@ -802,9 +804,9 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret /* Event type */ $data[2] = events_print_type_img ($event["event_type"], true); - + $data[3] = ui_print_string_substr (io_safe_output($event["evento"]), 75, true, '9'); - + if ($event["id_agente"] > 0) { // Agent name // Get class name, for the link color... @@ -821,7 +823,7 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret else { $data[4] = __('Alert')."SNMP"; } - + // Timestamp $data[5] = ui_print_timestamp ($event["timestamp"], true, array('style' => 'font-size: 7px')); @@ -983,54 +985,54 @@ function events_print_type_description ($type, $return = false) { $output = ''; switch ($type) { - case "going_unknown": - $output .= __('Going to unknown'); - break; - case "alert_recovered": - $output .= __('Alert recovered'); - break; - case "alert_manual_validation": - $output .= __('Alert manually validated'); - break; - case "going_up_warning": - $output .= __('Going from critical to warning'); - break; - case "going_down_critical": - case "going_up_critical": //This is to be backwards compatible - $output .= __('Going down to critical state'); - break; - case "going_up_normal": - case "going_down_normal": //This is to be backwards compatible - $output .= __('Going up to normal state'); - break; - case "going_down_warning": - $output .= __('Going down from normal to warning'); - break; - case "alert_fired": - $output .= __('Alert fired'); - break; - case "system"; - $output .= __('SYSTEM'); - break; - case "recon_host_detected"; - $output .= __('Recon server detected a new host'); - break; - case "new_agent"; - $output .= __('New agent created'); - break; - case "configuration_change"; - $output .= __('Configuration change'); - break; - case "alert_ceased"; - $output .= __('Alert ceased'); - break; - case "error"; - $output .= __('Error'); - break; - case "unknown": - default: - $output .= __('Unknown type:').': '.$type; - break; + case "going_unknown": + $output .= __('Going to unknown'); + break; + case "alert_recovered": + $output .= __('Alert recovered'); + break; + case "alert_manual_validation": + $output .= __('Alert manually validated'); + break; + case "going_up_warning": + $output .= __('Going from critical to warning'); + break; + case "going_down_critical": + case "going_up_critical": //This is to be backwards compatible + $output .= __('Going down to critical state'); + break; + case "going_up_normal": + case "going_down_normal": //This is to be backwards compatible + $output .= __('Going up to normal state'); + break; + case "going_down_warning": + $output .= __('Going down from normal to warning'); + break; + case "alert_fired": + $output .= __('Alert fired'); + break; + case "system"; + $output .= __('SYSTEM'); + break; + case "recon_host_detected"; + $output .= __('Recon server detected a new host'); + break; + case "new_agent"; + $output .= __('New agent created'); + break; + case "configuration_change"; + $output .= __('Configuration change'); + break; + case "alert_ceased"; + $output .= __('Alert ceased'); + break; + case "error"; + $output .= __('Error'); + break; + case "unknown": + default: + $output .= __('Unknown type:').': '.$type; + break; } if ($return) @@ -1049,24 +1051,45 @@ function events_print_type_description ($type, $return = false) { * * @return array An array with all the events happened. */ -function events_get_group_events ($id_group, $period, $date) { +function events_get_group_events ($id_group, $period, $date, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false) { global $config; - + $id_group = groups_safe_acl ($config["id_user"], $id_group, "ER"); - + if (empty ($id_group)) { //An empty array means the user doesn't have access return false; } - + $datelimit = $date - $period; - - $sql = sprintf ('SELECT * FROM tevento + + $sql_where = ' AND 1 = 1 '; + if ($filter_event_critical) { + $sql_where .= ' AND criticity = 4 '; + } + if ($filter_event_warning) { + $sql_where .= ' AND criticity = 3 '; + } + if ($filter_event_validated) { + $sql_where .= ' AND estado = 1 '; + } + + + $sql = sprintf ('SELECT *, + (SELECT t2.nombre + FROM tagente AS t2 + WHERE t2.id_agente = t3.id_agente) AS agent_name, + (SELECT t2.fullname + FROM tusuario AS t2 + WHERE t2.id_user = t3.id_usuario) AS user_name + FROM tevento AS t3 WHERE utimestamp > %d AND utimestamp <= %d - AND id_grupo IN (%s) + AND id_grupo IN (%s) ' . $sql_where . ' ORDER BY utimestamp ASC', $datelimit, $date, implode (",", $id_group)); - + return db_get_all_rows_sql ($sql); } @@ -1081,23 +1104,42 @@ function events_get_group_events ($id_group, $period, $date) { * * @return array An array with all the events happened. */ -function events_get_agent ($id_agent, $period, $date = 0) { +function events_get_agent ($id_agent, $period, $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false) { + if (!is_numeric ($date)) { $date = strtotime ($date); } if (empty ($date)) { $date = get_system_time (); } - + $datelimit = $date - $period; - - $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, - max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user - FROM tevento - WHERE id_agente = %d AND utimestamp > %d AND utimestamp <= %d + + $sql_where = ' AND 1 = 1 '; + if ($filter_event_critical) { + $sql_where .= ' AND criticity = 4 '; + } + if ($filter_event_warning) { + $sql_where .= ' AND criticity = 3 '; + } + if ($filter_event_validated) { + $sql_where .= ' AND estado = 1 '; + } + + $sql = sprintf ('SELECT id_usuario, + (SELECT t2.fullname + FROM tusuario AS t2 + WHERE t2.id_user = t3.id_usuario) AS user_name, + estado, id_agentmodule, evento, event_type, criticity, + count(*) AS count_rep, max(timestamp) AS time2 + FROM tevento as t3 + WHERE id_agente = %d AND utimestamp > %d + AND utimestamp <= %d ' . $sql_where . ' GROUP BY id_agentmodule, evento ORDER BY time2 DESC', $id_agent, $datelimit, $date); - + return db_get_all_rows_sql ($sql); } @@ -1119,14 +1161,14 @@ function events_get_module ($id_agent_module, $period, $date = 0) { if (empty ($date)) { $date = get_system_time (); } - + $datelimit = $date - $period; - + $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2 FROM tevento WHERE id_agentmodule = %d AND utimestamp > %d AND utimestamp <= %d GROUP BY id_agentmodule, evento ORDER BY time2 DESC', $id_agent_module, $datelimit, $date); - + return db_get_all_rows_sql ($sql); } @@ -1179,8 +1221,8 @@ function events_get_event_types ($type_id){ } break; } - - return $type_desc; + + return $type_desc; } @@ -1217,8 +1259,8 @@ function events_get_severity_types ($severity_id){ } break; } - - return $severity_desc; + + return $severity_desc; } /** @@ -1331,9 +1373,9 @@ function events_get_event_filter_select(){ return array(); } $sql = "SELECT id_filter, id_name FROM tevent_filter WHERE id_group IN (".implode(',', array_keys ($user_groups)).")"; - + $event_filters = db_get_all_rows_sql($sql); - + if ($event_filters === false){ return array(); } @@ -1364,7 +1406,7 @@ function events_page_responses ($event) { $table_responses->style[0] = 'width:35%; font-weight: bold; text-align: left;'; $table_responses->style[1] = 'text-align: left;'; $table_responses->class = "databox alternate"; - + if (check_acl ($config["id_user"], $event["id_grupo"], "EM") == 1) { // Owner $data = array(); @@ -1432,7 +1474,7 @@ function events_page_responses ($event) { $data = array(); $data[0] = __('Comment'); $data[1] = html_print_button(__('Add comment'),'comment_button',false,'$(\'#link_comments\').trigger(\'click\');','class="sub next"',true); - + $table_responses->data[] = $data; if (check_acl ($config["id_user"], $event["id_grupo"], "EM") == 1) { @@ -1444,7 +1486,7 @@ function events_page_responses ($event) { $data[1] .= html_print_input_hidden('delete', 1, true); $data[1] .= html_print_input_hidden('validate_ids', $event['id_evento'], true); $data[1] .= ''; - + $table_responses->data[] = $data; } @@ -1452,7 +1494,7 @@ function events_page_responses ($event) { $data = array(); $data[0] = __('Custom responses'); $event_responses = db_get_all_rows_in_table('tevent_response'); - + if(empty($event_responses)) { $data[1] .= ''.__('N/A').''; } @@ -1472,7 +1514,7 @@ function events_page_responses ($event) { $data[1] .= html_print_button(__('Execute'),'custom_response_button',false,'execute_response('.$event['id_evento'].','.$server_id.')',"class='sub next'",true); } - + $table_responses->data[] = $data; $responses_js = "