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.
global $config;
require_once 'include/functions_events.php';
require_once 'include/functions_agents.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_id_source_event = get_parameter('get_id_source_event');
$node_id = (int) get_parameter('node_id', 0);
if ($get_comments === true) {
$event = get_parameter('event', false);
$filter = get_parameter('filter', false);
if ($event === false) {
return __('Failed to retrieve comments');
}
$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.
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).
$whereGrouped = sprintf(
'`evento` = "%s" AND `estado` = "%s"',
'`evento` = "%s" AND `estado` = "%s" AND `event_type` = "%s" ',
$event['evento'],
$event['estado']
$event['estado'],
$event['event_type']
);
// If id_agente is reported, filter the messages by them as well.
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.
$eventsGrouped = db_get_all_rows_sql(
sprintf(
'SELECT `user_comment`
FROM `%s`
WHERE %s',
$eventTable,
$whereGrouped
)
if ((int) $event['id_agentmodule'] > 0) {
$whereGrouped .= sprintf(
' AND `id_agentmodule` = %d',
(int) $event['id_agentmodule']
);
} else {
$events = events_get_event(
$event['id_evento'],
false,
is_metaconsole(),
$history
}
try {
if (is_metaconsole() === true
&& $event['server_id'] > 0
) {
$node = new Node($event['server_id']);
$node->connect();
}
$sql = sprintf(
'SELECT `user_comment`
FROM tevento
WHERE %s',
$whereGrouped
);
if ($events !== false) {
$event = $events;
// Get grouped comments.
$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) {
$comment = (string) get_parameter('comment');
$eventId = (int) get_parameter('event_id');
$server_id = 0;
if (is_metaconsole() === true) {
$server_id = (int) get_parameter('server_id');
}
// Safe comments for hacks.
if (preg_match('/script/i', io_safe_output($comment))) {
$return = false;
} 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';
@ -1283,35 +1303,38 @@ if ($add_comment === true) {
return;
}
if ($change_status) {
if ($change_status === true) {
$event_ids = get_parameter('event_ids');
$new_status = get_parameter('new_status');
if ($node_id > 0) {
try {
if (is_metaconsole() === true
&& $node_id > 0
) {
$node = new Node($node_id);
$node->connect();
}
$return = events_change_status(
explode(',', $event_ids),
$new_status,
$meta,
$history
$new_status
);
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $node_id > 0
) {
$node->disconnect();
}
$success = false;
echo 'owner_error';
} finally {
if (is_metaconsole() === true
&& $node_id > 0
) {
$node->disconnect();
}
} else {
$return = events_change_status(
explode(',', $event_ids),
$new_status,
$meta,
$history
);
}
if ($return !== false) {
@ -1320,7 +1343,12 @@ if ($change_status) {
echo json_encode(
[
'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',
'user' => db_get_value(
'fullname',
@ -1356,24 +1384,37 @@ if ($change_owner) {
$new_owner = '';
}
if ($node_id > 0) {
try {
if (is_metaconsole() === true
&& $node_id > 0
) {
$node = new Node($node_id);
$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';
} else {
echo 'owner_error';
@ -1427,8 +1468,8 @@ if ($get_extended_event) {
$similar_ids = get_parameter('similar_ids', $event_id);
$group_rep = $filter['group_rep'];
$event_rep = $event['event_rep'];
$timestamp_first = $event['min_timestamp'];
$timestamp_last = $event['max_timestamp'];
$timestamp_first = $event['timestamp_first'];
$timestamp_last = $event['timestamp_last'];
$server_id = $event['server_id'];
if (empty($server_id) && !empty($event['server_name']) && is_metaconsole()) {
$server_id = metaconsole_get_id_server($event['server_name']);
@ -1521,19 +1562,19 @@ if ($get_extended_event) {
$event['id_grupo'],
'EM',
$event['clean_tags'],
$childrens_ids
[]
)) || (tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'EW',
$event['clean_tags'],
$childrens_ids
[]
)) || (tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'ER',
$event['clean_tags'],
$childrens_ids
[]
)))
) {
$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'],
'EM',
$event['clean_tags'],
$childrens_ids
[]
)) || (tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'EW',
$event['clean_tags'],
$childrens_ids
[]
)) || (tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'ER',
$event['clean_tags'],
$childrens_ids
[]
)))
) {
$responses = events_page_responses($event);
@ -1620,6 +1661,7 @@ if ($get_extended_event) {
$details = events_page_details($event, $server);
$related = '';
if (events_has_extended_info($event['id_evento']) === true) {
$related = events_page_related($event, $server);
}
@ -1721,8 +1763,7 @@ if ($get_extended_event) {
data : {
page: "include/ajax/events",
get_comments: 1,
meta: '.(int) is_metaconsole().',
event: '.json_encode($event).',
event: '.json_encode($event).'
},
dataType : "html",
success: function (data) {

View File

@ -11661,53 +11661,16 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
break;
}
} else {
switch ($config['dbtype']) {
case 'mysql':
db_process_sql('SET group_concat_max_len = 9999999');
$sql = "SELECT *, MAX(id_evento) AS id_evento,
GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment,
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.'
WHERE 1=1 '.$sql_post.'
GROUP BY evento, id_agentmodule
ORDER BY timestamp_rep 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;
}
ORDER BY timestamp_last DESC';
}
if ($other['type'] == 'string') {
@ -13500,9 +13463,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
$res = events_comment(
$return,
$user_comment,
'Added comment',
is_metaconsole(),
$config['history_db_enabled']
'Added comment'
);
if ($other['data'][13] != '') {
// owner user
@ -13512,9 +13473,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
events_change_owner(
$return,
$owner_user,
true,
is_metaconsole(),
$config['history_db_enabled']
true
);
}
}
@ -13570,9 +13529,7 @@ function api_set_add_event_comment($id, $thrash2, $other, $thrash3)
$status = events_comment(
$id,
$comment,
'Added comment',
$meta,
$history
'Added comment'
);
if (is_error($status)) {
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) {
$ip = $config['remote_addr'];
} else {
if ($_SERVER['REMOTE_ADDR']) {
if (isset($_SERVER['REMOTE_ADDR']) === true) {
$ip = $_SERVER['REMOTE_ADDR'];
} else {
$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 $status Target status.
* @param array $filter Optional. Filter options.
* @param boolean $history Apply on historical table.
*
* @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;
@ -558,7 +557,7 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
$result = db_process_sql($update_sql);
if ($result) {
if ($result !== false) {
switch ($status) {
case EVENT_STATUS_NEW:
$status_string = 'New';
@ -568,9 +567,7 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
events_change_owner(
$id_evento,
$config['id_user'],
false,
is_metaconsole() ? true : false,
$history
false
);
$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
&& isset($groups) === false
) {
@ -1345,7 +1342,7 @@ function events_get_all(
// Pagination.
$pagination = '';
if (is_metaconsole() === true && empty($id_server) === true) {
// TODO: XXX TIP. capturra el error.
// TODO: XXX TIP. captura el error.
$pagination = sprintf(
' LIMIT %d',
$config['max_number_of_events_per_node']
@ -1354,7 +1351,6 @@ function events_get_all(
$pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset);
}
$extra = '';
// Group by.
$group_by = 'GROUP BY ';
$tagente_join = 'LEFT';
@ -1367,8 +1363,7 @@ function events_get_all(
case '1':
// Group by events.
$group_by .= 'te.estado, te.event_type, te.id_agente, te.id_agentmodule';
$group_by .= $extra;
$group_by .= 'te.evento, te.id_agente, te.id_agentmodule, te.estado';
break;
case '2':
@ -1584,9 +1579,9 @@ function events_get_all(
// TODO: XXX;
hd($sort_field, true);
hd($order, true);
if ($sort_field !== 'agent_name'
&& $sort_field !== 'server_name'
&& $sort_field !== 'timestamp'
) {
$sort_field = explode('.', $sort_field)[1];
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($table, 'id_evento', $id, $fields);
$event = db_get_row('tevento', 'id_evento', $id, $fields);
if ((bool) check_acl($config['id_user'], $event['id_grupo'], 'ER') === 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 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
*/
function events_change_status(
$id_event,
$new_status,
$meta=false,
$history=false
$new_status
) {
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);
// 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_user = $config['id_user'];
} else {
$acl_utimestamp = 0;
$ack_user = $config['id_user'];
}
switch ($new_status) {
@ -1800,16 +1786,11 @@ function events_change_status(
$alerts = [];
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 = events_get_event($id);
}
if ($event['id_alert_am'] > 0 && !in_array($event['id_alert_am'], $alerts)) {
if ($event['id_alert_am'] > 0
&& in_array($event['id_alert_am'], $alerts) === false
) {
$alerts[] = $event['id_alert_am'];
}
@ -1823,7 +1804,7 @@ function events_change_status(
}
}
if (empty($id_event)) {
if (empty($id_event) === true) {
return false;
}
@ -1834,7 +1815,7 @@ function events_change_status(
];
$ret = db_process_sql_update(
$event_table,
'tevento',
$values,
['id_evento' => $id_event]
);
@ -1843,30 +1824,22 @@ function events_change_status(
return false;
}
if ($new_status == EVENT_STATUS_VALIDATED) {
if ($new_status === EVENT_STATUS_VALIDATED) {
events_change_owner(
$id_event,
$config['id_user'],
false,
$meta,
$history
false
);
}
events_comment(
$id_event,
'',
'Change status to '.$status_string,
$meta,
$history
'Change status to '.$status_string
);
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.
if (empty($alerts) === false) {
foreach ($alerts as $alert) {
switch ($new_status) {
case EVENT_NEW:
@ -1883,9 +1856,6 @@ function events_change_status(
break;
}
}
if ($meta && !empty($alerts)) {
metaconsole_restore_db();
}
return true;
@ -1908,24 +1878,15 @@ function events_change_status(
function events_change_owner(
$id_event,
$new_owner=false,
$force=false,
$meta=false,
$history=false
$force=false
) {
global $config;
$event_table = 'tevento';
// Cleans up the selection for all unwanted values also casts any single
// values as an array.
$id_event = (array) safe_int($id_event, 1);
foreach ($id_event as $k => $id) {
if ($meta) {
$event_group = events_meta_get_group($id, $history);
} else {
$event_group = events_get_group($id);
}
if (check_acl($config['id_user'], $event_group, 'EW') == 0) {
db_pandora_audit(
@ -1936,7 +1897,7 @@ function events_change_owner(
}
}
if (empty($id_event)) {
if (empty($id_event) === true) {
return false;
}
@ -1944,17 +1905,13 @@ function events_change_owner(
$new_owner = $config['id_user'];
}
// Only generate comment when is forced (sometimes is owner changes when
// comment).
if ($force) {
// Only generate comment when is forced
// (sometimes is owner changes when comment).
if ($force === true) {
events_comment(
$id_event,
'',
'Change owner to '.$new_owner,
$meta,
$history,
true,
false
'Change owner to '.$new_owner
);
}
@ -1963,12 +1920,12 @@ function events_change_owner(
$where = ['id_evento' => $id_event];
// If not force, add to where if owner_user = ''.
if (!$force) {
if ($force === false) {
$where['owner_user'] = '';
}
$ret = db_process_sql_update(
$event_table,
'tevento',
$values,
$where,
'AND',
@ -1990,37 +1947,21 @@ function events_change_owner(
* @param string $comment Comment to be registered.
* @param string $action Action performed with comment. By default just add
* 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
*/
function events_comment(
$id_event,
$comment='',
$action='Added comment',
$meta=false,
$history=false,
$similars=true,
$update_owner=true
$action='Added comment'
) {
global $config;
$event_table = 'tevento';
// Cleans up the selection for all unwanted values also casts any single
// values as an array.
$id_event = (array) safe_int($id_event, 1);
// Check ACL.
foreach ($id_event as $k => $id) {
if ($meta) {
$event_group = events_meta_get_group($id, $history);
} else {
$event_group = events_get_group($id);
}
if (check_acl($config['id_user'], $event_group, 'EW') == 0) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
@ -2031,35 +1972,38 @@ function events_comment(
}
}
if (empty($id_event)) {
if (empty($id_event) === true) {
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.
$first_event = $id_event;
if (is_array($id_event)) {
if (is_array($id_event) === true) {
$first_event = reset($id_event);
}
$event_comments = mysql_db_process_sql(
'SELECT user_comment FROM '.$event_table.' WHERE id_evento = '.$first_event,
'affected_rows',
'',
false
$sql = sprintf(
'SELECT user_comment
FROM tevento
WHERE id_evento = %d',
$first_event
);
$event_comments = db_get_all_rows_sql($sql);
$event_comments_array = [];
if ($event_comments[0]['user_comment'] == '') {
$comments_format = 'new';
} else {
// 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']);
if (empty($event_comments_array) === true) {
@ -2083,7 +2027,7 @@ function events_comment(
// Update comment.
$ret = db_process_sql_update(
$event_table,
'tevento',
['user_comment' => $event_comments],
['id_evento' => implode(',', $id_event)]
);
@ -2110,7 +2054,7 @@ function events_comment(
'UPDATE %s
SET user_comment = concat("%s", user_comment)
WHERE id_evento in (%s)',
$event_table,
'tevento',
$comment,
implode(',', $id_event)
);
@ -3284,12 +3228,12 @@ function events_page_responses($event, $childrens_ids=[])
$status_blocked
);
if (!$status_blocked) {
if ($status_blocked === false) {
$data[2] .= html_print_button(
__('Update'),
'status_button',
false,
'event_change_status(\''.$event['similar_ids'].'\');',
'event_change_status(\''.$event['similar_ids'].'\','.$event['server_id'].');',
'class="sub next w70p"',
true
);
@ -4764,6 +4708,10 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
$table_comments->head = [];
$table_comments->class = 'table_modal_alternate';
if (isset($event['user_comment']) === false) {
$event['user_comment'] = '';
}
$comments = (empty($groupedComments) === true) ? $event['user_comment'] : $groupedComments;
if (empty($comments) === true) {
@ -4793,10 +4741,14 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
// Plain comments. Can be improved.
$sortedCommentsArray = [];
foreach ($comments_array as $comm) {
if (isset($comm) === true
&& empty($comm) === false
) {
foreach ($comm as $subComm) {
$sortedCommentsArray[] = $subComm;
}
}
}
// Sorting the comments by utimestamp (newer is first).
usort(
@ -4820,7 +4772,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
}
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) {
case 'new':
@ -4895,13 +4847,13 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
$event['id_grupo'],
'EM',
$event['clean_tags'],
$childrens_ids
[]
)) || (tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'EW',
$event['clean_tags'],
$childrens_ids
[]
))) && $config['show_events_in_local'] == false || $config['event_replication'] == false
) {
$event['evento'] = io_safe_output($event['evento']);
@ -5047,7 +4999,7 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep=
break;
case 'timestamp':
$sort_field_translated = ($group_rep == 0) ? 'timestamp' : 'timestamp_rep';
$sort_field_translated = ($group_rep == 0) ? 'timestamp' : 'timestamp_last';
break;
case 'user_id':

View File

@ -10637,7 +10637,7 @@ function reporting_get_agents_detailed_event(
'type' => $e['event_type'],
'criticity' => $e['criticity'],
'validated_by' => $e['id_usuario'],
'timestamp' => $e['timestamp_rep'],
'timestamp' => $e['timestamp_last'],
'id_evento' => $e['id_evento'],
'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']) {
$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 {
$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']);
if ($show_summary_group) {
$data[4] = $event['event_rep'];
$data[5] = date($config['date_format'], $event['timestamp_rep']);
$data[5] = date($config['date_format'], $event['timestamp_last']);
} else {
$data[4] = date($config['date_format'], strtotime($event['timestamp']));
}

View File

@ -1480,21 +1480,6 @@ function dashboardShowEventDialog(settings) {
})
.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");
//$("div.vc-countdown").countdown("pause");

View File

@ -81,20 +81,6 @@ function show_event_dialog(event, dialog_page, result) {
}
})
.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");
$("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.
function event_change_status(event_ids) {
function event_change_status(event_ids, node_id) {
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");
$("#response_loading").show();
@ -487,13 +470,10 @@ function event_change_status(event_ids) {
change_status: 1,
event_ids: event_ids,
new_status: new_status,
meta: meta,
node_id: node_id,
history: history
node_id: node_id
},
type: "POST",
url: $("#hidden-ajax_file").val(),
async: true,
dataType: "json",
success: function(data) {
$("#button-status_button").removeAttr("disabled");
@ -607,10 +587,6 @@ function event_comment(current_event) {
}
var comment = $("#textarea_comment").val();
var meta = 0;
if ($("#hidden-meta").val() != undefined) {
meta = $("#hidden-meta").val();
}
var history = 0;
if ($("#hidden-history").val() != undefined) {
@ -631,7 +607,7 @@ function event_comment(current_event) {
params.push("event_id=" + event.id_evento);
}
params.push("comment=" + comment);
params.push("meta=" + meta);
params.push("server_id=" + event.server_id);
params.push("history=" + history);
$("#button-comment_button").attr("disabled", "disabled");

View File

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