Ticket integria:4063 fixed report alert for module, group, agent

This commit is contained in:
daniel 2016-09-22 10:55:57 +02:00
parent 6b882173c6
commit d2617df147

View File

@ -2601,19 +2601,14 @@ function reporting_alert_report_group($report, $content) {
$data_row['template'] = db_get_value_filter('name', 'talert_templates', $data_row['template'] = db_get_value_filter('name', 'talert_templates',
array('id' => $alert['id_alert_template'])); array('id' => $alert['id_alert_template']));
$actions = alerts_get_alert_agent_module_actions ($alert['id']);
$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)) { if (!empty($actions)) {
$row = db_get_row_sql('SELECT id_alert_action $row = db_get_row_sql('SELECT id_alert_action
FROM talert_templates FROM talert_templates
WHERE id IN (SELECT id_alert_template WHERE id IN (SELECT id_alert_template
FROM talert_template_modules FROM talert_template_modules
WHERE id = ' . $alert['id_alert_template'] . ')'); WHERE id = ' . $alert['id'] . ')');
$id_action = 0; $id_action = 0;
if (!empty($row)) if (!empty($row))
@ -2622,16 +2617,13 @@ function reporting_alert_report_group($report, $content) {
// Prevent from void action // Prevent from void action
if (empty($id_action)) if (empty($id_action))
$id_action = 0; $id_action = 0;
}
else {
$actions = db_get_all_rows_sql('SELECT name $actions = db_get_all_rows_sql('SELECT name
FROM talert_actions FROM talert_actions
WHERE id = ' . $id_action); WHERE id = ' . $id_action);
if (empty($actions)) {
$actions = array();
}
} }
$data_row['action'] = array(); $data_row['action'] = array();
foreach ($actions as $action) { foreach ($actions as $action) {
$data_row['action'][] = $action['name']; $data_row['action'][] = $action['name'];
@ -2643,9 +2635,12 @@ function reporting_alert_report_group($report, $content) {
$alert['id_alert_template'], $alert['id_alert_template'],
(int) $content['period'], (int) $content['period'],
(int) $report["datetime"]); (int) $report["datetime"]);
if (empty($firedTimes)) { if (empty($firedTimes)) {
$firedTimes = array(); $firedTimes = array();
$firedTimes[0]['timestamp'] = '----------------------------';
} }
foreach ($firedTimes as $fireTime) { foreach ($firedTimes as $fireTime) {
$data_row['fired'][] = $fireTime['timestamp']; $data_row['fired'][] = $fireTime['timestamp'];
} }
@ -2675,8 +2670,6 @@ function reporting_alert_report_agent($report, $content) {
if ($config['metaconsole']) { if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]); $id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta); $server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server); metaconsole_connect($server);
} }
@ -2700,87 +2693,69 @@ function reporting_alert_report_agent($report, $content) {
$data = array(); $data = array();
foreach ($alerts as $alert) { if (is_array($alerts) || is_object($alerts)) {
$data_row = 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']));
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$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'] . ');');
break;
case "oracle":
$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'] . ')');
break;
}
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; $data_row['disabled'] = $alert['disabled'];
if (!empty($row))
$id_action = $row['id_alert_action'];
// Prevent from void action $data_row['module'] = db_get_value_filter('nombre', 'tagente_modulo',
if (empty($id_action)) 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 = alerts_get_alert_agent_module_actions ($alert['id']);
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; $id_action = 0;
if (!empty($row))
$actions = db_get_all_rows_sql('SELECT name $id_action = $row['id_alert_action'];
FROM talert_actions
WHERE id = ' . $id_action); // Prevent from void action
if (empty($id_action))
$id_action = 0;
}
else {
$actions = db_get_all_rows_sql('SELECT name
FROM talert_actions
WHERE id = ' . $id_action);
}
if (empty($actions)) { if (empty($actions)) {
$actions = array(); $actions = array();
} }
$data_row['action'] = array();
foreach ($actions as $action) {
$data_row['action'][] = $action['name'];
}
$data_row['fired'] = array();
$firedTimes = get_module_alert_fired(
$alert['id_agent_module'],
$alert['id_alert_template'],
(int) $content['period'],
(int) $report["datetime"]);
if (empty($firedTimes)) {
$firedTimes = array();
$firedTimes[0]['timestamp'] = '----------------------------';
}
foreach ($firedTimes as $fireTime) {
$data_row['fired'][] = $fireTime['timestamp'];
}
$data[] = $data_row;
} }
$data_row['action'] = array();
foreach ($actions as $action) {
$data_row['action'][] = $action['name'];
}
$data_row['fired'] = array();
$firedTimes = get_module_alert_fired(
$alert['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['data'] = $data;
if ($config['metaconsole']) { if ($config['metaconsole']) {
@ -2845,7 +2820,9 @@ function reporting_alert_report_module($report, $content) {
} }
$data = array(); $data = array();
foreach ($alerts as $alert) { foreach ($alerts as $alert) {
$data_row = array(); $data_row = array();
$data_row['disabled'] = $alert['disabled']; $data_row['disabled'] = $alert['disabled'];
@ -2853,25 +2830,7 @@ function reporting_alert_report_module($report, $content) {
$data_row['template'] = db_get_value_filter('name', $data_row['template'] = db_get_value_filter('name',
'talert_templates', array('id' => $alert['id_alert_template'])); 'talert_templates', array('id' => $alert['id_alert_template']));
switch ($config["dbtype"]) { $actions = alerts_get_alert_agent_module_actions ($alert['id_alert_template_module']);
case "mysql":
case "postgresql":
$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'] . ');');
break;
case "oracle":
$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'] . ')');
break;
}
if (!empty($actions)) { if (!empty($actions)) {
$row = db_get_row_sql('SELECT id_alert_action $row = db_get_row_sql('SELECT id_alert_action
@ -2881,43 +2840,41 @@ function reporting_alert_report_module($report, $content) {
WHERE id = ' . $alert['id_alert_template_module'] . ')'); WHERE id = ' . $alert['id_alert_template_module'] . ')');
$id_action = 0; $id_action = 0;
if (!empty($row)) if (!empty($row))
$id_action = $row['id_alert_action']; $id_action = $row['id_alert_action'];
// Prevent from void action // Prevent from void action
if (empty($id_action)) if (empty($id_action))
$id_action = 0; $id_action = 0;
}
else {
$actions = db_get_all_rows_sql('SELECT name $actions = db_get_all_rows_sql('SELECT name
FROM talert_actions FROM talert_actions
WHERE id = ' . $id_action); WHERE id = ' . $id_action);
if (empty($actions)) {
$actions = array();
}
} }
$data_row['action'] = array(); $data_row['action'] = array();
foreach ($actions as $action) { foreach ($actions as $action) {
$data_row['action'][] = $action['name']; $data_row['action'][] = $action['name'];
} }
$data_row['fired'] = array(); $data_row['fired'] = array();
$firedTimes = get_module_alert_fired( $firedTimes = get_module_alert_fired(
$content['id_agent_module'], $content['id_agent_module'],
$alert['id_alert_template_module'], $alert['id_alert_template_module'],
(int) $content['period'], (int) $content['period'],
(int) $report["datetime"]); (int) $report["datetime"]);
if (empty($firedTimes)) { if (empty($firedTimes)) {
$firedTimes = array(); $firedTimes = array();
$firedTimes[0]['timestamp'] = '----------------------------';
} }
foreach ($firedTimes as $fireTime) { foreach ($firedTimes as $fireTime) {
$data_row['fired'][] = $fireTime['timestamp']; $data_row['fired'][] = $fireTime['timestamp'];
} }
$data[] = $data_row; $data[] = $data_row;
} }