diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index c233d56e50..03f4aeabc5 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,20 @@ +2010-04-28 Miguel de Dios + + * include/functions_reporting.php: added function "alert_reporting_agent" + for make the html list of agent alerts, added function + "alert_reporting_module" for same thing before function instead it is for + modules. In report item "event_report_agent" fixed the output. Added report + items "alert_report_module", "alert_report_agent", "url" and + "database_serialized". + + * include/functions_db.php: added function "get_agent_alert_fired" for + to extract the alerts fired of agent, and added "get_module_alert_fired" + for alerts fired of module. + + * godmode/reporting/reporting_builder.php, + godmode/reporting/reporting_builder.item_editor.php: fixed the renamed + column "row_separator" of previus commit. + 2010-04-28 Miguel de Dios * pandoradb.sql, extras/pandoradb_migrate_v3.0_to_v3.1.sql: renamed the diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index e5e963806e..c611058fdd 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -124,14 +124,14 @@ switch ($action) { break; case 'url': $description = $item['description']; - $url = $item['row_separator']; + $url = $item['column_separator']; break; case 'database_serialized': $description = $item['description']; $idAgentModule = $item['id_agent_module']; $idAgent = get_db_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); $header = $item['header_definition']; - $field = $item['row_separator']; + $field = $item['column_separator']; $line = $item['line_separator']; break; case 'TTRT': diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 634cf3ab59..00adf60708 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -182,7 +182,7 @@ switch ($action) { } $values['header_definition'] = get_parameter('header'); - $values['row_separator'] = get_parameter('field'); + $values['column_separator'] = get_parameter('field'); $values['line_separator'] = get_parameter('line'); $resultOperationDB = process_sql_update('treport_content', $values, array('id_rc' => $idItem)); @@ -209,7 +209,7 @@ switch ($action) { } $values['header_definition'] = get_parameter('header'); - $values['row_separator'] = get_parameter('field'); + $values['column_separator'] = get_parameter('field'); $values['line_separator'] = get_parameter('line'); $result = process_sql_insert('treport_content', $values); diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index be7f1d9f3f..2b0833cc9e 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -913,6 +913,66 @@ function get_module_events ($id_agent_module, $period, $date = 0) { return get_db_all_rows_sql ($sql); } +/** + * Get all the fired of alerts happened in an Agent during a period of time. + * + * The returned alerts will be in the time interval ($date - $period, $date] + * + * @param int $id_agent Agent id to get events. + * @param int $period Period of time in seconds to get events. + * @param int $date Beginning date to get events. + * + * @return array An array with all the events happened. + */ +function get_agent_alert_fired ($id_agent, $id_alert, $period, $date = 0) { + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $datelimit = $date - $period; + + $sql = sprintf ('SELECT timestamp + FROM tevento + WHERE id_agente = %d AND utimestamp > %d AND utimestamp <= %d + AND id_alert_am = %d + ORDER BY timestamp DESC', $id_agent, $datelimit, $date, $id_alert); + + return get_db_all_rows_sql ($sql); +} + +/** + * Get all the fired of alerts happened in an Agent module during a period of time. + * + * The returned alerts will be in the time interval ($date - $period, $date] + * + * @param int $id_agent_module Agent module id to get events. + * @param int $period Period of time in seconds to get events. + * @param int $date Beginning date to get events. + * + * @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); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $datelimit = $date - $period; + + $sql = sprintf ('SELECT timestamp + FROM tevento + WHERE id_agentmodule = %d AND utimestamp > %d AND utimestamp <= %d + AND id_alert_am = %d + ORDER BY timestamp DESC', $id_agent_module, $datelimit, $date, $id_alert); + + return get_db_all_rows_sql ($sql); +} + /** * Get all the monitors defined in an agent. * diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 3032c8a741..9157806cbb 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -539,6 +539,158 @@ function get_fired_alerts_reporting_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). + * + * @return string + */ +function alert_reporting_agent ($id_agent, $period = 0, $date = 0, $return = true) { + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + if (empty ($period)) { + global $config; + $period = $config["sla_period"]; + } + + $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 = get_agent_alerts ($id_agent); + + if (isset($alerts['simple'])) { + $i = 0; + foreach ($alerts['simple'] as $alert) { + $data = array(); + $data[0] = get_db_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $alert['id_agent_module'])); + $data[1] = get_db_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); + $actions = get_db_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); + } + } + + return print_table ($table, $return); +} + +/** + * Get a report for alerts of module. + * + * It prints the numbers of alerts defined, fired and not fired of agent. + * + * @param int $id_agent_module Module 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). + * + * @return string + */ +function alert_reporting_module ($id_agent_module, $period = 0, $date = 0, $return = true) { + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + if (empty ($period)) { + global $config; + $period = $config["sla_period"]; + } + + $table->width = '99%'; + $table->data = array (); + $table->head = array (); + $table->head[1] = __('Template'); + $table->head[2] = __('Actions'); + $table->head[3] = __('Fired'); + + + $alerts = get_db_all_rows_sql('SELECT * + FROM talert_template_modules AS t1 + INNER JOIN talert_templates AS t2 ON t1.id = t2.id + WHERE id_agent_module = ' . $id_agent_module); + + $i = 0; + foreach ($alerts as $alert) { + $data = array(); + $data[1] = get_db_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); + $actions = get_db_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); + } + + return print_table ($table, $return); +} + /** * Get a report for alerts in a group of agents. * @@ -1017,7 +1169,7 @@ function get_module_detailed_event_reporting ($id_modules, $period = 0, $date = $events = array (); foreach ($id_modules as $id_module) { - $event = get_agent_events ($id_module, (int) $period, (int) $date); + $event = get_module_events ($id_module, (int) $period, (int) $date); if (!empty ($event)) { array_push ($events, $event); } @@ -1637,7 +1789,7 @@ function render_report_html_item ($content, $table, $report) { $data = array (); $table->colspan[2][0] = 3; - $data[0] = get_agents_detailed_event_reporting ($content['id_agent'], $content['period'], $report["datetime"]); + $data[0] = get_agents_detailed_event_reporting ($content['id_agent'], $content['period'], $report["datetime"], true); array_push ($table->data, $data); break; case 'text': @@ -1725,6 +1877,118 @@ function render_report_html_item ($content, $table, $report) { $data[0] = get_module_detailed_event_reporting($content['id_agent_module'], $content['period'], $report["datetime"]); array_push ($table->data, $data); break; + case 'alert_report_module': + $data = array (); + $data[0] = "

" . __('Agent detailed event') . "

"; + $data[1] = "

$agent_name

"; + array_push ($table->data, $data); + + // Put description at the end of the module (if exists) + if ($content["description"] != ""){ + $table->colspan[1][0] = 3; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = alert_reporting_module ($content['id_agent_module'], $content['period'], $report["datetime"], true); + array_push ($table->data, $data); + break; + case 'alert_report_agent': + $data = array (); + $data[0] = "

" . __('Module detailed event') . "

"; + $data[1] = "

$agent_name - $module_name

"; + array_push ($table->data, $data); + + // Put description at the end of the module (if exists) + if ($content["description"] != ""){ + $table->colspan[1][0] = 3; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = alert_reporting_agent ($content['id_agent'], $content['period'], $report["datetime"], true); + array_push ($table->data, $data); + break; + case 'url': + $table->colspan[1][0] = 2; + $data = array (); + $data[0] = "

" . __('Import text from URL') . "

"; + array_push ($table->data, $data); + + // Put description at the end of the module (if exists) + if ($content["description"] != ""){ + $table->colspan[1][0] = 3; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array(); + $table->colspan[2][0] = 3; + $data[0] = ''; + $data[0] .= ''; + + array_push ($table->data, $data); + break; + case 'database_serialized': + $data = array (); + $data[0] = "

" . __('Serialize data') . "

"; + $data[1] = "

$agent_name - $module_name

"; + array_push ($table->data, $data); + + // Put description at the end of the module (if exists) + if ($content["description"] != ""){ + $table->colspan[1][0] = 3; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $table2->class = 'databox'; + $table2->width = '100%'; + + //Create the head + $table2->head = array(); + if ($content['header_definition'] != '') { + $table2->head = explode('|', $content['header_definition']); + } + array_unshift($table2->head, __('Date')); + + $datelimit = $report["datetime"] - $content['period']; + + $result = get_db_all_rows_sql('SELECT * + FROM tagente_datos_string + WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' + AND utimestamp > ' . $datelimit . ' AND utimestamp <= ' . $report["datetime"]); + if ($result === false) { + $result = array(); + } + + $table2->data = array(); + foreach ($result as $row) { + $date = date ($config["date_format"], $row['utimestamp']); + $serialized = $row['datos']; + $rowsUnserialize = explode($content['line_separator'], $serialized); + foreach ($rowsUnserialize as $rowUnser) { + $columnsUnserialize = explode($content['column_separator'], $rowUnser); + array_unshift($columnsUnserialize, $date); + array_push($table2->data, $columnsUnserialize); + } + } + + $cellContent = print_table($table2, true); + array_push($table->data, array($cellContent)); + $table->colspan[1][0] = 2; + break; } }