refactor events meta pandora_enterprise#9086

This commit is contained in:
Daniel Barbero Martin 2022-06-14 18:47:09 +02:00
parent 3b3e964cf9
commit b82b3c3fb1
9 changed files with 591 additions and 546 deletions

View File

@ -31,7 +31,6 @@ use PandoraFMS\Enterprise\Metaconsole\Node;
// Begin. // Begin.
global $config; global $config;
require_once 'include/functions_events.php'; require_once 'include/functions_events.php';
require_once 'include/functions_agents.php'; require_once 'include/functions_agents.php';
require_once 'include/functions_ui.php'; require_once 'include/functions_ui.php';
@ -88,81 +87,70 @@ $get_comments = (bool) get_parameter('get_comments', false);
$get_events_fired = (bool) get_parameter('get_events_fired'); $get_events_fired = (bool) get_parameter('get_events_fired');
$get_id_source_event = get_parameter('get_id_source_event'); $get_id_source_event = get_parameter('get_id_source_event');
$node_id = (int) get_parameter('node_id', 0); $node_id = (int) get_parameter('node_id', 0);
if ($get_comments === true) { if ($get_comments === true) {
$event = get_parameter('event', false); $event = get_parameter('event', false);
$filter = get_parameter('filter', false);
if ($event === false) { if ($event === false) {
return __('Failed to retrieve comments'); return __('Failed to retrieve comments');
} }
$eventsGrouped = []; $eventsGrouped = [];
if ($filter['group_rep'] == 1) {
$events = events_get_all(
['te.*'],
// Filter.
$filter,
// Offset.
null,
// Limit.
null,
// Order.
null,
// Sort_field.
null,
// History.
$filter['history'],
// Return_sql.
false,
// Having.
sprintf(
' HAVING max_id_evento = %d',
$event['id_evento']
),
// True for show comments of validated events.
true
);
if ($events !== false) {
$event = $events[0];
}
} else {
// Consider if the event is grouped. // Consider if the event is grouped.
if (isset($event['event_rep']) === true && $event['event_rep'] > 0) { if (isset($event['event_rep']) === true && $event['event_rep'] > 0) {
// Evaluate if we are in metaconsole or not.
$eventTable = 'tevento';
// Default grouped message filtering (evento and estado). // Default grouped message filtering (evento and estado).
$whereGrouped = sprintf( $whereGrouped = sprintf(
'`evento` = "%s" AND `estado` = "%s"', '`evento` = "%s" AND `estado` = "%s" AND `event_type` = "%s" ',
$event['evento'], $event['evento'],
$event['estado'] $event['estado'],
$event['event_type']
); );
// If id_agente is reported, filter the messages by them as well. // If id_agente is reported, filter the messages by them as well.
if ((int) $event['id_agente'] > 0) { if ((int) $event['id_agente'] > 0) {
$whereGrouped .= sprintf(' AND `id_agente` = "%s"', $event['id_agente']); $whereGrouped .= sprintf(
' AND `id_agente` = %d',
(int) $event['id_agente']
);
} }
// Get grouped comments. if ((int) $event['id_agentmodule'] > 0) {
$eventsGrouped = db_get_all_rows_sql( $whereGrouped .= sprintf(
sprintf( ' AND `id_agentmodule` = %d',
'SELECT `user_comment` (int) $event['id_agentmodule']
FROM `%s`
WHERE %s',
$eventTable,
$whereGrouped
)
); );
} else { }
$events = events_get_event(
$event['id_evento'], try {
false, if (is_metaconsole() === true
is_metaconsole(), && $event['server_id'] > 0
$history ) {
$node = new Node($event['server_id']);
$node->connect();
}
$sql = sprintf(
'SELECT `user_comment`
FROM tevento
WHERE %s',
$whereGrouped
); );
if ($events !== false) { // Get grouped comments.
$event = $events; $eventsGrouped = db_get_all_rows_sql($sql);
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $event['server_id'] > 0
) {
$node->disconnect();
}
$eventsGrouped = [];
} finally {
if (is_metaconsole() === true
&& $event['server_id'] > 0
) {
$node->disconnect();
} }
} }
} }
@ -1270,12 +1258,44 @@ if ($dialogue_event_response) {
if ($add_comment === true) { if ($add_comment === true) {
$comment = (string) get_parameter('comment'); $comment = (string) get_parameter('comment');
$eventId = (int) get_parameter('event_id'); $eventId = (int) get_parameter('event_id');
$server_id = 0;
if (is_metaconsole() === true) {
$server_id = (int) get_parameter('server_id');
}
// Safe comments for hacks. // Safe comments for hacks.
if (preg_match('/script/i', io_safe_output($comment))) { if (preg_match('/script/i', io_safe_output($comment))) {
$return = false; $return = false;
} else { } else {
$return = events_comment($eventId, $comment, 'Added comment', $meta, $history); try {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node = new Node($server_id);
$node->connect();
}
$return = events_comment(
$eventId,
$comment,
'Added comment'
);
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
$return = false;
} finally {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
}
} }
echo ($return === true) ? 'comment_ok' : 'comment_error'; echo ($return === true) ? 'comment_ok' : 'comment_error';
@ -1283,35 +1303,38 @@ if ($add_comment === true) {
return; return;
} }
if ($change_status) { if ($change_status === true) {
$event_ids = get_parameter('event_ids'); $event_ids = get_parameter('event_ids');
$new_status = get_parameter('new_status'); $new_status = get_parameter('new_status');
if ($node_id > 0) {
try { try {
if (is_metaconsole() === true
&& $node_id > 0
) {
$node = new Node($node_id); $node = new Node($node_id);
$node->connect(); $node->connect();
}
$return = events_change_status( $return = events_change_status(
explode(',', $event_ids), explode(',', $event_ids),
$new_status, $new_status
$meta,
$history
); );
} catch (\Exception $e) { } catch (\Exception $e) {
// Unexistent agent. // Unexistent agent.
if (is_metaconsole() === true
&& $node_id > 0
) {
$node->disconnect(); $node->disconnect();
}
$success = false; $success = false;
echo 'owner_error'; echo 'owner_error';
} finally { } finally {
if (is_metaconsole() === true
&& $node_id > 0
) {
$node->disconnect(); $node->disconnect();
} }
} else {
$return = events_change_status(
explode(',', $event_ids),
$new_status,
$meta,
$history
);
} }
if ($return !== false) { if ($return !== false) {
@ -1320,7 +1343,12 @@ if ($change_status) {
echo json_encode( echo json_encode(
[ [
'status_title' => $event_st['title'], 'status_title' => $event_st['title'],
'status_img' => html_print_image($event_st['img'], true, false, true), 'status_img' => html_print_image(
$event_st['img'],
true,
false,
true
),
'status' => 'status_ok', 'status' => 'status_ok',
'user' => db_get_value( 'user' => db_get_value(
'fullname', 'fullname',
@ -1356,24 +1384,37 @@ if ($change_owner) {
$new_owner = ''; $new_owner = '';
} }
if ($node_id > 0) {
try { try {
if (is_metaconsole() === true
&& $node_id > 0
) {
$node = new Node($node_id); $node = new Node($node_id);
$node->connect(); $node->connect();
$return = events_change_owner($event_id, $new_owner, true, $meta, $history);
} catch (\Exception $e) {
// Unexistent agent.
$node->disconnect();
$success = false;
echo 'owner_error';
} finally {
$node->disconnect();
}
} else {
$return = events_change_owner($event_id, $new_owner, true, $meta, $history);
} }
if ($return) { $return = events_change_owner(
$event_id,
$new_owner,
true
);
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $node_id > 0
) {
$node->disconnect();
}
$return = false;
} finally {
if (is_metaconsole() === true
&& $node_id > 0
) {
$node->disconnect();
}
}
if ($return === true) {
echo 'owner_ok'; echo 'owner_ok';
} else { } else {
echo 'owner_error'; echo 'owner_error';
@ -1427,8 +1468,8 @@ if ($get_extended_event) {
$similar_ids = get_parameter('similar_ids', $event_id); $similar_ids = get_parameter('similar_ids', $event_id);
$group_rep = $filter['group_rep']; $group_rep = $filter['group_rep'];
$event_rep = $event['event_rep']; $event_rep = $event['event_rep'];
$timestamp_first = $event['min_timestamp']; $timestamp_first = $event['timestamp_first'];
$timestamp_last = $event['max_timestamp']; $timestamp_last = $event['timestamp_last'];
$server_id = $event['server_id']; $server_id = $event['server_id'];
if (empty($server_id) && !empty($event['server_name']) && is_metaconsole()) { if (empty($server_id) && !empty($event['server_name']) && is_metaconsole()) {
$server_id = metaconsole_get_id_server($event['server_name']); $server_id = metaconsole_get_id_server($event['server_name']);
@ -1521,19 +1562,19 @@ if ($get_extended_event) {
$event['id_grupo'], $event['id_grupo'],
'EM', 'EM',
$event['clean_tags'], $event['clean_tags'],
$childrens_ids []
)) || (tags_checks_event_acl( )) || (tags_checks_event_acl(
$config['id_user'], $config['id_user'],
$event['id_grupo'], $event['id_grupo'],
'EW', 'EW',
$event['clean_tags'], $event['clean_tags'],
$childrens_ids []
)) || (tags_checks_event_acl( )) || (tags_checks_event_acl(
$config['id_user'], $config['id_user'],
$event['id_grupo'], $event['id_grupo'],
'ER', 'ER',
$event['clean_tags'], $event['clean_tags'],
$childrens_ids []
))) )))
) { ) {
$tabs .= "<li><a href='#extended_event_responses_page' id='link_responses'>".html_print_image( $tabs .= "<li><a href='#extended_event_responses_page' id='link_responses'>".html_print_image(
@ -1590,19 +1631,19 @@ if ($get_extended_event) {
$event['id_grupo'], $event['id_grupo'],
'EM', 'EM',
$event['clean_tags'], $event['clean_tags'],
$childrens_ids []
)) || (tags_checks_event_acl( )) || (tags_checks_event_acl(
$config['id_user'], $config['id_user'],
$event['id_grupo'], $event['id_grupo'],
'EW', 'EW',
$event['clean_tags'], $event['clean_tags'],
$childrens_ids []
)) || (tags_checks_event_acl( )) || (tags_checks_event_acl(
$config['id_user'], $config['id_user'],
$event['id_grupo'], $event['id_grupo'],
'ER', 'ER',
$event['clean_tags'], $event['clean_tags'],
$childrens_ids []
))) )))
) { ) {
$responses = events_page_responses($event); $responses = events_page_responses($event);
@ -1620,6 +1661,7 @@ if ($get_extended_event) {
$details = events_page_details($event, $server); $details = events_page_details($event, $server);
$related = '';
if (events_has_extended_info($event['id_evento']) === true) { if (events_has_extended_info($event['id_evento']) === true) {
$related = events_page_related($event, $server); $related = events_page_related($event, $server);
} }
@ -1721,8 +1763,7 @@ if ($get_extended_event) {
data : { data : {
page: "include/ajax/events", page: "include/ajax/events",
get_comments: 1, get_comments: 1,
meta: '.(int) is_metaconsole().', event: '.json_encode($event).'
event: '.json_encode($event).',
}, },
dataType : "html", dataType : "html",
success: function (data) { success: function (data) {

View File

@ -11661,53 +11661,16 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
break; break;
} }
} else { } else {
switch ($config['dbtype']) {
case 'mysql':
db_process_sql('SET group_concat_max_len = 9999999'); db_process_sql('SET group_concat_max_len = 9999999');
$sql = "SELECT *, MAX(id_evento) AS id_evento, $sql = "SELECT *, MAX(id_evento) AS id_evento,
GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment, GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment,
MIN(estado) AS min_estado, MAX(estado) AS max_estado, MIN(estado) AS min_estado, MAX(estado) AS max_estado,
COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_last
FROM ".$table_events.' FROM ".$table_events.'
WHERE 1=1 '.$sql_post.' WHERE 1=1 '.$sql_post.'
GROUP BY evento, id_agentmodule GROUP BY evento, id_agentmodule
ORDER BY timestamp_rep DESC'; ORDER BY timestamp_last DESC';
break;
case 'postgresql':
$sql = "SELECT *, MAX(id_evento) AS id_evento,
array_to_string(array_agg(DISTINCT user_comment), '') AS user_comment,
MIN(estado) AS min_estado, MAX(estado) AS max_estado,
COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep
FROM ".$table_events.'
WHERE 1=1 '.$sql_post.'
GROUP BY evento, id_agentmodule
ORDER BY timestamp_rep DESC';
break;
case 'oracle':
$set = [];
// TODO: Remove duplicate user comments
$sql = 'SELECT a.*, b.event_rep, b.timestamp_rep
FROM (SELECT *
FROM tevento
WHERE 1=1 '.$sql_post.") a,
(SELECT MAX (id_evento) AS id_evento,
to_char(evento) AS evento, id_agentmodule,
COUNT(*) AS event_rep, MIN(estado) AS min_estado,
MAX(estado) AS max_estado,
LISTAGG(user_comment, '') AS user_comment,
MAX(utimestamp) AS timestamp_rep
FROM ".$table_events.'
WHERE 1=1 '.$sql_post.'
GROUP BY to_char(evento), id_agentmodule) b
WHERE a.id_evento=b.id_evento AND
to_char(a.evento)=to_char(b.evento) AND
a.id_agentmodule=b.id_agentmodule';
$sql = oracle_recode_query($sql, $set);
break;
}
} }
if ($other['type'] == 'string') { if ($other['type'] == 'string') {
@ -13500,9 +13463,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
$res = events_comment( $res = events_comment(
$return, $return,
$user_comment, $user_comment,
'Added comment', 'Added comment'
is_metaconsole(),
$config['history_db_enabled']
); );
if ($other['data'][13] != '') { if ($other['data'][13] != '') {
// owner user // owner user
@ -13512,9 +13473,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
events_change_owner( events_change_owner(
$return, $return,
$owner_user, $owner_user,
true, true
is_metaconsole(),
$config['history_db_enabled']
); );
} }
} }
@ -13570,9 +13529,7 @@ function api_set_add_event_comment($id, $thrash2, $other, $thrash3)
$status = events_comment( $status = events_comment(
$id, $id,
$comment, $comment,
'Added comment', 'Added comment'
$meta,
$history
); );
if (is_error($status)) { if (is_error($status)) {
returnError( returnError(

View File

@ -235,7 +235,7 @@ function db_pandora_audit($accion, $descripcion, $user_id=false, $ip=true, $info
if (isset($config['remote_addr']) === true) { if (isset($config['remote_addr']) === true) {
$ip = $config['remote_addr']; $ip = $config['remote_addr'];
} else { } else {
if ($_SERVER['REMOTE_ADDR']) { if (isset($_SERVER['REMOTE_ADDR']) === true) {
$ip = $_SERVER['REMOTE_ADDR']; $ip = $_SERVER['REMOTE_ADDR'];
} else { } else {
$ip = __('N/A'); $ip = __('N/A');

View File

@ -458,11 +458,10 @@ function events_delete($id_evento, $filter=null, $history=false, $force_node=fal
* @param integer $id_evento Master event. * @param integer $id_evento Master event.
* @param integer $status Target status. * @param integer $status Target status.
* @param array $filter Optional. Filter options. * @param array $filter Optional. Filter options.
* @param boolean $history Apply on historical table.
* *
* @return integer Events validated or false if error. * @return integer Events validated or false if error.
*/ */
function events_update_status($id_evento, $status, $filter=null, $history=false) function events_update_status($id_evento, $status, $filter=null)
{ {
global $config; global $config;
@ -558,7 +557,7 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
$result = db_process_sql($update_sql); $result = db_process_sql($update_sql);
if ($result) { if ($result !== false) {
switch ($status) { switch ($status) {
case EVENT_STATUS_NEW: case EVENT_STATUS_NEW:
$status_string = 'New'; $status_string = 'New';
@ -568,9 +567,7 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
events_change_owner( events_change_owner(
$id_evento, $id_evento,
$config['id_user'], $config['id_user'],
false, false
is_metaconsole() ? true : false,
$history
); );
$status_string = 'Validated'; $status_string = 'Validated';
@ -856,7 +853,7 @@ function events_get_all(
} }
} }
$groups = $filter['id_group_filter']; $groups = isset($filter['id_group_filter']) === true ? $filter['id_group_filter'] : null;
if ((bool) $user_is_admin === false if ((bool) $user_is_admin === false
&& isset($groups) === false && isset($groups) === false
) { ) {
@ -1345,7 +1342,7 @@ function events_get_all(
// Pagination. // Pagination.
$pagination = ''; $pagination = '';
if (is_metaconsole() === true && empty($id_server) === true) { if (is_metaconsole() === true && empty($id_server) === true) {
// TODO: XXX TIP. capturra el error. // TODO: XXX TIP. captura el error.
$pagination = sprintf( $pagination = sprintf(
' LIMIT %d', ' LIMIT %d',
$config['max_number_of_events_per_node'] $config['max_number_of_events_per_node']
@ -1354,7 +1351,6 @@ function events_get_all(
$pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset); $pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset);
} }
$extra = '';
// Group by. // Group by.
$group_by = 'GROUP BY '; $group_by = 'GROUP BY ';
$tagente_join = 'LEFT'; $tagente_join = 'LEFT';
@ -1367,8 +1363,7 @@ function events_get_all(
case '1': case '1':
// Group by events. // Group by events.
$group_by .= 'te.estado, te.event_type, te.id_agente, te.id_agentmodule'; $group_by .= 'te.evento, te.id_agente, te.id_agentmodule, te.estado';
$group_by .= $extra;
break; break;
case '2': case '2':
@ -1584,9 +1579,9 @@ function events_get_all(
// TODO: XXX; // TODO: XXX;
hd($sort_field, true); hd($sort_field, true);
hd($order, true); hd($order, true);
if ($sort_field !== 'agent_name' if ($sort_field !== 'agent_name'
&& $sort_field !== 'server_name' && $sort_field !== 'server_name'
&& $sort_field !== 'timestamp'
) { ) {
$sort_field = explode('.', $sort_field)[1]; $sort_field = explode('.', $sort_field)[1];
if ($sort_field === 'user_comment') { if ($sort_field === 'user_comment') {
@ -1736,9 +1731,7 @@ function events_get_event($id, $fields=false, $meta=false, $history=false)
} }
} }
$table = 'tevento'; $event = db_get_row('tevento', 'id_evento', $id, $fields);
$event = db_get_row($table, 'id_evento', $id, $fields);
if ((bool) check_acl($config['id_user'], $event['id_grupo'], 'ER') === false) { if ((bool) check_acl($config['id_user'], $event['id_grupo'], 'ER') === false) {
return false; return false;
} }
@ -1752,31 +1745,24 @@ function events_get_event($id, $fields=false, $meta=false, $history=false)
* *
* @param mixed $id_event Event ID or array of events. * @param mixed $id_event Event ID or array of events.
* @param integer $new_status New status of the event. * @param integer $new_status New status of the event.
* @param boolean $meta Metaconsole mode flag.
* @param boolean $history History mode flag.
* *
* @return boolean Whether or not it was successful * @return boolean Whether or not it was successful
*/ */
function events_change_status( function events_change_status(
$id_event, $id_event,
$new_status, $new_status
$meta=false,
$history=false
) { ) {
global $config; global $config;
$event_table = 'tevento'; // Cleans up the selection for all unwanted
// values also casts any single values as an array.
// Cleans up the selection for all unwanted values also casts any single values as an array.
$id_event = (array) safe_int($id_event, 1); $id_event = (array) safe_int($id_event, 1);
// Update ack info if the new status is validated. // Update ack info if the new status is validated.
if ($new_status == EVENT_STATUS_VALIDATED) { $ack_utimestamp = 0;
$ack_user = $config['id_user'];
if ((int) $new_status === EVENT_STATUS_VALIDATED) {
$ack_utimestamp = time(); $ack_utimestamp = time();
$ack_user = $config['id_user'];
} else {
$acl_utimestamp = 0;
$ack_user = $config['id_user'];
} }
switch ($new_status) { switch ($new_status) {
@ -1800,16 +1786,11 @@ function events_change_status(
$alerts = []; $alerts = [];
foreach ($id_event as $k => $id) { foreach ($id_event as $k => $id) {
if ($meta) {
$event_group = events_meta_get_group($id, $history);
$event = events_meta_get_event($id, false, $history);
$server_id = $event['server_id'];
} else {
$event_group = events_get_group($id); $event_group = events_get_group($id);
$event = events_get_event($id); $event = events_get_event($id);
} if ($event['id_alert_am'] > 0
&& in_array($event['id_alert_am'], $alerts) === false
if ($event['id_alert_am'] > 0 && !in_array($event['id_alert_am'], $alerts)) { ) {
$alerts[] = $event['id_alert_am']; $alerts[] = $event['id_alert_am'];
} }
@ -1823,7 +1804,7 @@ function events_change_status(
} }
} }
if (empty($id_event)) { if (empty($id_event) === true) {
return false; return false;
} }
@ -1834,7 +1815,7 @@ function events_change_status(
]; ];
$ret = db_process_sql_update( $ret = db_process_sql_update(
$event_table, 'tevento',
$values, $values,
['id_evento' => $id_event] ['id_evento' => $id_event]
); );
@ -1843,30 +1824,22 @@ function events_change_status(
return false; return false;
} }
if ($new_status == EVENT_STATUS_VALIDATED) { if ($new_status === EVENT_STATUS_VALIDATED) {
events_change_owner( events_change_owner(
$id_event, $id_event,
$config['id_user'], $config['id_user'],
false, false
$meta,
$history
); );
} }
events_comment( events_comment(
$id_event, $id_event,
'', '',
'Change status to '.$status_string, 'Change status to '.$status_string
$meta,
$history
); );
if ($meta && !empty($alerts)) {
$server = metaconsole_get_connection_by_id($server_id);
metaconsole_connect($server);
}
// Put the alerts in standby or not depends the new status. // Put the alerts in standby or not depends the new status.
if (empty($alerts) === false) {
foreach ($alerts as $alert) { foreach ($alerts as $alert) {
switch ($new_status) { switch ($new_status) {
case EVENT_NEW: case EVENT_NEW:
@ -1883,9 +1856,6 @@ function events_change_status(
break; break;
} }
} }
if ($meta && !empty($alerts)) {
metaconsole_restore_db();
} }
return true; return true;
@ -1908,24 +1878,15 @@ function events_change_status(
function events_change_owner( function events_change_owner(
$id_event, $id_event,
$new_owner=false, $new_owner=false,
$force=false, $force=false
$meta=false,
$history=false
) { ) {
global $config; global $config;
$event_table = 'tevento';
// Cleans up the selection for all unwanted values also casts any single // Cleans up the selection for all unwanted values also casts any single
// values as an array. // values as an array.
$id_event = (array) safe_int($id_event, 1); $id_event = (array) safe_int($id_event, 1);
foreach ($id_event as $k => $id) { foreach ($id_event as $k => $id) {
if ($meta) {
$event_group = events_meta_get_group($id, $history);
} else {
$event_group = events_get_group($id); $event_group = events_get_group($id);
}
if (check_acl($config['id_user'], $event_group, 'EW') == 0) { if (check_acl($config['id_user'], $event_group, 'EW') == 0) {
db_pandora_audit( db_pandora_audit(
@ -1936,7 +1897,7 @@ function events_change_owner(
} }
} }
if (empty($id_event)) { if (empty($id_event) === true) {
return false; return false;
} }
@ -1944,17 +1905,13 @@ function events_change_owner(
$new_owner = $config['id_user']; $new_owner = $config['id_user'];
} }
// Only generate comment when is forced (sometimes is owner changes when // Only generate comment when is forced
// comment). // (sometimes is owner changes when comment).
if ($force) { if ($force === true) {
events_comment( events_comment(
$id_event, $id_event,
'', '',
'Change owner to '.$new_owner, 'Change owner to '.$new_owner
$meta,
$history,
true,
false
); );
} }
@ -1963,12 +1920,12 @@ function events_change_owner(
$where = ['id_evento' => $id_event]; $where = ['id_evento' => $id_event];
// If not force, add to where if owner_user = ''. // If not force, add to where if owner_user = ''.
if (!$force) { if ($force === false) {
$where['owner_user'] = ''; $where['owner_user'] = '';
} }
$ret = db_process_sql_update( $ret = db_process_sql_update(
$event_table, 'tevento',
$values, $values,
$where, $where,
'AND', 'AND',
@ -1990,37 +1947,21 @@ function events_change_owner(
* @param string $comment Comment to be registered. * @param string $comment Comment to be registered.
* @param string $action Action performed with comment. By default just add * @param string $action Action performed with comment. By default just add
* a comment. * a comment.
* @param boolean $meta Flag of metaconsole mode.
* @param boolean $history Flag of history mode.
* @param boolean $similars Similars.
* @param boolean $update_owner Update owner.
* *
* @return boolean Whether or not it was successful * @return boolean Whether or not it was successful
*/ */
function events_comment( function events_comment(
$id_event, $id_event,
$comment='', $comment='',
$action='Added comment', $action='Added comment'
$meta=false,
$history=false,
$similars=true,
$update_owner=true
) { ) {
global $config; global $config;
$event_table = 'tevento';
// Cleans up the selection for all unwanted values also casts any single // Cleans up the selection for all unwanted values also casts any single
// values as an array. // values as an array.
$id_event = (array) safe_int($id_event, 1); $id_event = (array) safe_int($id_event, 1);
// Check ACL.
foreach ($id_event as $k => $id) { foreach ($id_event as $k => $id) {
if ($meta) {
$event_group = events_meta_get_group($id, $history);
} else {
$event_group = events_get_group($id); $event_group = events_get_group($id);
}
if (check_acl($config['id_user'], $event_group, 'EW') == 0) { if (check_acl($config['id_user'], $event_group, 'EW') == 0) {
db_pandora_audit( db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION, AUDIT_LOG_ACL_VIOLATION,
@ -2031,35 +1972,38 @@ function events_comment(
} }
} }
if (empty($id_event)) { if (empty($id_event) === true) {
return false; return false;
} }
if ($update_owner) {
// If the event hasn't owner, assign the user as owner.
events_change_owner($id_event);
}
// Get the current event comments. // Get the current event comments.
$first_event = $id_event; $first_event = $id_event;
if (is_array($id_event)) { if (is_array($id_event) === true) {
$first_event = reset($id_event); $first_event = reset($id_event);
} }
$event_comments = mysql_db_process_sql( $sql = sprintf(
'SELECT user_comment FROM '.$event_table.' WHERE id_evento = '.$first_event, 'SELECT user_comment
'affected_rows', FROM tevento
'', WHERE id_evento = %d',
false $first_event
); );
$event_comments = db_get_all_rows_sql($sql);
$event_comments_array = []; $event_comments_array = [];
if ($event_comments[0]['user_comment'] == '') { if ($event_comments[0]['user_comment'] == '') {
$comments_format = 'new'; $comments_format = 'new';
} else { } else {
// If comments are not stored in json, the format is old. // If comments are not stored in json, the format is old.
$event_comments[0]['user_comment'] = str_replace(["\n", '&#x0a;'], '<br>', $event_comments[0]['user_comment']); $event_comments[0]['user_comment'] = str_replace(
[
"\n",
'&#x0a;',
],
'<br>',
$event_comments[0]['user_comment']
);
$event_comments_array = json_decode($event_comments[0]['user_comment']); $event_comments_array = json_decode($event_comments[0]['user_comment']);
if (empty($event_comments_array) === true) { if (empty($event_comments_array) === true) {
@ -2083,7 +2027,7 @@ function events_comment(
// Update comment. // Update comment.
$ret = db_process_sql_update( $ret = db_process_sql_update(
$event_table, 'tevento',
['user_comment' => $event_comments], ['user_comment' => $event_comments],
['id_evento' => implode(',', $id_event)] ['id_evento' => implode(',', $id_event)]
); );
@ -2110,7 +2054,7 @@ function events_comment(
'UPDATE %s 'UPDATE %s
SET user_comment = concat("%s", user_comment) SET user_comment = concat("%s", user_comment)
WHERE id_evento in (%s)', WHERE id_evento in (%s)',
$event_table, 'tevento',
$comment, $comment,
implode(',', $id_event) implode(',', $id_event)
); );
@ -3284,12 +3228,12 @@ function events_page_responses($event, $childrens_ids=[])
$status_blocked $status_blocked
); );
if (!$status_blocked) { if ($status_blocked === false) {
$data[2] .= html_print_button( $data[2] .= html_print_button(
__('Update'), __('Update'),
'status_button', 'status_button',
false, false,
'event_change_status(\''.$event['similar_ids'].'\');', 'event_change_status(\''.$event['similar_ids'].'\','.$event['server_id'].');',
'class="sub next w70p"', 'class="sub next w70p"',
true true
); );
@ -4764,6 +4708,10 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
$table_comments->head = []; $table_comments->head = [];
$table_comments->class = 'table_modal_alternate'; $table_comments->class = 'table_modal_alternate';
if (isset($event['user_comment']) === false) {
$event['user_comment'] = '';
}
$comments = (empty($groupedComments) === true) ? $event['user_comment'] : $groupedComments; $comments = (empty($groupedComments) === true) ? $event['user_comment'] : $groupedComments;
if (empty($comments) === true) { if (empty($comments) === true) {
@ -4793,10 +4741,14 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
// Plain comments. Can be improved. // Plain comments. Can be improved.
$sortedCommentsArray = []; $sortedCommentsArray = [];
foreach ($comments_array as $comm) { foreach ($comments_array as $comm) {
if (isset($comm) === true
&& empty($comm) === false
) {
foreach ($comm as $subComm) { foreach ($comm as $subComm) {
$sortedCommentsArray[] = $subComm; $sortedCommentsArray[] = $subComm;
} }
} }
}
// Sorting the comments by utimestamp (newer is first). // Sorting the comments by utimestamp (newer is first).
usort( usort(
@ -4820,7 +4772,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
} }
foreach ($comments_array as $comm) { foreach ($comments_array as $comm) {
$comments_format = (empty($comm) === true) ? 'old' : 'new'; $comments_format = (empty($comm) === true && is_array($comments) === false) ? 'old' : 'new';
switch ($comments_format) { switch ($comments_format) {
case 'new': case 'new':
@ -4895,13 +4847,13 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
$event['id_grupo'], $event['id_grupo'],
'EM', 'EM',
$event['clean_tags'], $event['clean_tags'],
$childrens_ids []
)) || (tags_checks_event_acl( )) || (tags_checks_event_acl(
$config['id_user'], $config['id_user'],
$event['id_grupo'], $event['id_grupo'],
'EW', 'EW',
$event['clean_tags'], $event['clean_tags'],
$childrens_ids []
))) && $config['show_events_in_local'] == false || $config['event_replication'] == false ))) && $config['show_events_in_local'] == false || $config['event_replication'] == false
) { ) {
$event['evento'] = io_safe_output($event['evento']); $event['evento'] = io_safe_output($event['evento']);
@ -5047,7 +4999,7 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep=
break; break;
case 'timestamp': case 'timestamp':
$sort_field_translated = ($group_rep == 0) ? 'timestamp' : 'timestamp_rep'; $sort_field_translated = ($group_rep == 0) ? 'timestamp' : 'timestamp_last';
break; break;
case 'user_id': case 'user_id':

View File

@ -10637,7 +10637,7 @@ function reporting_get_agents_detailed_event(
'type' => $e['event_type'], 'type' => $e['event_type'],
'criticity' => $e['criticity'], 'criticity' => $e['criticity'],
'validated_by' => $e['id_usuario'], 'validated_by' => $e['id_usuario'],
'timestamp' => $e['timestamp_rep'], 'timestamp' => $e['timestamp_last'],
'id_evento' => $e['id_evento'], 'id_evento' => $e['id_evento'],
'custom_data' => ($show_custom_data === true) ? $e['custom_data'] : '', 'custom_data' => ($show_custom_data === true) ? $e['custom_data'] : '',
]; ];

View File

@ -1156,7 +1156,7 @@ function reporting_html_event_report_group($table, $item, $pdf=0)
} }
if ($item['show_summary_group']) { if ($item['show_summary_group']) {
$data[] = '<font class="font_6pt">'.date($config['date_format'], $event['timestamp_rep']).'</font>'; $data[] = '<font class="font_6pt">'.date($config['date_format'], $event['timestamp_last']).'</font>';
} else { } else {
$data[] = '<font class="font_6pt">'.date($config['date_format'], strtotime($event['timestamp'])).'</font>'; $data[] = '<font class="font_6pt">'.date($config['date_format'], strtotime($event['timestamp'])).'</font>';
} }
@ -1381,7 +1381,7 @@ function reporting_html_event_report_module($table, $item, $pdf=0)
$data[3] = get_priority_name($event['criticity']); $data[3] = get_priority_name($event['criticity']);
if ($show_summary_group) { if ($show_summary_group) {
$data[4] = $event['event_rep']; $data[4] = $event['event_rep'];
$data[5] = date($config['date_format'], $event['timestamp_rep']); $data[5] = date($config['date_format'], $event['timestamp_last']);
} else { } else {
$data[4] = date($config['date_format'], strtotime($event['timestamp'])); $data[4] = date($config['date_format'], strtotime($event['timestamp']));
} }

View File

@ -1480,21 +1480,6 @@ function dashboardShowEventDialog(settings) {
}) })
.show(); .show();
$.post({
url: settings.ajaxUrl,
data: {
page: "include/ajax/events",
get_comments: 1,
event: settings.event,
filter: []
},
dataType: "html",
success: function(data) {
$("#extended_event_comments_page").empty();
$("#extended_event_comments_page").html(data);
}
});
//$("#refrcounter").countdown("pause"); //$("#refrcounter").countdown("pause");
//$("div.vc-countdown").countdown("pause"); //$("div.vc-countdown").countdown("pause");

View File

@ -81,20 +81,6 @@ function show_event_dialog(event, dialog_page, result) {
} }
}) })
.show(); .show();
$.post({
url: "ajax.php",
data: {
page: "include/ajax/events",
get_comments: 1,
event: event,
filter: values
},
dataType: "html",
success: function(data) {
$("#extended_event_comments_page").empty();
$("#extended_event_comments_page").html(data);
}
});
$("#refrcounter").countdown("pause"); $("#refrcounter").countdown("pause");
$("div.vc-countdown").countdown("pause"); $("div.vc-countdown").countdown("pause");
@ -472,11 +458,8 @@ function perform_response_massive(response, response_id, out_iterator) {
} }
// Change the status of an event to new, in process or validated. // Change the status of an event to new, in process or validated.
function event_change_status(event_ids) { function event_change_status(event_ids, node_id) {
var new_status = $("#estado").val(); var new_status = $("#estado").val();
var meta = $("#hidden-meta").val();
var history = $("#hidden-history").val();
var node_id = $("#hidden-node_id").val();
$("#button-status_button").attr("disabled", "disabled"); $("#button-status_button").attr("disabled", "disabled");
$("#response_loading").show(); $("#response_loading").show();
@ -487,13 +470,10 @@ function event_change_status(event_ids) {
change_status: 1, change_status: 1,
event_ids: event_ids, event_ids: event_ids,
new_status: new_status, new_status: new_status,
meta: meta, node_id: node_id
node_id: node_id,
history: history
}, },
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: true,
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
$("#button-status_button").removeAttr("disabled"); $("#button-status_button").removeAttr("disabled");
@ -607,10 +587,6 @@ function event_comment(current_event) {
} }
var comment = $("#textarea_comment").val(); var comment = $("#textarea_comment").val();
var meta = 0;
if ($("#hidden-meta").val() != undefined) {
meta = $("#hidden-meta").val();
}
var history = 0; var history = 0;
if ($("#hidden-history").val() != undefined) { if ($("#hidden-history").val() != undefined) {
@ -631,7 +607,7 @@ function event_comment(current_event) {
params.push("event_id=" + event.id_evento); params.push("event_id=" + event.id_evento);
} }
params.push("comment=" + comment); params.push("comment=" + comment);
params.push("meta=" + meta); params.push("server_id=" + event.server_id);
params.push("history=" + history); params.push("history=" + history);
$("#button-comment_button").attr("disabled", "disabled"); $("#button-comment_button").attr("disabled", "disabled");

View File

@ -10,6 +10,8 @@
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
use PandoraFMS\Enterprise\Metaconsole\Node;
class Events class Events
{ {
@ -68,7 +70,7 @@ class Events
{ {
$system = System::getInstance(); $system = System::getInstance();
if (!$this->correct_acl) { if ($this->correct_acl === false) {
return; return;
} else { } else {
switch ($parameter2) { switch ($parameter2) {
@ -121,7 +123,7 @@ class Events
$status_icon = html_print_image($img_st, true, false, false, false, false, true); $status_icon = html_print_image($img_st, true, false, false, false, false, true);
$row = []; $row = [];
$row[] = '<b class="ui-table-cell-label">'.__('Event Name').'</b><a href="#" onclick="openDetails('.$event['id_evento'].')"><div class="event_name">'.io_safe_output(str_replace(['&nbsp;', '&#20;'], ' ', $event['evento'])).'</div></a>'; $row[] = '<b class="ui-table-cell-label">'.__('Event Name').'</b><a href="#" onclick="openDetails('.$event['id_evento'].','.$event['server_id'].')"><div class="event_name">'.io_safe_output(str_replace(['&nbsp;', '&#20;'], ' ', $event['evento'])).'</div></a>';
if ($event['id_agente'] == 0) { if ($event['id_agente'] == 0) {
$agent_name = __('System'); $agent_name = __('System');
@ -130,7 +132,7 @@ class Events
} }
$row_1 = '<span class="events_agent">'.$agent_name.'</span>'; $row_1 = '<span class="events_agent">'.$agent_name.'</span>';
$row_1 .= '<span class="events_timestamp">'.ui_print_timestamp($event['timestamp_rep'], true, ['units' => 'tiny']).$status_icon.'</span>'; $row_1 .= '<span class="events_timestamp">'.ui_print_timestamp($event['timestamp_last'], true, ['units' => 'tiny']).$status_icon.'</span>';
$row[] = $row_1; $row[] = $row_1;
@ -139,21 +141,27 @@ class Events
} }
echo json_encode(['end' => $end, 'events' => $events]); echo json_encode(['end' => $end, 'events' => $events]);
break; break;
case 'get_detail_event': case 'get_detail_event':
$system = System::getInstance(); $system = System::getInstance();
$id_event = $system->getRequest('id_event', 0); $id_event = $system->getRequest('id_event', 0);
$server_id = $system->getRequest('server_id', 0);
$meta = false; try {
if ($system->getConfig('metaconsole')) { if (is_metaconsole() === true
$meta = true; && $server_id > 0
) {
$node = new Node($server_id);
$node->connect();
} }
$event = events_get_event($id_event, false, $meta); $event = events_get_event($id_event, false);
if ($event) {
if ($event !== false
&& empty($event) === false
) {
// Check if it is a event from module. // Check if it is a event from module.
if ($event['id_agentmodule'] > 0) { if ($event['id_agentmodule'] > 0) {
$event['module_graph_link'] = '<a data-ajax="false" href="index.php?page=module_graph&id='.$event['id_agentmodule'].'">'.html_print_image('images/chart_curve.png', true, ['style' => 'vertical-align: middle;'], false, false, false, true).'</a>'; $event['module_graph_link'] = '<a data-ajax="false" href="index.php?page=module_graph&id='.$event['id_agentmodule'].'">'.html_print_image('images/chart_curve.png', true, ['style' => 'vertical-align: middle;'], false, false, false, true).'</a>';
@ -162,45 +170,74 @@ class Events
} }
if ($event['id_agente'] > 0) { if ($event['id_agente'] > 0) {
$event['agent'] = "<a class='black'"."href='index.php?page=agent&id=".$event['id_agente']."'>".agents_get_alias($event['id_agente']).'</a>'; $event['agent'] = "<a class='black'";
$event['agent'] .= "href='index.php?page=agent&id=";
$event['agent'] .= $event['id_agente']."'>";
$event['agent'] .= agents_get_alias(
$event['id_agente']
);
$event['agent'] .= '</a>';
} else { } else {
$event['agent'] = '<i>'.__('N/A').'</i>'; $event['agent'] = '<i>'.__('N/A').'</i>';
} }
$event['evento'] = io_safe_output($event['evento']); $event['evento'] = io_safe_output(
$event['evento']
);
$event['clean_tags'] = events_clean_tags($event['tags']); $event['clean_tags'] = events_clean_tags(
$event['timestamp'] = date($system->getConfig('date_format'), $event['utimestamp']); $event['tags']
if (empty($event['owner_user'])) { );
$event['timestamp'] = date(
$system->getConfig('date_format'),
$event['utimestamp']
);
if (empty($event['owner_user']) === true) {
$event['owner_user'] = '<i>'.__('N/A').'</i>'; $event['owner_user'] = '<i>'.__('N/A').'</i>';
} else { } else {
$user_owner = db_get_value('fullname', 'tusuario', 'id_user', $event['owner_user']); $user_owner = db_get_value(
if (empty($user_owner)) { 'fullname',
'tusuario',
'id_user',
$event['owner_user']
);
if (empty($user_owner) === true) {
$user_owner = $event['owner_user']; $user_owner = $event['owner_user'];
} }
$event['owner_user'] = $user_owner; $event['owner_user'] = $user_owner;
} }
$event['event_type'] = events_print_type_description($event['event_type'], true); $event['event_type'] = events_print_type_description(
$event['event_type'],
true
);
$event['event_type'] .= ' '; $event['event_type'] .= ' ';
$event['event_type'] .= events_print_type_img($event['event_type'], true); $event['event_type'] .= events_print_type_img(
$event['event_type'],
true
);
if (!isset($group_rep)) { if (isset($group_rep) === false) {
$group_rep = 0; $group_rep = 0;
} }
if ($group_rep != 0) { if ((int) $group_rep !== 0) {
if ($event['event_rep'] <= 1) { if ($event['event_rep'] <= 1) {
$event['event_repeated'] = '<i>'.__('No').'</i>'; $event['event_repeated'] = '<i>'.__('No').'</i>';
} else { } else {
$event['event_repeated'] = sprintf('%d Times', $event['event_rep']); $event['event_repeated'] = sprintf(
'%d Times',
$event['event_rep']
);
} }
} else { } else {
$event['event_repeated'] = '<i>'.__('No').'</i>'; $event['event_repeated'] = '<i>'.__('No').'</i>';
} }
$event_criticity = get_priority_name($event['criticity']); $event_criticity = get_priority_name(
$event['criticity']
);
switch ($event['criticity']) { switch ($event['criticity']) {
default: default:
@ -248,19 +285,27 @@ class Events
true true
); );
if ($event['estado'] == 1) { if ((int) $event['estado'] === 1) {
$user_ack = db_get_value('fullname', 'tusuario', 'id_user', $event['id_usuario']); $user_ack = db_get_value(
if (empty($user_ack)) { 'fullname',
'tusuario',
'id_user',
$event['id_usuario']
);
if (empty($user_ack) === true) {
$user_ack = $event['id_usuario']; $user_ack = $event['id_usuario'];
} }
$date_ack = date($system->getConfig('date_format'), $event['ack_utimestamp']); $date_ack = date(
$system->getConfig('date_format'),
$event['ack_utimestamp']
);
$event['acknowledged_by'] = $user_ack.' ('.$date_ack.')'; $event['acknowledged_by'] = $user_ack.' ('.$date_ack.')';
} else { } else {
$event['acknowledged_by'] = '<i>'.__('N/A').'</i>'; $event['acknowledged_by'] = '<i>'.__('N/A').'</i>';
} }
// Get Status // Get Status.
switch ($event['estado']) { switch ($event['estado']) {
case 0: case 0:
$img_st = 'images/star_dark.png'; $img_st = 'images/star_dark.png';
@ -276,33 +321,74 @@ class Events
$img_st = 'images/hourglass.png'; $img_st = 'images/hourglass.png';
$title_st = __('Event in process'); $title_st = __('Event in process');
break; break;
default:
// Not posible.
break;
} }
$event['status'] = $title_st; $event['status'] = $title_st;
$event['status'] .= ' '; $event['status'] .= ' ';
$event['status'] .= html_print_image($img_st, true, false, false, false, false, true); $event['status'] .= html_print_image(
$img_st,
true,
false,
false,
false,
false,
true
);
$event['group'] = groups_get_name($event['id_grupo'], true); $event['group'] = groups_get_name(
$event['group'] .= ui_print_group_icon($event['id_grupo'], true); $event['id_grupo'],
true
);
$event['group'] .= ui_print_group_icon(
$event['id_grupo'],
true
);
$event['tags'] = tags_get_tags_formatted($event['tags']); $event['tags'] = tags_get_tags_formatted(
if (empty($event['tags'])) { $event['tags']
);
if (empty($event['tags']) === true) {
$event['tags'] = '<i>'.__('N/A').'</i>'; $event['tags'] = '<i>'.__('N/A').'</i>';
} }
$event_comments = db_get_value('user_comment', 'tevento', 'id_evento', $id_event); $event_comments = db_get_value(
'user_comment',
'tevento',
'id_evento',
$id_event
);
$event_comments_array = []; $event_comments_array = [];
$event_comments_array = json_decode($event_comments, true); $event_comments_array = json_decode(
$event_comments,
true
);
// Support for new format only. // Support for new format only.
if (empty($event_comments_array)) { if (empty($event_comments_array) === true) {
$comment = '<i>'.__('N/A').'</i>'; $comment = '<i>'.__('N/A').'</i>';
} else { } else {
$comment = ''; $comment = '';
$event_comments_array = array_reverse($event_comments_array); $event_comments_array = array_reverse(
$event_comments_array
);
foreach ($event_comments_array as $c) { foreach ($event_comments_array as $c) {
$comment .= date($system->getConfig('date_format'), $c['utimestamp']).' ('.$c['id_user'].')'; $comment .= date(
$c['comment'] = io_safe_output($c['comment']); $system->getConfig(
$c['comment'] = str_replace("\n", '<br>', $c['comment']); 'date_format'
),
$c['utimestamp']
).' ('.$c['id_user'].')';
$c['comment'] = io_safe_output(
$c['comment']
);
$c['comment'] = str_replace(
"\n",
'<br>',
$c['comment']
);
$comment .= '<br>'.$c['comment'].'<br>'; $comment .= '<br>'.$c['comment'].'<br>';
} }
} }
@ -313,18 +399,59 @@ class Events
} else { } else {
echo json_encode(['correct' => 0, 'event' => []]); echo json_encode(['correct' => 0, 'event' => []]);
} }
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
echo json_encode(['correct' => 0, 'event' => []]);
} finally {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
}
break; break;
case 'validate_event': case 'validate_event':
$system = System::getInstance(); $system = System::getInstance();
$id_event = $system->getRequest('id_event', 0); $id_event = $system->getRequest('id_event', 0);
$server_id = $system->getRequest('server_id', 0);
if (events_change_status($id_event, EVENT_VALIDATE, $system->getConfig('metaconsole'))) { try {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node = new Node($server_id);
$node->connect();
}
if (events_change_status($id_event, EVENT_VALIDATE) === true) {
echo json_encode(['correct' => 1]); echo json_encode(['correct' => 1]);
} else { } else {
echo json_encode(['correct' => 0]); echo json_encode(['correct' => 0]);
} }
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
echo json_encode(['correct' => 0]);
} finally {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
}
break; break;
} }
} }
@ -443,12 +570,19 @@ class Events
{ {
$filter = db_get_row('tevent_filter', 'id_filter', $this->filter); $filter = db_get_row('tevent_filter', 'id_filter', $this->filter);
$this->free_search = null;
$this->hours_old = null;
$this->status = null;
$this->type = null;
$this->severity = null;
if ($filter !== false && empty($filter) === false) {
$this->free_search = $filter['search']; $this->free_search = $filter['search'];
$this->hours_old = $filter['event_view_hr']; $this->hours_old = $filter['event_view_hr'];
$this->status = $filter['status']; $this->status = $filter['status'];
$this->type = $filter['event_type']; $this->type = $filter['event_type'];
$this->severity = $filter['severity']; $this->severity = $filter['severity'];
} }
}
public function show() public function show()
@ -578,6 +712,12 @@ class Events
'type' => 'hidden', 'type' => 'hidden',
]; ];
$options['content_text'] .= $ui->getInput($options_hidden); $options['content_text'] .= $ui->getInput($options_hidden);
$options_hidden = [
'id' => 'server_id',
'value' => 0,
'type' => 'hidden',
];
$options['content_text'] .= $ui->getInput($options_hidden);
$options['content_text'] .= '<div id="validate_button_loading" class="invisible center"> $options['content_text'] .= '<div id="validate_button_loading" class="invisible center">
<img src="images/ajax-loader.gif" /></div>'; <img src="images/ajax-loader.gif" /></div>';
$options['content_text'] .= '<div id="validate_button_correct" class="invisible center"> $options['content_text'] .= '<div id="validate_button_correct" class="invisible center">
@ -872,14 +1012,14 @@ class Events
$ui->contentAddHtml( $ui->contentAddHtml(
' '
<script type="text/javascript"> <script type="text/javascript">
function openDetails(id_event) { function openDetails(id_event, server_id) {
$.mobile.loading("show"); $.mobile.loading("show");
postvars = {}; postvars = {};
postvars["action"] = "ajax"; postvars["action"] = "ajax";
postvars["parameter1"] = "events"; postvars["parameter1"] = "events";
postvars["parameter2"] = "get_detail_event"; postvars["parameter2"] = "get_detail_event";
postvars["id_event"] = id_event; postvars["id_event"] = id_event;
postvars["server_id"] = server_id;
$.ajax ({ $.ajax ({
type: "POST", type: "POST",
@ -890,7 +1030,6 @@ class Events
function (data) { function (data) {
if (data.correct) { if (data.correct) {
event = data.event; event = data.event;
//Fill the dialog //Fill the dialog
$("#detail_event_dialog h1.dialog_title") $("#detail_event_dialog h1.dialog_title")
.html(event["evento"]); .html(event["evento"]);
@ -917,8 +1056,7 @@ class Events
$("#detail_event_dialog .cell_event_tags") $("#detail_event_dialog .cell_event_tags")
.html(event["tags"]); .html(event["tags"]);
$("#detail_event_dialog .cell_event_comments") $("#detail_event_dialog .cell_event_comments")
.html(event["comments"]);
.html(event["comments"]);
$("#detail_event_dialog .cell_agent") $("#detail_event_dialog .cell_agent")
.html(event["agent"]); .html(event["agent"]);
@ -926,6 +1064,7 @@ class Events
$(".cell_module_graph").html(event["module_graph_link"]); $(".cell_module_graph").html(event["module_graph_link"]);
$("#event_id").val(id_event); $("#event_id").val(id_event);
$("#server_id").val(server_id);
if (event["estado"] != 1) { if (event["estado"] != 1) {
$("#validate_button").show(); $("#validate_button").show();
@ -937,9 +1076,7 @@ class Events
$("#validate_button_loading").hide(); $("#validate_button_loading").hide();
$("#validate_button_fail").hide(); $("#validate_button_fail").hide();
$("#validate_button_correct").hide(); $("#validate_button_correct").hide();
$.mobile.loading( "hide" ); $.mobile.loading( "hide" );
$("#detail_event_dialog_hook").click(); $("#detail_event_dialog_hook").click();
} }
else { else {
@ -955,9 +1092,9 @@ class Events
}); });
} }
function validateEvent() { function validateEvent() {
id_event = $("#event_id").val(); id_event = $("#event_id").val();
server_id = $("#server_id").val();
$("#validate_button").hide(); $("#validate_button").hide();
$("#validate_button_loading").show(); $("#validate_button_loading").show();
@ -971,6 +1108,7 @@ class Events
postvars["parameter1"] = "events"; postvars["parameter1"] = "events";
postvars["parameter2"] = "validate_event"; postvars["parameter2"] = "validate_event";
postvars["id_event"] = id_event; postvars["id_event"] = id_event;
postvars["server_id"] = server_id;
$.ajax ({ $.ajax ({
type: "POST", type: "POST",
@ -1038,7 +1176,6 @@ class Events
function ajax_load_rows() { function ajax_load_rows() {
if (load_more_rows) { if (load_more_rows) {
load_more_rows = 0; load_more_rows = 0;
postvars = {}; postvars = {};
postvars[\"action\"] = \"ajax\"; postvars[\"action\"] = \"ajax\";
postvars[\"parameter1\"] = \"events\"; postvars[\"parameter1\"] = \"events\";
@ -1098,11 +1235,9 @@ class Events
$(document).ready(function() { $(document).ready(function() {
ajax_load_rows(); ajax_load_rows();
$(window).bind(\"scroll\", function () { $(window).bind(\"scroll\", function () {
custom_scroll(); custom_scroll();
}); });
$(window).on(\"touchmove\", function(event) { $(window).on(\"touchmove\", function(event) {
custom_scroll(); custom_scroll();
}); });
@ -1111,7 +1246,6 @@ class Events
function custom_scroll() { function custom_scroll() {
if ($(this).scrollTop() + $(this).height() if ($(this).scrollTop() + $(this).height()
>= ($(document).height() - 100)) { >= ($(document).height() - 100)) {
ajax_load_rows(); ajax_load_rows();
} }
} }