[#3c9g25] Add support for new endpoint to collect node information
This commit is contained in:
parent
979bdc1f9f
commit
564d947f7e
4 changed files with 74 additions and 5 deletions
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Admin\Nodes;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Repositories\Wings\DaemonConfigurationRepository;
|
||||
|
||||
class SystemInformationController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonConfigurationRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* SystemInformationController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonConfigurationRepository $repository
|
||||
*/
|
||||
public function __construct(DaemonConfigurationRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns system information from the Daemon.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function __invoke(Request $request, Node $node)
|
||||
{
|
||||
$data = $this->repository->setNode($node)->getSystemInformation();
|
||||
|
||||
return JsonResponse::create([
|
||||
'version' => $data['version'] ?? '',
|
||||
'system' => [
|
||||
'type' => Str::title($data['os'] ?? 'Unknown'),
|
||||
'arch' => $data['architecture'] ?? '--',
|
||||
'release' => $data['kernel_version'] ?? '--',
|
||||
'cpus' => $data['cpu_count'] ?? 0,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,25 @@
|
|||
|
||||
namespace Pterodactyl\Repositories\Wings;
|
||||
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
|
||||
class DaemonConfigurationRepository extends DaemonRepository
|
||||
{
|
||||
/**
|
||||
* Returns system information from the wings instance.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function getSystemInformation(): array
|
||||
{
|
||||
try {
|
||||
$response = $this->getHttpClient()->get('/api/system');
|
||||
} catch (TransferException $exception) {
|
||||
throw new DaemonConnectionException($exception);
|
||||
}
|
||||
|
||||
return json_decode($response->getBody()->__toString(), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,14 +153,11 @@
|
|||
(function getInformation() {
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/v1',
|
||||
url: '/admin/nodes/view/{{ $node->id }}/system-information',
|
||||
timeout: 5000,
|
||||
headers: {
|
||||
'X-Access-Token': '{{ $node->daemonSecret }}'
|
||||
},
|
||||
}).done(function (data) {
|
||||
$('[data-attr="info-version"]').html(data.version);
|
||||
$('[data-attr="info-system"]').html(data.system.type + '(' + data.system.arch + ') <code>' + data.system.release + '</code>');
|
||||
$('[data-attr="info-system"]').html(data.system.type + ' (' + data.system.arch + ') <code>' + data.system.release + '</code>');
|
||||
$('[data-attr="info-cpus"]').html(data.system.cpus);
|
||||
}).fail(function (jqXHR) {
|
||||
|
||||
|
|
|
@ -150,6 +150,7 @@ Route::group(['prefix' => 'nodes'], function () {
|
|||
Route::get('/view/{node}/configuration', 'Nodes\NodeViewController@configuration')->name('admin.nodes.view.configuration');
|
||||
Route::get('/view/{node}/allocation', 'Nodes\NodeViewController@allocations')->name('admin.nodes.view.allocation');
|
||||
Route::get('/view/{node}/servers', 'Nodes\NodeViewController@servers')->name('admin.nodes.view.servers');
|
||||
Route::get('/view/{node}/system-information', 'Nodes\SystemInformationController');
|
||||
Route::get('/view/{node}/settings/token', 'NodesController@setToken')->name('admin.nodes.view.configuration.token');
|
||||
|
||||
Route::post('/new', 'NodesController@store');
|
||||
|
|
Loading…
Reference in a new issue