fixed alias filter in get events api method (metaconsole)

This commit is contained in:
alejandro.campos@artica.es 2022-01-11 15:26:31 +01:00
parent c360a3a06c
commit 8123d9e44b
2 changed files with 22 additions and 7 deletions

View File

@ -162,9 +162,13 @@ function agents_locate_agent(string $field)
* *
* @return array|boolean Agents ids or false if error. * @return array|boolean Agents ids or false if error.
*/ */
function agents_get_agent_id_by_alias($alias) function agents_get_agent_id_by_alias($alias, $is_metaconsole=false)
{ {
return db_get_all_rows_sql("SELECT id_agente FROM tagente WHERE upper(alias) LIKE upper('%$alias%')"); if ($is_metaconsole === true) {
return db_get_all_rows_sql("SELECT id_tagente FROM tmetaconsole_agent WHERE upper(alias) LIKE upper('%$alias%')");
} else {
return db_get_all_rows_sql("SELECT id_agente FROM tagente WHERE upper(alias) LIKE upper('%$alias%')");
}
} }

View File

@ -9925,12 +9925,19 @@ function otherParameter2Filter($other, $return_as_array=false, $use_agent_name=f
if (isset($other['data'][2]) && $other['data'][2] != '') { if (isset($other['data'][2]) && $other['data'][2] != '') {
if ($use_agent_name === false) { if ($use_agent_name === false) {
$idAgents = agents_get_agent_id_by_alias($other['data'][2]); $idAgents = agents_get_agent_id_by_alias($other['data'][2], is_metaconsole());
if (!empty($idAgents)) { if (!empty($idAgents)) {
$idAgent = []; $idAgent = [];
$id_agent_field = 'id_agente';
if (is_metaconsole() === true) {
$id_agent_field = 'id_tagente';
}
foreach ($idAgents as $key => $value) { foreach ($idAgents as $key => $value) {
$idAgent[] .= $value['id_agente']; $idAgent[] .= $value[$id_agent_field];
} }
$filter[] = 'id_agente IN ('.implode(',', $idAgent).')'; $filter[] = 'id_agente IN ('.implode(',', $idAgent).')';
@ -11438,7 +11445,7 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
global $config; global $config;
$table_events = 'tevento'; $table_events = 'tevento';
if (defined('METACONSOLE')) { if (is_metaconsole() === true) {
$table_events = 'tmetaconsole_event'; $table_events = 'tmetaconsole_event';
} }
@ -11671,7 +11678,7 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db
ORDER BY criticity DESC ORDER BY criticity DESC
LIMIT 1'; LIMIT 1';
} else { } else {
if (defined('METACONSOLE')) { if (is_metaconsole() === true) {
$sql = 'SELECT *, $sql = 'SELECT *,
(SELECT t2.nombre (SELECT t2.nombre
FROM tgrupo t2 FROM tgrupo t2
@ -11972,7 +11979,7 @@ function api_set_event($id_event, $unused1, $params, $unused2, $unused3)
* @param $returnType * @param $returnType
* @param $user_in_db * @param $user_in_db
*/ */
function api_get_events($trash1, $trash2, $other, $returnType, $user_in_db=null) function api_get_events($node_id, $trash2, $other, $returnType, $user_in_db=null)
{ {
if ($user_in_db !== null) { if ($user_in_db !== null) {
$correct = get_events_with_user( $correct = get_events_with_user(
@ -12017,6 +12024,10 @@ function api_get_events($trash1, $trash2, $other, $returnType, $user_in_db=null)
} }
if (is_metaconsole()) { if (is_metaconsole()) {
if ((int) $node_id !== 0) {
$filterString .= ' AND server_id = '.$node_id;
}
$dataRows = db_get_all_rows_filter('tmetaconsole_event', $filterString); $dataRows = db_get_all_rows_filter('tmetaconsole_event', $filterString);
} else { } else {
$dataRows = db_get_all_rows_filter('tevento', $filterString); $dataRows = db_get_all_rows_filter('tevento', $filterString);