Files

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

63 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2021-03-06 17:48:20 -03:00
<?php
/**
* LibreNMS Google Chat alerting transport
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://librenms.org
2021-09-10 20:09:53 +02:00
*
2021-03-06 17:48:20 -03:00
* @copyright 2021 Pablo Baldovi
* @author Pablo Baldovi <[email protected]>
*/
namespace LibreNMS\Alert\Transport;
use LibreNMS\Alert\Transport;
use LibreNMS\Exceptions\AlertTransportDeliveryException;
use LibreNMS\Util\Http;
2021-03-06 17:48:20 -03:00
class Googlechat extends Transport
{
protected string $name = 'Google Chat';
2021-10-06 07:29:47 -05:00
public function deliverAlert(array $alert_data): bool
2021-03-06 17:48:20 -03:00
{
$data = ['text' => $alert_data['msg']];
$res = Http::client()->post($this->config['googlechat-webhook'], $data);
2021-03-06 17:48:20 -03:00
if ($res->successful()) {
return true;
2021-03-06 17:48:20 -03:00
}
throw new AlertTransportDeliveryException($alert_data, $res->status(), $res->body(), $data['text'], $data);
2021-03-06 17:48:20 -03:00
}
public static function configTemplate(): array
2021-03-06 17:48:20 -03:00
{
return [
'config' => [
[
'title' => 'Webhook URL',
'name' => 'googlechat-webhook',
'descr' => 'Google Chat Room Webhook',
'type' => 'text',
],
],
'validation' => [
'googlechat-webhook' => 'required|string',
],
];
}
}