mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Add no_proxy and other proxy related settings Set user agent on all http client requests Unify http client usage * Style fixes * Remove useless use statements * Correct variable, good job phpstan * Add tests fix https_proxy bug add tcp:// to the config settings format * style and lint fixes * Remove guzzle from the direct dependencies * Use built in Laravel testing functionality * update baseline
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\AlertTransport;
|
|
use App\Models\Device;
|
|
use Illuminate\Http\Request;
|
|
use LibreNMS\Alert\AlertData;
|
|
use LibreNMS\Exceptions\AlertTransportDeliveryException;
|
|
|
|
class AlertTransportController extends Controller
|
|
{
|
|
public function test(Request $request, AlertTransport $transport): \Illuminate\Http\JsonResponse
|
|
{
|
|
/** @var Device $device */
|
|
$device = Device::with('location')->first();
|
|
$alert_data = AlertData::testData($device);
|
|
|
|
try {
|
|
$result = $transport->instance()->deliverAlert($alert_data);
|
|
|
|
if ($result === true) {
|
|
return response()->json(['status' => 'ok']);
|
|
}
|
|
} catch (AlertTransportDeliveryException $e) {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => strip_tags($e->getMessage()),
|
|
]);
|
|
} catch (\Exception $e) {
|
|
\Log::error($e);
|
|
$result = basename($e->getFile(), '.php') . ':' . $e->getLine() . ' ' . $e->getMessage();
|
|
}
|
|
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'message' => strip_tags($result),
|
|
]);
|
|
}
|
|
}
|