Files
librenms-librenms/app/Http/Controllers/AlertTransportController.php
Tony Murray 04bb75f5f3 Alert transport cleanup, no_proxy support and other proxy cleanups (#14763)
* 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
2023-05-23 09:25:17 -05:00

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),
]);
}
}