#10316 new function return_agent_macros

This commit is contained in:
Jonathan 2023-11-23 17:21:37 +01:00
parent 2a2a1b6e3e
commit fafe4bc9b4
3 changed files with 90 additions and 2 deletions

View File

@ -38,6 +38,7 @@ $isFunctionPolicies = enterprise_include_once('include/functions_policies.php');
require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_modules.php';
require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_servers.php'; require_once $config['homedir'].'/include/functions_servers.php';
require_once $config['homedir'].'/include/functions_macros.php';
$search_string = get_parameter('search_string'); $search_string = get_parameter('search_string');
@ -953,7 +954,16 @@ if ($modules !== false) {
if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') { if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') {
$custom_field_name = substr($module['ip_target'], 1, -1); $custom_field_name = substr($module['ip_target'], 1, -1);
$custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name); $custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name);
$title .= '<br/>IP: '.$custom_value; if (isset($custom_value) && $custom_value !== false) {
$title .= '<br/>IP: '.$custom_value;
} else {
$array_macros = return_agent_macros($id_agente);
if (isset($array_macros[$module['ip_target']])) {
$title .= '<br/>IP: '.$array_macros[$module['ip_target']];
} else {
$title .= '<br/>IP: '.$module['ip_target'];
}
}
} else { } else {
$title .= '<br/>IP: '.$module['ip_target']; $title .= '<br/>IP: '.$module['ip_target'];
} }

View File

@ -35,6 +35,7 @@ if (check_login()) {
include_once $config['homedir'].'/include/functions_agents.php'; include_once $config['homedir'].'/include/functions_agents.php';
include_once $config['homedir'].'/include/functions_modules.php'; include_once $config['homedir'].'/include/functions_modules.php';
include_once $config['homedir'].'/include/functions_ui.php'; include_once $config['homedir'].'/include/functions_ui.php';
include_once $config['homedir'].'/include/functions_macros.php';
enterprise_include_once('include/functions_metaconsole.php'); enterprise_include_once('include/functions_metaconsole.php');
$get_plugin_macros = get_parameter('get_plugin_macros'); $get_plugin_macros = get_parameter('get_plugin_macros');
@ -1197,7 +1198,23 @@ if (check_login()) {
); );
if (strlen($module['ip_target']) !== 0) { if (strlen($module['ip_target']) !== 0) {
$title .= '<br/>IP: '.$module['ip_target']; // Check if value is custom field.
if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') {
$custom_field_name = substr($module['ip_target'], 1, -1);
$custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name);
if (isset($custom_value) && $custom_value !== false) {
$title .= '<br/>IP: '.$custom_value;
} else {
$array_macros = return_agent_macros($id_agente);
if (isset($array_macros[$module['ip_target']])) {
$title .= '<br/>IP: '.$array_macros[$module['ip_target']];
} else {
$title .= '<br/>IP: '.$module['ip_target'];
}
}
} else {
$title .= '<br/>IP: '.$module['ip_target'];
}
} }
$last_status_change_text = __('Time elapsed since last status change: '); $last_status_change_text = __('Time elapsed since last status change: ');

View File

@ -0,0 +1,61 @@
<?php
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// 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.
/**
* Return array with macros of agent like core.pm
*
* @param interger $id_agente Id agent to return data.
*
* @return array Array with all macros.
*/
function return_agent_macros($id_agente)
{
global $config;
$array_macros = [];
$grupo = [];
$agente = db_get_row_sql(
'SELECT * FROM tagente WHERE id_agente = '.$id_agente
);
if (isset($agente['id_grupo'])) {
$grupo = db_get_row_sql(
'SELECT * FROM tgrupo WHERE id_grupo = '.$agente['id_grupo']
);
}
if (isset($agente['server_name'])) {
$server_ip = db_get_row_sql(
'SELECT ip_address FROM tserver WHERE name = "'.$agente['server_name'].'"'
)['id_address'];
}
$array_macros = [
'_agentname_' => ($agente['nombre']) ?: '',
'_agentalias_' => ($agente['alias']) ?: '',
'_agent_' => ($agente['alias']) ?: (($agente['nombre']) ?: ''),
'_agentcustomid_' => ($agente['custom_id']) ?: '',
'_agentdescription_' => ($agente['comentarios']) ?: '',
'_agentgroup_' => ($grupo['nombre']) ?: '',
'_agentos_' => ($agente['id_os']) ?: '',
'_address_' => ($agente['direccion']) ?: '',
'_homeurl_' => ($config['public_url']) ?: '',
'_groupcontact_' => ($agente['contact']) ?: '',
'_groupcustomid_' => ($agente['custom_id']) ?: '',
'_groupother_' => ($agente['other']) ?: '',
'_server_ip_' => ($server_ip) ?: '',
'_server_name_' => ($agente['server_name']) ?: '',
];
return $array_macros;
}