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
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* LINE Notify Transport
|
|
*/
|
|
|
|
namespace LibreNMS\Alert\Transport;
|
|
|
|
use LibreNMS\Alert\Transport;
|
|
use LibreNMS\Exceptions\AlertTransportDeliveryException;
|
|
use LibreNMS\Util\Http;
|
|
|
|
class Linenotify extends Transport
|
|
{
|
|
protected string $name = 'LINE Notify';
|
|
|
|
public function deliverAlert(array $alert_data): bool
|
|
{
|
|
// TODO possible to attach graph images
|
|
$lineUrl = 'https://notify-api.line.me/api/notify';
|
|
$lineFields = ['message' => $alert_data['msg']];
|
|
|
|
$res = Http::client()
|
|
->withToken($this->config['line-notify-access-token'])
|
|
->asForm()
|
|
->post($lineUrl, $lineFields);
|
|
|
|
if ($res->successful()) {
|
|
return true;
|
|
}
|
|
|
|
throw new AlertTransportDeliveryException($alert_data, $res->status(), $res->body(), $alert_data['msg'], $lineFields);
|
|
}
|
|
|
|
public static function configTemplate(): array
|
|
{
|
|
return [
|
|
'config' => [
|
|
[
|
|
'title' => 'Token',
|
|
'name' => 'line-notify-access-token',
|
|
'descr' => 'LINE Notify Token',
|
|
'type' => 'text',
|
|
],
|
|
],
|
|
'validation' => [
|
|
'line-notify-access-token' => 'required|string',
|
|
],
|
|
];
|
|
}
|
|
}
|