Add new function of locate agent in servers. Tiquet: #3119

(cherry picked from commit 4c6451372b)
This commit is contained in:
m-lopez-f 2015-12-30 13:42:34 +01:00
parent e91dc72885
commit fea29a84a0
1 changed files with 47 additions and 0 deletions

View File

@ -1555,6 +1555,53 @@ function api_get_group_agent_by_name($thrash1, $thrash2, $other, $thrash3) {
}
}
/**
* Get id server whare agent is located, and print all the result like a csv.
*
* @param $id name of agent.
* @param $thrash1 Don't use.
* @param $thrash2 Don't use.
* example:
*
* api.php?op=get&op2=locate_agent&return_type=csv&id=Pepito&other_mode=url_encode_separator_|
*
* @param $thrash3 Don't use.
*/
function api_get_locate_agent($id, $thrash1, $thrash2, $thrash3) {
if (!is_metaconsole())
return;
$servers = db_get_all_rows_sql ("SELECT *
FROM tmetaconsole_setup
WHERE disabled = 0");
if ($servers === false)
$servers = array();
foreach($servers as $server) {
$id_server = $server['id'];
if (metaconsole_connect($server) == NOERR) {
$agent_id = agents_get_agent_id($id,true);
if ($agent_id) {
$group_servers[]['server'] = $id_server;
}
}
metaconsole_restore_db();
}
if (count($group_servers) > 0 and $group_servers !== false) {
$data = array('type' => 'array', 'data' => $group_servers);
returnData('csv', $data, ';');
}
else {
returnError('error_locate_agents', 'No agents located.');
}
}
/**
* Get id group for an agent, and print all the result like a csv.
*