Working in the refactoring the code of reports (alert_report_module).
This commit is contained in:
parent
f0d30f1057
commit
a3f602d114
|
@ -333,12 +333,104 @@ function reporting_make_reporting_data($id_report, $date, $time,
|
|||
$force_height_chart,
|
||||
'sql_graph_pie');
|
||||
break;
|
||||
case 'alert_report_module':
|
||||
$report['contents'][] = reporting_alert_report_module(
|
||||
$report,
|
||||
$content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return reporting_check_structure_report($report);
|
||||
}
|
||||
|
||||
function reporting_alert_report_module($report, $content) {
|
||||
|
||||
global $config;
|
||||
|
||||
$return['type'] = 'alert_report_module';
|
||||
|
||||
if (empty($content['name'])) {
|
||||
$content['name'] = __('Alert Report Module');
|
||||
}
|
||||
|
||||
$return['title'] = $content['name'];
|
||||
$return["description"] = $content["description"];
|
||||
$return["date"] = reporting_get_date_text($report, $content);
|
||||
|
||||
$alerts = db_get_all_rows_sql('SELECT *, t1.id as id_alert_template_module
|
||||
FROM talert_template_modules AS t1
|
||||
INNER JOIN talert_templates AS t2 ON t1.id_alert_template = t2.id
|
||||
WHERE id_agent_module = ' . $content['id_agent_module']);
|
||||
|
||||
if ($alerts === false) {
|
||||
$alerts = array();
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($alerts as $alert) {
|
||||
$data_row = array();
|
||||
|
||||
$data_row['disabled'] = $alert['disabled'];
|
||||
|
||||
$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_module'] . ');');
|
||||
|
||||
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_module'] . ')');
|
||||
|
||||
$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_module'],
|
||||
(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_sql_graph($report, $content, $type,
|
||||
$force_width_chart, $force_height_chart, $type_sql_graph) {
|
||||
|
||||
|
|
|
@ -209,6 +209,9 @@ function reporting_html_print_report($report, $mini = false) {
|
|||
case 'sql_graph_pie':
|
||||
reporting_html_sql_graph($table, $item);
|
||||
break;
|
||||
case 'alert_report_module':
|
||||
reporting_html_alert_report_module($table, $item);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($item['type'] == 'agent_module')
|
||||
|
@ -221,6 +224,40 @@ function reporting_html_print_report($report, $mini = false) {
|
|||
}
|
||||
}
|
||||
|
||||
function reporting_html_alert_report_module($table, $item) {
|
||||
$table->colspan['alerts']['cell'] = 3;
|
||||
$table->cellstyle['alerts']['cell'] = 'text-align: left;';
|
||||
|
||||
$table1->width = '99%';
|
||||
$table1->head = array ();
|
||||
$table1->head['template'] = __('Template');
|
||||
$table1->head['actions'] = __('Actions');
|
||||
$table1->head['fired'] = __('Fired');
|
||||
$table1->data = array ();
|
||||
foreach ($item['data'] as $alert) {
|
||||
$row = array();
|
||||
|
||||
$row['template'] = $alert['template'];
|
||||
$row['actions'] = $alert['template'];
|
||||
|
||||
$row['actions'] = '<ul class="action_list">' . "\n";
|
||||
foreach ($alert['action'] as $action) {
|
||||
$row['actions'] .= '<li>' . $action . '</li>' . "\n";
|
||||
}
|
||||
$row['actions'] .= '</ul>';
|
||||
|
||||
$row['fired'] = '<ul style="list-style-type: disc; margin-left: 10px;">' . "\n";
|
||||
foreach ($alert['fired'] as $fired) {
|
||||
$row['fired'] .= '<li>' . $fired . '</li>' . "\n";
|
||||
}
|
||||
$row['fired'] .= '</ul>';
|
||||
|
||||
$table1->data[] = $row;
|
||||
}
|
||||
|
||||
$table->data['alerts']['cell'] = html_print_table($table1, true);
|
||||
}
|
||||
|
||||
function reporting_html_sql_graph($table, $item) {
|
||||
$table->colspan['chart']['cell'] = 3;
|
||||
$table->cellstyle['chart']['cell'] = 'text-align: center;';
|
||||
|
@ -2342,109 +2379,6 @@ function reporting_alert_reporting_group ($id_group, $period = 0, $date = 0, $re
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
* @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_module ($id_agent_module, $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[1] = __('Template');
|
||||
$table->head[2] = __('Actions');
|
||||
$table->head[3] = __('Fired');
|
||||
|
||||
|
||||
$alerts = db_get_all_rows_sql('SELECT *, t1.id as id_alert_template_module
|
||||
FROM talert_template_modules AS t1
|
||||
INNER JOIN talert_templates AS t2 ON t1.id_alert_template = t2.id
|
||||
WHERE id_agent_module = ' . $id_agent_module);
|
||||
|
||||
if ($alerts === false) {
|
||||
$alerts = array();
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach ($alerts as $alert) {
|
||||
$data = array();
|
||||
$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_alert_template_module'] . ');');
|
||||
$data[2] = '<ul class="action_list">';
|
||||
|
||||
if ($actions === false) {
|
||||
$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_module'] . ')');
|
||||
$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 ($actions === false) {
|
||||
$actions = array();
|
||||
}
|
||||
|
||||
foreach ($actions as $action) {
|
||||
$data[2] .= '<li>' . $action['name'] . '</li>';
|
||||
}
|
||||
$data[2] .= '</ul>';
|
||||
|
||||
$data[3] = '<ul style="list-style-type: disc; margin-left: 10px;">';
|
||||
$firedTimes = get_module_alert_fired($id_agent_module, $alert['id_alert_template_module'], (int) $period, (int) $date);
|
||||
if ($firedTimes === false) {
|
||||
$firedTimes = array();
|
||||
}
|
||||
foreach ($firedTimes as $fireTime) {
|
||||
$data[3] .= '<li>' . $fireTime['timestamp'] . '</li>';
|
||||
}
|
||||
$data[3] .= '</ul>';
|
||||
|
||||
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 in a group of agents.
|
||||
*
|
||||
|
@ -4221,27 +4155,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
|
|||
$report["datetime"], true);
|
||||
array_push ($table->data, $data);
|
||||
break;
|
||||
case 'alert_report_module':
|
||||
if (empty($item_title)) {
|
||||
$item_title = __('Alert report module');
|
||||
}
|
||||
reporting_header_content($mini, $content, $report, $table, $item_title,
|
||||
ui_print_truncate_text($agent_name, 'agent_medium', false) .
|
||||
' <br> '.ui_print_truncate_text($module_name, 'module_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_module ($content['id_agent_module'], $content['period'], $report["datetime"], true);
|
||||
array_push ($table->data, $data);
|
||||
break;
|
||||
case 'alert_report_agent':
|
||||
if (empty($item_title)) {
|
||||
$item_title = __('Alert report agent');
|
||||
|
|
Loading…
Reference in New Issue