Files
librenms-librenms/LibreNMS/Alert/Transport/Clickatell.php
T

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

74 lines
2.4 KiB
PHP
Raw Normal View History

<?php
2015-10-11 07:11:29 +00:00
/* Copyright (C) 2015 Daniel Preussker <f0o@librenms.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>. */
2015-10-11 07:11:29 +00:00
/**
* Clickatell REST-API Transport
2021-09-10 20:09:53 +02:00
*
2015-10-11 07:11:29 +00:00
* @author f0o <f0o@librenms.org>
* @copyright 2015 f0o, LibreNMS
* @license GPL
*/
2020-09-21 14:54:51 +02:00
namespace LibreNMS\Alert\Transport;
2015-10-11 07:11:29 +00:00
2018-07-21 13:34:59 -06:00
use LibreNMS\Alert\Transport;
use LibreNMS\Exceptions\AlertTransportDeliveryException;
use LibreNMS\Util\Http;
2018-07-21 13:34:59 -06:00
class Clickatell extends Transport
{
public function deliverAlert(array $alert_data): bool
2018-07-21 13:34:59 -06:00
{
$url = 'https://platform.clickatell.com/messages/http/send';
$params = [
'apiKey' => $this->config['clickatell-token'],
'to' => implode(',', preg_split('/([,\r\n]+)/', $this->config['clickatell-numbers'])),
'content' => $alert_data['title'],
];
$res = Http::client()->get($url, $params);
2021-03-24 15:13:43 +01:00
if ($res->successful()) {
return true;
}
2020-09-21 14:54:51 +02:00
throw new AlertTransportDeliveryException($alert_data, $res->status(), $res->body(), $alert_data['title'], $params);
2015-10-11 07:11:29 +00:00
}
2018-07-21 13:34:59 -06:00
public static function configTemplate(): array
2018-07-21 13:34:59 -06:00
{
return [
'config' => [
[
'title' => 'Token',
2024-01-05 05:39:12 +01:00
'name' => 'clickatell-token',
2018-07-21 13:34:59 -06:00
'descr' => 'Clickatell Token',
2024-01-05 05:39:12 +01:00
'type' => 'password',
2018-07-21 13:34:59 -06:00
],
[
'title' => 'Mobile Numbers',
2024-01-05 05:39:12 +01:00
'name' => 'clickatell-numbers',
2018-07-21 13:34:59 -06:00
'descr' => 'Enter mobile numbers, can be new line or comma separated',
2024-01-05 05:39:12 +01:00
'type' => 'textarea',
2018-07-21 13:34:59 -06:00
],
],
'validation' => [
2024-01-05 05:39:12 +01:00
'clickatell-token' => 'required|string',
2018-07-21 13:34:59 -06:00
'clickatell-numbers' => 'required|string',
],
];
}
2015-10-11 07:11:29 +00:00
}