mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Graylog API properly throw errors (#15188)
* Graylog API properly throw errors remove unused legacy graylog code * Add type casts
This commit is contained in:
@@ -34,26 +34,21 @@ class GraylogApi
|
||||
private \Illuminate\Http\Client\PendingRequest $client;
|
||||
private string $api_prefix = '';
|
||||
|
||||
public function __construct(array $config = [])
|
||||
public function __construct()
|
||||
{
|
||||
if (version_compare(Config::get('graylog.version', '2.4'), '2.1', '>=')) {
|
||||
$this->api_prefix = '/api';
|
||||
}
|
||||
|
||||
if (empty($config)) {
|
||||
$base_uri = Config::get('graylog.server');
|
||||
if ($port = Config::get('graylog.port')) {
|
||||
$base_uri .= ':' . $port;
|
||||
}
|
||||
|
||||
$config = [
|
||||
'base_uri' => $base_uri,
|
||||
'auth' => [Config::get('graylog.username'), Config::get('graylog.password')],
|
||||
'headers' => ['Accept' => 'application/json'],
|
||||
];
|
||||
$base_uri = Config::get('graylog.server');
|
||||
if ($port = Config::get('graylog.port')) {
|
||||
$base_uri .= ':' . $port;
|
||||
}
|
||||
|
||||
$this->client = Http::client()->withOptions($config);
|
||||
$this->client = Http::client()
|
||||
->baseUrl($base_uri)
|
||||
->withBasicAuth(Config::get('graylog.username'), Config::get('graylog.password'))
|
||||
->acceptJson();
|
||||
}
|
||||
|
||||
public function getStreams(): array
|
||||
@@ -92,7 +87,7 @@ class GraylogApi
|
||||
'filter' => $filter,
|
||||
];
|
||||
|
||||
$response = $this->client->get($uri, $data);
|
||||
$response = $this->client->get($uri, $data)->throw();
|
||||
|
||||
return $response->json() ?: [];
|
||||
}
|
||||
|
@@ -61,12 +61,12 @@ class GraylogController extends SimpleTableController
|
||||
]);
|
||||
|
||||
$search = $request->get('searchPhrase');
|
||||
$device_id = $request->get('device');
|
||||
$device_id = (int) $request->get('device');
|
||||
$device = $device_id ? Device::find($device_id) : null;
|
||||
$range = $request->get('range', 0);
|
||||
$limit = $request->get('rowCount', 10);
|
||||
$page = $request->get('current', 1);
|
||||
$offset = ($page - 1) * $limit;
|
||||
$range = (int) $request->get('range', 0);
|
||||
$limit = (int) $request->get('rowCount', 10);
|
||||
$page = (int) $request->get('current', 1);
|
||||
$offset = (int) (($page - 1) * $limit);
|
||||
$loglevel = $request->get('loglevel') ?? Config::get('graylog.loglevel');
|
||||
|
||||
$query = $api->buildSimpleQuery($search, $device) .
|
||||
|
Reference in New Issue
Block a user