mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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
This commit is contained in:
@@ -5,41 +5,19 @@ namespace App\Http\Controllers;
|
||||
use App\Models\AlertTransport;
|
||||
use App\Models\Device;
|
||||
use Illuminate\Http\Request;
|
||||
use LibreNMS\Alert\AlertUtil;
|
||||
use LibreNMS\Config;
|
||||
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();
|
||||
$obj = [
|
||||
'hostname' => $device->hostname,
|
||||
'device_id' => $device->device_id,
|
||||
'sysDescr' => $device->sysDescr,
|
||||
'version' => $device->version,
|
||||
'hardware' => $device->hardware,
|
||||
'location' => $device->location,
|
||||
'title' => 'Testing transport from ' . Config::get('project_name'),
|
||||
'elapsed' => '11s',
|
||||
'alert_id' => '000',
|
||||
'id' => '000',
|
||||
'faults' => [],
|
||||
'uid' => '000',
|
||||
'severity' => 'critical',
|
||||
'rule' => 'macros.device = 1',
|
||||
'name' => 'Test-Rule',
|
||||
'string' => '#1: test => string;',
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'contacts' => AlertUtil::getContacts($device->toArray()),
|
||||
'state' => '1',
|
||||
'msg' => 'This is a test alert',
|
||||
];
|
||||
$alert_data = AlertData::testData($device);
|
||||
|
||||
$opts = Config::get('alert.transports.' . $transport->transport_type);
|
||||
try {
|
||||
$result = $transport->instance()->deliverAlert($obj, $opts);
|
||||
$result = $transport->instance()->deliverAlert($alert_data);
|
||||
|
||||
if ($result === true) {
|
||||
return response()->json(['status' => 'ok']);
|
||||
@@ -47,7 +25,7 @@ class AlertTransportController extends Controller
|
||||
} catch (AlertTransportDeliveryException $e) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage(),
|
||||
'message' => strip_tags($e->getMessage()),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error($e);
|
||||
@@ -56,7 +34,7 @@ class AlertTransportController extends Controller
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => $result,
|
||||
'message' => strip_tags($result),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user