Files
librenms-librenms/app/Http/Controllers/AlertTransportController.php
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.2 KiB
PHP
Raw Normal View History

2021-10-06 07:29:47 -05:00
<?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;
2021-10-06 07:29:47 -05:00
class AlertTransportController extends Controller
{
public function test(Request $request, AlertTransport $transport): \Illuminate\Http\JsonResponse
{
/** @var Device $device */
2021-10-06 07:29:47 -05:00
$device = Device::with('location')->first();
$alert_data = AlertData::testData($device);
2021-10-06 07:29:47 -05:00
try {
$result = $transport->instance()->deliverAlert($alert_data);
2021-10-06 07:29:47 -05:00
if ($result === true) {
return response()->json(['status' => 'ok']);
}
} catch (AlertTransportDeliveryException $e) {
return response()->json([
'status' => 'error',
'message' => strip_tags($e->getMessage()),
]);
2021-10-06 07:29:47 -05:00
} catch (\Exception $e) {
\Log::error($e);
$result = basename($e->getFile(), '.php') . ':' . $e->getLine() . ' ' . $e->getMessage();
2021-10-06 07:29:47 -05:00
}
return response()->json([
'status' => 'error',
'message' => strip_tags($result),
2021-10-06 07:29:47 -05:00
]);
}
}