Files

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

51 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2019-09-05 12:30:53 +08:00
<?php
/**
* LINE Notify Transport
*/
2020-09-21 14:54:51 +02:00
2019-09-05 12:30:53 +08:00
namespace LibreNMS\Alert\Transport;
use LibreNMS\Alert\Transport;
use LibreNMS\Exceptions\AlertTransportDeliveryException;
use LibreNMS\Util\Http;
2019-09-05 12:30:53 +08:00
class Linenotify extends Transport
{
protected string $name = 'LINE Notify';
2021-10-06 07:29:47 -05:00
public function deliverAlert(array $alert_data): bool
2019-09-05 12:30:53 +08:00
{
// TODO possible to attach graph images
$lineUrl = 'https://notify-api.line.me/api/notify';
$lineFields = ['message' => $alert_data['msg']];
2020-09-21 14:54:51 +02:00
$res = Http::client()
->withToken($this->config['line-notify-access-token'])
->asForm()
->post($lineUrl, $lineFields);
2019-09-05 12:30:53 +08:00
if ($res->successful()) {
return true;
2019-09-05 12:30:53 +08:00
}
2020-09-21 14:54:51 +02:00
throw new AlertTransportDeliveryException($alert_data, $res->status(), $res->body(), $alert_data['msg'], $lineFields);
2019-09-05 12:30:53 +08:00
}
public static function configTemplate(): array
2019-09-05 12:30:53 +08:00
{
return [
'config' => [
[
'title' => 'Token',
'name' => 'line-notify-access-token',
'descr' => 'LINE Notify Token',
'type' => 'password',
2019-09-05 12:30:53 +08:00
],
],
'validation' => [
'line-notify-access-token' => 'required|string',
],
];
}
}