diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 02a807a337..44b3173d02 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -338,12 +338,112 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'alert_report_agent': + $report['contents'][] = reporting_alert_report_agent( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_alert_report_agent($report, $content) { + + global $config; + + $return['type'] = 'alert_report_agent'; + + if (empty($content['name'])) { + $content['name'] = __('Alert Report Agent'); + } + + $agent_name = agents_get_name($content['id_agent']); + + $return['title'] = $content['name']; + $return['subtitle'] = $agent_name; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $alerts = agents_get_alerts($content['id_agent']); + + if (isset($alerts['simple'])) { + $alerts = $alerts['simple']; + } + else { + $alerts = array(); + } + + $data = array(); + + foreach ($alerts as $alert) { + $data_row = array(); + + $data_row['disabled'] = $alert['disabled']; + + $data_row['module'] = db_get_value_filter('nombre', 'tagente_modulo', + array('id_agente_modulo' => $alert['id_agent_module'])); + $data_row['template'] = db_get_value_filter('name', 'talert_templates', + array('id' => $alert['id_alert_template'])); + + + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id IN (SELECT id_alert_action + FROM talert_template_module_actions + WHERE id_alert_template_module = ' . $alert['id_alert_template'] . ');'); + + if (!empty($actions)) { + $row = db_get_row_sql('SELECT id_alert_action + FROM talert_templates + WHERE id IN (SELECT id_alert_template + FROM talert_template_modules + WHERE id = ' . $alert['id_alert_template'] . ')'); + + $id_action = 0; + if (!empty($row)) + $id_action = $row['id_alert_action']; + + // Prevent from void action + if (empty($id_action)) + $id_action = 0; + + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id = ' . $id_action); + + if (empty($actions)) { + $actions = array(); + } + } + + $data_row['action'] = array(); + foreach ($actions as $action) { + $data_row['action'][] = $action['name']; + } + + $data_row['fired'] = array(); + $firedTimes = get_module_alert_fired( + $content['id_agent_module'], + $alert['id_alert_template'], + (int) $content['period'], + (int) $report["datetime"]); + if (empty($firedTimes)) { + $firedTimes = array(); + } + foreach ($firedTimes as $fireTime) { + $data_row['fired'][] = $fireTime['timestamp']; + } + + $data[] = $data_row; + } + + $return['data'] = $data; + + return reporting_check_structure_content($return); +} + function reporting_alert_report_module($report, $content) { global $config; @@ -354,7 +454,13 @@ function reporting_alert_report_module($report, $content) { $content['name'] = __('Alert Report Module'); } + $module_name = io_safe_output( + modules_get_agentmodule_name($content['id_agent_module'])); + $agent_name = io_safe_output( + modules_get_agentmodule_agent_name ($content['id_agent_module'])); + $return['title'] = $content['name']; + $return['subtitle'] = $agent_name . " - " . $module_name; $return["description"] = $content["description"]; $return["date"] = reporting_get_date_text($report, $content); diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 5b4e757fb7..de3b9eb209 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -212,6 +212,9 @@ function reporting_html_print_report($report, $mini = false) { case 'alert_report_module': reporting_html_alert_report_module($table, $item); break; + case 'alert_report_agent': + reporting_html_alert_report_agent($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -224,6 +227,42 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_alert_report_agent($table, $item) { + $table->colspan['alerts']['cell'] = 3; + $table->cellstyle['alerts']['cell'] = 'text-align: left;'; + + $table1->width = '99%'; + $table1->head = array (); + $table1->head['module'] = __('Module'); + $table1->head['template'] = __('Template'); + $table1->head['actions'] = __('Actions'); + $table1->head['fired'] = __('Fired'); + $table1->data = array (); + foreach ($item['data'] as $alert) { + $row = array(); + + $row['module'] = $alert['module']; + $row['template'] = $alert['template']; + $row['actions'] = $alert['template']; + + $row['actions'] = ''; + + $row['fired'] = ''; + + $table1->data[] = $row; + } + + $table->data['alerts']['cell'] = html_print_table($table1, true); +} + function reporting_html_alert_report_module($table, $item) { $table->colspan['alerts']['cell'] = 3; $table->cellstyle['alerts']['cell'] = 'text-align: left;'; @@ -2137,110 +2176,6 @@ function reporting_get_fired_alerts_table ($alerts_fired) { return $table; } -/** - * Get a report for alerts of agent. - * - * It prints the numbers of alerts defined, fired and not fired of agent. - * - * @param int $id_agent Agent to get info of the alerts. - * @param int $period Period of time of the desired alert report. - * @param int $date Beggining date of the report (current date by default). - * @param bool $return Flag to return or echo the report (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_alert_reporting_agent ($id_agent, $period = 0, $date = 0, $return = true, $html = true) { - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Module'); - $table->head[1] = __('Template'); - $table->head[2] = __('Actions'); - $table->head[3] = __('Fired'); - - $alerts = agents_get_alerts ($id_agent); - - if (isset($alerts['simple'])) { - $i = 0; - if ($alerts['simple'] === false) - $alerts['simple'] = array(); - - foreach ($alerts['simple'] as $alert) { - $data = array(); - $data[0] = db_get_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $alert['id_agent_module'])); - $data[1] = db_get_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id IN (SELECT id_alert_action - FROM talert_template_module_actions - WHERE id_alert_template_module = ' . $alert['id'] . ');'); - $data[2] = ''; - - $data[3] = ''; - - if ($alert['disabled']) { - $table->rowstyle[$i] = 'color: grey; font-style: italic;'; - } - $i++; - - array_push ($table->data, $data); - } - } - - if ($html) { - return html_print_table ($table, $return); - } - else { - return $table; - } -} - /** * Get a report for alerts of group. * @@ -4156,27 +4091,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); break; - case 'alert_report_agent': - if (empty($item_title)) { - $item_title = __('Alert report agent'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_alert_reporting_agent ($content['id_agent'], $content['period'], $report["datetime"], true); - array_push ($table->data, $data); - break; - case 'database_serialized': if (empty($item_title)) { $item_title = __('Serialize data');