2021-11-03 13:37:57 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
use LibreNMS\Alert\Transport;
|
|
|
|
|
2024-08-02 22:23:31 -05:00
|
|
|
/** @extends Factory<\App\Models\AlertTransport> */
|
2021-11-03 13:37:57 -05:00
|
|
|
class AlertTransportFactory extends Factory
|
|
|
|
{
|
|
|
|
public function definition(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'transport_name' => $this->faker->text(30),
|
|
|
|
'transport_type' => $this->faker->randomElement(Transport::list()),
|
|
|
|
'is_default' => 0,
|
|
|
|
'transport_config' => '',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function api(
|
|
|
|
string $options = '',
|
|
|
|
string $method = 'get',
|
|
|
|
string $body = '',
|
|
|
|
string $url = 'https://librenms.org',
|
|
|
|
string $headers = 'test=header',
|
|
|
|
string $username = '',
|
|
|
|
string $password = ''
|
|
|
|
): AlertTransportFactory {
|
|
|
|
$config = [
|
|
|
|
'api-method' => $method,
|
|
|
|
'api-url' => $url,
|
|
|
|
'api-options' => $options,
|
|
|
|
'api-headers' => $headers,
|
|
|
|
'api-body' => $body,
|
|
|
|
'api-auth-username' => $username,
|
|
|
|
'api-auth-password' => $password,
|
|
|
|
];
|
|
|
|
|
|
|
|
return $this->state(function () use ($config) {
|
|
|
|
return [
|
|
|
|
'transport_type' => 'api',
|
|
|
|
'transport_config' => $config,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|