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'] = '