mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
refactor events meta pandora_enterprise#9086
This commit is contained in:
parent
f3e645146d
commit
7e25a86d52
@ -10928,11 +10928,6 @@ function api_set_event_validate_filter_pro($trash1, $trash2, $other, $trash3)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table_events = 'tevento';
|
|
||||||
if (is_metaconsole()) {
|
|
||||||
$table_events = 'tmetaconsole_event';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($other['type'] == 'string') {
|
if ($other['type'] == 'string') {
|
||||||
if ($other['data'] != '') {
|
if ($other['data'] != '') {
|
||||||
returnError('Parameter error.');
|
returnError('Parameter error.');
|
||||||
@ -10998,7 +10993,7 @@ function api_set_event_validate_filter_pro($trash1, $trash2, $other, $trash3)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$count = db_process_sql_update(
|
$count = db_process_sql_update(
|
||||||
$table_events,
|
'tevento',
|
||||||
['estado' => 1],
|
['estado' => 1],
|
||||||
$filterString
|
$filterString
|
||||||
);
|
);
|
||||||
@ -11024,12 +11019,6 @@ function api_set_event_validate_filter($trash1, $trash2, $other, $trash3)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$simulate = false;
|
$simulate = false;
|
||||||
|
|
||||||
$table_events = 'tevento';
|
|
||||||
if (is_metaconsole()) {
|
|
||||||
$table_events = 'tmetaconsole_event';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($other['type'] == 'string') {
|
if ($other['type'] == 'string') {
|
||||||
if ($other['data'] != '') {
|
if ($other['data'] != '') {
|
||||||
returnError('Parameter error.');
|
returnError('Parameter error.');
|
||||||
@ -11064,14 +11053,14 @@ function api_set_event_validate_filter($trash1, $trash2, $other, $trash3)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($simulate) {
|
if ($simulate) {
|
||||||
$rows = db_get_all_rows_filter($table_events, $filterString);
|
$rows = db_get_all_rows_filter('tevento', $filterString);
|
||||||
if ($rows !== false) {
|
if ($rows !== false) {
|
||||||
returnData('string', count($rows));
|
returnData('string', count($rows));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$count = db_process_sql_update(
|
$count = db_process_sql_update(
|
||||||
$table_events,
|
'tevento',
|
||||||
['estado' => 1],
|
['estado' => 1],
|
||||||
$filterString
|
$filterString
|
||||||
);
|
);
|
||||||
@ -11341,9 +11330,6 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
|
|||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$table_events = 'tevento';
|
$table_events = 'tevento';
|
||||||
if (is_metaconsole() === true) {
|
|
||||||
$table_events = 'tmetaconsole_event';
|
|
||||||
}
|
|
||||||
|
|
||||||
// By default.
|
// By default.
|
||||||
$status = 3;
|
$status = 3;
|
||||||
@ -11561,21 +11547,19 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($group_rep == 0) {
|
if ($group_rep == 0) {
|
||||||
switch ($config['dbtype']) {
|
if ($filter['total']) {
|
||||||
case 'mysql':
|
$sql = 'SELECT COUNT(*)
|
||||||
if ($filter['total']) {
|
|
||||||
$sql = 'SELECT COUNT(*)
|
|
||||||
FROM '.$table_events.'
|
FROM '.$table_events.'
|
||||||
WHERE 1=1 '.$sql_post;
|
WHERE 1=1 '.$sql_post;
|
||||||
} else if ($filter['more_criticity']) {
|
} else if ($filter['more_criticity']) {
|
||||||
$sql = 'SELECT criticity
|
$sql = 'SELECT criticity
|
||||||
FROM '.$table_events.'
|
FROM '.$table_events.'
|
||||||
WHERE 1=1 '.$sql_post.'
|
WHERE 1=1 '.$sql_post.'
|
||||||
ORDER BY criticity DESC
|
ORDER BY criticity DESC
|
||||||
LIMIT 1';
|
LIMIT 1';
|
||||||
} else {
|
} else {
|
||||||
if (is_metaconsole() === true) {
|
if (is_metaconsole() === true) {
|
||||||
$sql = 'SELECT *,
|
$sql = 'SELECT *,
|
||||||
(SELECT t2.nombre
|
(SELECT t2.nombre
|
||||||
FROM tgrupo t2
|
FROM tgrupo t2
|
||||||
WHERE t2.id_grupo = '.$table_events.'.id_grupo) AS group_name,
|
WHERE t2.id_grupo = '.$table_events.'.id_grupo) AS group_name,
|
||||||
@ -11585,8 +11569,8 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
|
|||||||
FROM '.$table_events.$alert_join.'
|
FROM '.$table_events.$alert_join.'
|
||||||
WHERE 1=1 '.$sql_post.'
|
WHERE 1=1 '.$sql_post.'
|
||||||
ORDER BY utimestamp DESC';
|
ORDER BY utimestamp DESC';
|
||||||
} else {
|
} else {
|
||||||
$sql = 'SELECT *,
|
$sql = 'SELECT *,
|
||||||
(SELECT t1.alias
|
(SELECT t1.alias
|
||||||
FROM tagente t1
|
FROM tagente t1
|
||||||
WHERE t1.id_agente = tevento.id_agente) AS agent_name,
|
WHERE t1.id_agente = tevento.id_agente) AS agent_name,
|
||||||
@ -11605,60 +11589,7 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
|
|||||||
FROM '.$table_events.$alert_join.'
|
FROM '.$table_events.$alert_join.'
|
||||||
WHERE 1=1 '.$sql_post.'
|
WHERE 1=1 '.$sql_post.'
|
||||||
ORDER BY utimestamp DESC';
|
ORDER BY utimestamp DESC';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'postgresql':
|
|
||||||
// TODO TOTAL
|
|
||||||
$sql = 'SELECT *,
|
|
||||||
(SELECT t1.alias
|
|
||||||
FROM tagente t1
|
|
||||||
WHERE t1.id_agente = tevento.id_agente) AS agent_name,
|
|
||||||
(SELECT t2.nombre
|
|
||||||
FROM tgrupo t2
|
|
||||||
WHERE t2.id_grupo = tevento.id_grupo) AS group_name,
|
|
||||||
(SELECT t2.icon
|
|
||||||
FROM tgrupo t2
|
|
||||||
WHERE t2.id_grupo = tevento.id_grupo) AS group_icon,
|
|
||||||
(SELECT tmodule.name
|
|
||||||
FROM tmodule
|
|
||||||
WHERE id_module IN (
|
|
||||||
SELECT tagente_modulo.id_modulo
|
|
||||||
FROM tagente_modulo
|
|
||||||
WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name
|
|
||||||
FROM tevento
|
|
||||||
WHERE 1=1 '.$sql_post.'
|
|
||||||
ORDER BY utimestamp DESC';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
// TODO TOTAL
|
|
||||||
$set = [];
|
|
||||||
|
|
||||||
$sql = 'SELECT *,
|
|
||||||
(SELECT t1.alias
|
|
||||||
FROM tagente t1
|
|
||||||
WHERE t1.id_agente = tevento.id_agente) AS alias,
|
|
||||||
(SELECT t1.nombre
|
|
||||||
FROM tagente t1
|
|
||||||
WHERE t1.id_agente = tevento.id_agente) AS agent_name,
|
|
||||||
(SELECT t2.nombre
|
|
||||||
FROM tgrupo t2
|
|
||||||
WHERE t2.id_grupo = tevento.id_grupo) AS group_name,
|
|
||||||
(SELECT t2.icon
|
|
||||||
FROM tgrupo t2
|
|
||||||
WHERE t2.id_grupo = tevento.id_grupo) AS group_icon,
|
|
||||||
(SELECT tmodule.name
|
|
||||||
FROM tmodule
|
|
||||||
WHERE id_module IN (
|
|
||||||
SELECT tagente_modulo.id_modulo
|
|
||||||
FROM tagente_modulo
|
|
||||||
WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name
|
|
||||||
FROM tevento
|
|
||||||
WHERE 1=1 '.$sql_post.' ORDER BY utimestamp DESC';
|
|
||||||
$sql = oracle_recode_query($sql, $set);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
db_process_sql('SET group_concat_max_len = 9999999');
|
db_process_sql('SET group_concat_max_len = 9999999');
|
||||||
@ -11801,17 +11732,9 @@ function api_set_event($id_event, $unused1, $params, $unused2, $unused3)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In meta or node.
|
|
||||||
if (is_metaconsole() === true) {
|
|
||||||
$table = 'tmetaconsole_event';
|
|
||||||
} else {
|
|
||||||
$table = 'tevento';
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO. Stablish security for prevent sql injection?
|
|
||||||
// Update the row
|
// Update the row
|
||||||
$result = db_process_sql_update(
|
$result = db_process_sql_update(
|
||||||
$table,
|
'tevento',
|
||||||
$paramsSerialize,
|
$paramsSerialize,
|
||||||
[ 'id_evento' => $id_event ]
|
[ 'id_evento' => $id_event ]
|
||||||
);
|
);
|
||||||
@ -11882,15 +11805,7 @@ function api_get_events($node_id, $trash2, $other, $returnType, $user_in_db=null
|
|||||||
$filterString = otherParameter2Filter($other, false, $use_agent_name);
|
$filterString = otherParameter2Filter($other, false, $use_agent_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_metaconsole()) {
|
$dataRows = db_get_all_rows_filter('tevento', $filterString);
|
||||||
if ((int) $node_id !== 0) {
|
|
||||||
$filterString .= ' AND server_id = '.$node_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dataRows = db_get_all_rows_filter('tmetaconsole_event', $filterString);
|
|
||||||
} else {
|
|
||||||
$dataRows = db_get_all_rows_filter('tevento', $filterString);
|
|
||||||
}
|
|
||||||
|
|
||||||
$last_error = error_get_last();
|
$last_error = error_get_last();
|
||||||
if (empty($dataRows)) {
|
if (empty($dataRows)) {
|
||||||
@ -13107,18 +13022,20 @@ function api_get_event_info($id_event, $trash1, $trash, $returnType)
|
|||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$table_events = 'tevento';
|
$sql = sprintf(
|
||||||
if (defined('METACONSOLE')) {
|
'SELECT *
|
||||||
$table_events = 'tmetaconsole_event';
|
FROM tevento
|
||||||
}
|
WHERE id_evento= %d',
|
||||||
|
$id_event
|
||||||
|
);
|
||||||
|
|
||||||
$sql = 'SELECT *
|
|
||||||
FROM '.$table_events."
|
|
||||||
WHERE id_evento=$id_event";
|
|
||||||
$event_data = db_get_row_sql($sql);
|
$event_data = db_get_row_sql($sql);
|
||||||
|
|
||||||
// Check the access to group
|
// Check the access to group
|
||||||
if (!empty($event_data['id_grupo']) && $event_data['id_grupo'] > 0 && !$event_data['id_agente']) {
|
if (!empty($event_data['id_grupo'])
|
||||||
|
&& $event_data['id_grupo'] > 0
|
||||||
|
&& !$event_data['id_agente']
|
||||||
|
) {
|
||||||
if (!check_acl($config['id_user'], $event_data['id_grupo'], 'ER')) {
|
if (!check_acl($config['id_user'], $event_data['id_grupo'], 'ER')) {
|
||||||
returnError('forbidden', $returnType);
|
returnError('forbidden', $returnType);
|
||||||
return;
|
return;
|
||||||
@ -13126,8 +13043,14 @@ function api_get_event_info($id_event, $trash1, $trash, $returnType)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the access to agent
|
// Check the access to agent
|
||||||
if (!empty($event_data['id_agente']) && $event_data['id_agente'] > 0) {
|
if (!empty($event_data['id_agente'])
|
||||||
if (!util_api_check_agent_and_print_error($event_data['id_agente'], $returnType)) {
|
&& $event_data['id_agente'] > 0
|
||||||
|
) {
|
||||||
|
if (!util_api_check_agent_and_print_error(
|
||||||
|
$event_data['id_agente'],
|
||||||
|
$returnType
|
||||||
|
)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -13415,13 +13338,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
|
|||||||
|
|
||||||
if ($other['data'][18] != '') {
|
if ($other['data'][18] != '') {
|
||||||
$values['id_extra'] = $other['data'][18];
|
$values['id_extra'] = $other['data'][18];
|
||||||
if (is_metaconsole()) {
|
$sql_validation = 'SELECT id_evento FROM tevento where estado IN (0,2) and id_extra ="'.$other['data'][18].'";';
|
||||||
$table_event = 'tmetaconsole_event';
|
|
||||||
} else {
|
|
||||||
$table_event = 'tevento';
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql_validation = 'SELECT id_evento FROM '.$table_event.' where estado IN (0,2) and id_extra ="'.$other['data'][18].'";';
|
|
||||||
$validation = db_get_all_rows_sql($sql_validation);
|
$validation = db_get_all_rows_sql($sql_validation);
|
||||||
if ($validation) {
|
if ($validation) {
|
||||||
foreach ($validation as $val) {
|
foreach ($validation as $val) {
|
||||||
@ -13692,17 +13609,12 @@ function api_set_validate_event_by_id($id, $trash1=null, $trash2=null, $returnTy
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table_events = 'tevento';
|
|
||||||
if (is_metaconsole()) {
|
|
||||||
$table_events = 'tmetaconsole_event';
|
|
||||||
}
|
|
||||||
|
|
||||||
$data['type'] = 'string';
|
$data['type'] = 'string';
|
||||||
$check_id = db_get_value('id_evento', $table_events, 'id_evento', $id);
|
$check_id = db_get_value('id_evento', 'tevento', 'id_evento', $id);
|
||||||
|
|
||||||
if ($check_id) {
|
if ($check_id) {
|
||||||
// event exists
|
// event exists
|
||||||
$status = db_get_value('estado', $table_events, 'id_evento', $id);
|
$status = db_get_value('estado', 'tevento', 'id_evento', $id);
|
||||||
if ($status == 1) {
|
if ($status == 1) {
|
||||||
// event already validated
|
// event already validated
|
||||||
$data['data'] = 'Event already validated.';
|
$data['data'] = 'Event already validated.';
|
||||||
@ -13716,7 +13628,7 @@ function api_set_validate_event_by_id($id, $trash1=null, $trash2=null, $returnTy
|
|||||||
'estado' => 1,
|
'estado' => 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = db_process_sql_update($table_events, $values, ['id_evento' => $id]);
|
$result = db_process_sql_update('tevento', $values, ['id_evento' => $id]);
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
$data['data'] = 'The event could not be validated.';
|
$data['data'] = 'The event could not be validated.';
|
||||||
@ -17554,20 +17466,14 @@ function api_get_is_centralized($server_id, $thrash1, $thrash2, $returnType)
|
|||||||
function api_set_event_in_progress($event_id, $trash2, $returnType)
|
function api_set_event_in_progress($event_id, $trash2, $returnType)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
if (is_metaconsole()) {
|
|
||||||
$table = 'tmetaconsole_event';
|
|
||||||
} else {
|
|
||||||
$table = 'tevento';
|
|
||||||
}
|
|
||||||
|
|
||||||
$event = db_process_sql_update(
|
$event = db_process_sql_update(
|
||||||
$table,
|
'tevento',
|
||||||
['estado' => 2],
|
['estado' => 2],
|
||||||
['id_evento' => $event_id]
|
['id_evento' => $event_id]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($event !== false) {
|
if ($event !== false) {
|
||||||
returnData('string', ['data' => $event]);
|
returnData('string', ['data' => $event]);
|
||||||
} else {
|
} else {
|
||||||
returnError('id_not_found', 'string');
|
returnError('id_not_found', 'string');
|
||||||
}
|
}
|
||||||
|
@ -337,13 +337,15 @@ function events_get_column_name($field, $table_alias=false)
|
|||||||
*/
|
*/
|
||||||
function events_get_column_names($fields, $table_alias=false)
|
function events_get_column_names($fields, $table_alias=false)
|
||||||
{
|
{
|
||||||
if (!isset($fields) || !is_array($fields)) {
|
if (isset($fields) === false
|
||||||
|
|| is_array($fields) === false
|
||||||
|
) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$names = [];
|
$names = [];
|
||||||
foreach ($fields as $f) {
|
foreach ($fields as $f) {
|
||||||
if (is_array($f)) {
|
if (is_array($f) === true) {
|
||||||
$name = [];
|
$name = [];
|
||||||
$name['text'] = events_get_column_name($f['text'], $table_alias);
|
$name['text'] = events_get_column_name($f['text'], $table_alias);
|
||||||
$name['class'] = ($f['class'] ?? '');
|
$name['class'] = ($f['class'] ?? '');
|
||||||
@ -373,25 +375,26 @@ function events_get_column_names($fields, $table_alias=false)
|
|||||||
*/
|
*/
|
||||||
function events_delete($id_evento, $filter=null, $history=false, $force_node=false)
|
function events_delete($id_evento, $filter=null, $history=false, $force_node=false)
|
||||||
{
|
{
|
||||||
if (!isset($id_evento) || $id_evento <= 0) {
|
if (isset($id_evento) === false
|
||||||
|
|| $id_evento <= 0
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($filter) || !is_array($filter)) {
|
if (isset($filter) === false
|
||||||
|
|| is_array($filter) === true
|
||||||
|
) {
|
||||||
$filter = ['group_rep' => 0];
|
$filter = ['group_rep' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = 'tevento';
|
|
||||||
|
|
||||||
switch ($filter['group_rep']) {
|
switch ($filter['group_rep']) {
|
||||||
case '0':
|
case '0':
|
||||||
case '2':
|
case '2':
|
||||||
default:
|
default:
|
||||||
// No groups option direct update.
|
// No groups option direct update.
|
||||||
$delete_sql = sprintf(
|
$delete_sql = sprintf(
|
||||||
'DELETE FROM %s
|
'DELETE FROM tevento
|
||||||
WHERE id_evento = %d',
|
WHERE id_evento = %d',
|
||||||
$table,
|
|
||||||
$id_evento
|
$id_evento
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -417,13 +420,12 @@ function events_delete($id_evento, $filter=null, $history=false, $force_node=fal
|
|||||||
|
|
||||||
$target_ids = db_get_all_rows_sql(
|
$target_ids = db_get_all_rows_sql(
|
||||||
sprintf(
|
sprintf(
|
||||||
'SELECT tu.id_evento FROM %s tu INNER JOIN ( %s ) tf
|
'SELECT tu.id_evento FROM tevento tu INNER JOIN ( %s ) tf
|
||||||
ON tu.estado = tf.estado
|
ON tu.estado = tf.estado
|
||||||
AND tu.evento = tf.evento
|
AND tu.evento = tf.evento
|
||||||
AND tu.id_agente = tf.id_agente
|
AND tu.id_agente = tf.id_agente
|
||||||
AND tu.id_agentmodule = tf.id_agentmodule
|
AND tu.id_agentmodule = tf.id_agentmodule
|
||||||
AND tf.max_id_evento = %d',
|
AND tf.max_id_evento = %d',
|
||||||
$table,
|
|
||||||
$sql,
|
$sql,
|
||||||
$id_evento
|
$id_evento
|
||||||
)
|
)
|
||||||
@ -440,8 +442,7 @@ function events_delete($id_evento, $filter=null, $history=false, $force_node=fal
|
|||||||
);
|
);
|
||||||
|
|
||||||
$delete_sql = sprintf(
|
$delete_sql = sprintf(
|
||||||
'DELETE FROM %s WHERE id_evento IN (%s)',
|
'DELETE FROM tevento WHERE id_evento IN (%s)',
|
||||||
$table,
|
|
||||||
join(', ', $target_ids)
|
join(', ', $target_ids)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1557,8 +1558,21 @@ function events_get_all(
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
$buffers = [
|
||||||
|
'settings' => [
|
||||||
|
'total' => $config['max_number_of_events_per_node'],
|
||||||
|
'translate' => [
|
||||||
|
'tev' => __('Total Events'),
|
||||||
|
'nev' => __('Total Events per node'),
|
||||||
|
'ev' => __('Events'),
|
||||||
|
'tevn' => __('Total number of events in this node reached'),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'data' => [],
|
||||||
|
];
|
||||||
if (empty($result_meta) === false) {
|
if (empty($result_meta) === false) {
|
||||||
foreach ($result_meta as $node => $value) {
|
foreach ($result_meta as $node => $value) {
|
||||||
|
$buffers['data'][$node] = count($value);
|
||||||
if (empty($value) === false) {
|
if (empty($value) === false) {
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
$value[$k]['server_id'] = $metaconsole_connections[$node];
|
$value[$k]['server_id'] = $metaconsole_connections[$node];
|
||||||
@ -1623,8 +1637,9 @@ function events_get_all(
|
|||||||
$end = ((int) $offset !== 0) ? ($offset + $limit) : $limit;
|
$end = ((int) $offset !== 0) ? ($offset + $limit) : $limit;
|
||||||
$finally = array_slice($data, $offset, $end, true);
|
$finally = array_slice($data, $offset, $end, true);
|
||||||
$return = [
|
$return = [
|
||||||
'data' => $finally,
|
'buffers' => $buffers,
|
||||||
'total' => $count,
|
'data' => $finally,
|
||||||
|
'total' => $count,
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$return = array_slice(
|
$return = array_slice(
|
||||||
@ -5017,21 +5032,12 @@ function events_get_field_value_by_event_id(
|
|||||||
) {
|
) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$meta = false;
|
|
||||||
$event = db_get_row('tevento', 'id_evento', $event_id);
|
$event = db_get_row('tevento', 'id_evento', $event_id);
|
||||||
|
|
||||||
// Replace each macro.
|
// Replace each macro.
|
||||||
if (strpos($value, '_agent_address_') !== false) {
|
if (strpos($value, '_agent_address_') !== false) {
|
||||||
if ($meta) {
|
$agente_table_name = 'tagente';
|
||||||
$agente_table_name = 'tmetaconsole_agent';
|
$filter = ['id_agente' => $event['id_agente']];
|
||||||
$filter = [
|
|
||||||
'id_tagente' => $event['id_agente'],
|
|
||||||
'id_tmetaconsole_setup' => $server_id,
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$agente_table_name = 'tagente';
|
|
||||||
$filter = ['id_agente' => $event['id_agente']];
|
|
||||||
}
|
|
||||||
|
|
||||||
$ip = db_get_value_filter('direccion', $agente_table_name, $filter);
|
$ip = db_get_value_filter('direccion', $agente_table_name, $filter);
|
||||||
// If agent does not have an IP, display N/A.
|
// If agent does not have an IP, display N/A.
|
||||||
@ -5048,11 +5054,6 @@ function events_get_field_value_by_event_id(
|
|||||||
|
|
||||||
if (strpos($value, '_module_address_') !== false) {
|
if (strpos($value, '_module_address_') !== false) {
|
||||||
if ($event['id_agentmodule'] != 0) {
|
if ($event['id_agentmodule'] != 0) {
|
||||||
if ($meta) {
|
|
||||||
$server = metaconsole_get_connection_by_id($server_id);
|
|
||||||
metaconsole_connect($server);
|
|
||||||
}
|
|
||||||
|
|
||||||
$module = db_get_row('tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']);
|
$module = db_get_row('tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']);
|
||||||
if (empty($module['ip_target'])) {
|
if (empty($module['ip_target'])) {
|
||||||
$module['ip_target'] = __('N/A');
|
$module['ip_target'] = __('N/A');
|
||||||
@ -5062,10 +5063,6 @@ function events_get_field_value_by_event_id(
|
|||||||
if (empty($module['nombre'])) {
|
if (empty($module['nombre'])) {
|
||||||
$module['nombre'] = __('N/A');
|
$module['nombre'] = __('N/A');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($meta) {
|
|
||||||
metaconsole_restore_db();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$value = str_replace('_module_address_', __('N/A'), $value);
|
$value = str_replace('_module_address_', __('N/A'), $value);
|
||||||
}
|
}
|
||||||
@ -5073,11 +5070,6 @@ function events_get_field_value_by_event_id(
|
|||||||
|
|
||||||
if (strpos($value, '_module_name_') !== false) {
|
if (strpos($value, '_module_name_') !== false) {
|
||||||
if ($event['id_agentmodule'] != 0) {
|
if ($event['id_agentmodule'] != 0) {
|
||||||
if ($meta) {
|
|
||||||
$server = metaconsole_get_connection_by_id($server_id);
|
|
||||||
metaconsole_connect($server);
|
|
||||||
}
|
|
||||||
|
|
||||||
$module = db_get_row('tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']);
|
$module = db_get_row('tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']);
|
||||||
if (empty($module['ip_target'])) {
|
if (empty($module['ip_target'])) {
|
||||||
$module['ip_target'] = __('N/A');
|
$module['ip_target'] = __('N/A');
|
||||||
@ -5088,10 +5080,6 @@ function events_get_field_value_by_event_id(
|
|||||||
io_safe_output($module['nombre']),
|
io_safe_output($module['nombre']),
|
||||||
$value
|
$value
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($meta) {
|
|
||||||
metaconsole_restore_db();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$value = str_replace('_module_name_', __('N/A'), $value);
|
$value = str_replace('_module_name_', __('N/A'), $value);
|
||||||
}
|
}
|
||||||
@ -5274,33 +5262,49 @@ function events_get_field_value_by_event_id(
|
|||||||
|
|
||||||
function events_get_instructions($event)
|
function events_get_instructions($event)
|
||||||
{
|
{
|
||||||
if (!is_array($event)) {
|
if (is_array($event) === false) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($event['event_type']) {
|
switch ($event['event_type']) {
|
||||||
case 'going_unknown':
|
case 'going_unknown':
|
||||||
if ($event['unknown_instructions'] != '') {
|
if ($event['unknown_instructions'] != '') {
|
||||||
$value = str_replace("\n", '<br>', io_safe_output($event['unknown_instructions']));
|
$value = str_replace(
|
||||||
|
"\n",
|
||||||
|
'<br>',
|
||||||
|
io_safe_output($event['unknown_instructions'])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'going_up_warning':
|
case 'going_up_warning':
|
||||||
case 'going_down_warning':
|
case 'going_down_warning':
|
||||||
if ($event['warning_instructions'] != '') {
|
if ($event['warning_instructions'] != '') {
|
||||||
$value = str_replace("\n", '<br>', io_safe_output($event['warning_instructions']));
|
$value = str_replace(
|
||||||
|
"\n",
|
||||||
|
'<br>',
|
||||||
|
io_safe_output($event['warning_instructions'])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'going_up_critical':
|
case 'going_up_critical':
|
||||||
case 'going_down_critical':
|
case 'going_down_critical':
|
||||||
if ($event['critical_instructions'] != '') {
|
if ($event['critical_instructions'] != '') {
|
||||||
$value = str_replace("\n", '<br>', io_safe_output($event['critical_instructions']));
|
$value = str_replace(
|
||||||
|
"\n",
|
||||||
|
'<br>',
|
||||||
|
io_safe_output($event['critical_instructions'])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Not posible.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($value)) {
|
if (isset($value) === false) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5318,7 +5322,11 @@ function events_get_instructions($event)
|
|||||||
$output .= '<span id="value_event_'.$event['id_evento'].'" class="nowrap">';
|
$output .= '<span id="value_event_'.$event['id_evento'].'" class="nowrap">';
|
||||||
$output .= '<span id="value_event_text_'.$event['id_evento'].'"></span>';
|
$output .= '<span id="value_event_text_'.$event['id_evento'].'"></span>';
|
||||||
$output .= '<a href="javascript:show_instructions('.$event['id_evento'].')">';
|
$output .= '<a href="javascript:show_instructions('.$event['id_evento'].')">';
|
||||||
$output .= html_print_image('images/default_list.png', true, ['title' => $over_text]).'</a></span>';
|
$output .= html_print_image(
|
||||||
|
'images/default_list.png',
|
||||||
|
true,
|
||||||
|
['title' => $over_text]
|
||||||
|
).'</a></span>';
|
||||||
$output .= '</center>';
|
$output .= '</center>';
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
@ -3519,7 +3519,7 @@ function ui_print_datatable(array $parameters)
|
|||||||
type: "POST",
|
type: "POST",
|
||||||
dataSrc: function (json) {
|
dataSrc: function (json) {
|
||||||
if (json.error) {
|
if (json.error) {
|
||||||
console.log(json.error);
|
console.error(json.error);
|
||||||
$("#error-'.$table_id.'").html(json.error);
|
$("#error-'.$table_id.'").html(json.error);
|
||||||
$("#error-'.$table_id.'").dialog({
|
$("#error-'.$table_id.'").dialog({
|
||||||
title: "Filter failed",
|
title: "Filter failed",
|
||||||
@ -3535,6 +3535,19 @@ function ui_print_datatable(array $parameters)
|
|||||||
}
|
}
|
||||||
}).parent().addClass("ui-state-error");
|
}).parent().addClass("ui-state-error");
|
||||||
} else {';
|
} else {';
|
||||||
|
|
||||||
|
if (isset($parameters['ajax_return_operation']) === true
|
||||||
|
&& empty($parameters['ajax_return_operation']) === false
|
||||||
|
&& isset($parameters['ajax_return_operation_function']) === true
|
||||||
|
&& empty($parameters['ajax_return_operation_function']) === false
|
||||||
|
) {
|
||||||
|
$js .= '
|
||||||
|
if (json.'.$parameters['ajax_return_operation'].' !== undefined) {
|
||||||
|
'.$parameters['ajax_return_operation_function'].'(json.'.$parameters['ajax_return_operation'].');
|
||||||
|
}
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($parameters['ajax_postprocess'])) {
|
if (isset($parameters['ajax_postprocess'])) {
|
||||||
$js .= '
|
$js .= '
|
||||||
if (json.data) {
|
if (json.data) {
|
||||||
|
@ -344,3 +344,32 @@ div.multi-response-buttons {
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#events_buffers_display {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
#events_buffers_display ul {
|
||||||
|
min-width: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#events_buffers_display li {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#events_buffers_display ul li span.info {
|
||||||
|
flex: 1 1 100px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
#events_buffers_display ul li span.danger {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
#events_buffers_display ul li span.text {
|
||||||
|
color: #3f3f3f;
|
||||||
|
}
|
||||||
|
@ -352,6 +352,7 @@ if (is_ajax() === true) {
|
|||||||
$history
|
$history
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$buffers = [];
|
||||||
if (is_metaconsole() === false
|
if (is_metaconsole() === false
|
||||||
|| (is_metaconsole() === true
|
|| (is_metaconsole() === true
|
||||||
&& empty($filter['server_id']) === false)
|
&& empty($filter['server_id']) === false)
|
||||||
@ -370,6 +371,7 @@ if (is_ajax() === true) {
|
|||||||
$count = $count['0']['nitems'];
|
$count = $count['0']['nitems'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$buffers = $events['buffers'];
|
||||||
$count = $events['total'];
|
$count = $events['total'];
|
||||||
$events = $events['data'];
|
$events = $events['data'];
|
||||||
}
|
}
|
||||||
@ -471,6 +473,7 @@ if (is_ajax() === true) {
|
|||||||
echo json_encode(
|
echo json_encode(
|
||||||
[
|
[
|
||||||
'data' => ($data ?? []),
|
'data' => ($data ?? []),
|
||||||
|
'buffers' => $buffers,
|
||||||
'recordsTotal' => $count,
|
'recordsTotal' => $count,
|
||||||
'recordsFiltered' => $count,
|
'recordsFiltered' => $count,
|
||||||
]
|
]
|
||||||
@ -1740,6 +1743,7 @@ try {
|
|||||||
|
|
||||||
// Close.
|
// Close.
|
||||||
$active_filters_div .= '</div>';
|
$active_filters_div .= '</div>';
|
||||||
|
$active_filters_div .= '<div id="events_buffers_display"></div>';
|
||||||
|
|
||||||
$table_id = 'events';
|
$table_id = 'events';
|
||||||
$form_id = 'events_form';
|
$form_id = 'events_form';
|
||||||
@ -1747,23 +1751,23 @@ try {
|
|||||||
// Print datatable.
|
// Print datatable.
|
||||||
ui_print_datatable(
|
ui_print_datatable(
|
||||||
[
|
[
|
||||||
'id' => $table_id,
|
'id' => $table_id,
|
||||||
'class' => 'info_table events',
|
'class' => 'info_table events',
|
||||||
'style' => 'width: 100%;',
|
'style' => 'width: 100%;',
|
||||||
'ajax_url' => 'operation/events/events',
|
'ajax_url' => 'operation/events/events',
|
||||||
'ajax_data' => [
|
'ajax_data' => [
|
||||||
'get_events' => 1,
|
'get_events' => 1,
|
||||||
'history' => (int) $history,
|
'history' => (int) $history,
|
||||||
],
|
],
|
||||||
'form' => [
|
'form' => [
|
||||||
'id' => $form_id,
|
'id' => $form_id,
|
||||||
'class' => 'flex-row',
|
'class' => 'flex-row',
|
||||||
'html' => $filter,
|
'html' => $filter,
|
||||||
'inputs' => [],
|
'inputs' => [],
|
||||||
'extra_buttons' => $buttons,
|
'extra_buttons' => $buttons,
|
||||||
],
|
],
|
||||||
'extra_html' => $active_filters_div,
|
'extra_html' => $active_filters_div,
|
||||||
'pagination_options' => [
|
'pagination_options' => [
|
||||||
[
|
[
|
||||||
$config['block_size'],
|
$config['block_size'],
|
||||||
10,
|
10,
|
||||||
@ -1785,19 +1789,21 @@ try {
|
|||||||
'All',
|
'All',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'order' => [
|
'order' => [
|
||||||
'field' => 'timestamp',
|
'field' => 'timestamp',
|
||||||
'direction' => 'desc',
|
'direction' => 'desc',
|
||||||
],
|
],
|
||||||
'column_names' => $column_names,
|
'column_names' => $column_names,
|
||||||
'columns' => $fields,
|
'columns' => $fields,
|
||||||
'no_sortable_columns' => [
|
'no_sortable_columns' => [
|
||||||
-1,
|
-1,
|
||||||
-2,
|
-2,
|
||||||
'column-instructions',
|
'column-instructions',
|
||||||
],
|
],
|
||||||
'ajax_postprocess' => 'process_datatables_item(item)',
|
'ajax_postprocess' => 'process_datatables_item(item)',
|
||||||
'drawCallback' => 'process_datatables_callback(this, settings)',
|
'ajax_return_operation' => 'buffers',
|
||||||
|
'ajax_return_operation_function' => 'process_buffers',
|
||||||
|
'drawCallback' => 'process_datatables_callback(this, settings)',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@ -2013,8 +2019,46 @@ function process_datatables_callback(table, settings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_datatables_item(item) {
|
function process_buffers(buffers) {
|
||||||
|
$('#events_buffers_display').empty();
|
||||||
|
console.log(buffers);
|
||||||
|
if(buffers.settings != undefined && buffers.data.length > 0) {
|
||||||
|
var html = '<h3>'+buffers.settings.translate.nev;
|
||||||
|
html += ': ('+buffers.settings.total+')</h3>';
|
||||||
|
html += '<ul>';
|
||||||
|
Object.entries(buffers.data).forEach(function (element) {
|
||||||
|
html += '<li>';
|
||||||
|
html += '<span><b>';
|
||||||
|
html += buffers.settings.translate.ev+' ';
|
||||||
|
html += element[0];
|
||||||
|
html += ': ';
|
||||||
|
html += '</b></span>';
|
||||||
|
|
||||||
|
var class_total = 'info';
|
||||||
|
var str_total = '';
|
||||||
|
if(buffers.settings.total == element[1]) {
|
||||||
|
class_total += ' danger';
|
||||||
|
str_total = buffers.settings.translate.tevn;
|
||||||
|
}
|
||||||
|
html += '<span class='+class_total+'>';
|
||||||
|
html += element[1];
|
||||||
|
if(str_total != '') {
|
||||||
|
html += '<span class="text">';
|
||||||
|
html += ' '+str_total;
|
||||||
|
html += '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
html += '</span>';
|
||||||
|
|
||||||
|
html += '</li>';
|
||||||
|
});
|
||||||
|
html += '</ul>';
|
||||||
|
|
||||||
|
$('#events_buffers_display').html(html);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function process_datatables_item(item) {
|
||||||
// Url to go to node from meta.
|
// Url to go to node from meta.
|
||||||
var server_url = '';
|
var server_url = '';
|
||||||
var hashdata = '';
|
var hashdata = '';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user