mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 02:18:39 +00:00
Revert "Mattermost Alert Transport (#9711)"
This reverts commit 09d500812e
.
This commit is contained in:
parent
b7ae282848
commit
75927c8389
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
/* Copyright (C) 2018 George Pantazis <gpant@eservices-greece.com>
|
||||
* 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/>. */
|
||||
|
||||
/**
|
||||
* Mattermost API Transport
|
||||
* @author George Pantazis <gpant@eservices-greece.com>
|
||||
* @copyright 2019 George Pantazis, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Alert\Transport;
|
||||
|
||||
class Mattermost extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
|
||||
$mattermost_opts = [
|
||||
'url' => $this->config['mattermost-url'],
|
||||
'username' => $this->config['mattermost-username'],
|
||||
'icon' => $this->config['mattermost-icon'],
|
||||
'channel' => $this->config['mattermost-channel'],
|
||||
];
|
||||
|
||||
return $this->contactMattermost($obj, $mattermost_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $tmp_api) {
|
||||
$this->contactMattermost($obj, $tmp_api);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function contactMattermost($obj, $api)
|
||||
{
|
||||
$host = $api['url'];
|
||||
$curl = curl_init();
|
||||
$mattermost_msg = strip_tags($obj['msg']);
|
||||
$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000');
|
||||
$data = [
|
||||
'attachments' => [
|
||||
0 => [
|
||||
'fallback' => $mattermost_msg,
|
||||
'color' => $color,
|
||||
'title' => $obj['title'],
|
||||
'text' => $obj['msg'],
|
||||
'mrkdwn_in' => ['text', 'fallback'],
|
||||
'author_name' => $obj['hostname'],
|
||||
],
|
||||
],
|
||||
'channel' => $api['channel'],
|
||||
'username' => $api['username'],
|
||||
'icon_url' => $api['icon'],
|
||||
];
|
||||
|
||||
$device = device_by_id_cache($obj['device_id']);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
|
||||
$httpheaders = array('Accept: application/json', 'Content-Type: application/json');
|
||||
$alert_payload = json_encode($data);
|
||||
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $httpheaders);
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_payload);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
d_echo("Mattermost Connection Error: " . $ret);
|
||||
return false;
|
||||
} else {
|
||||
d_echo("Mattermost message sent for " . $device);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function configTemplate()
|
||||
{
|
||||
return [
|
||||
'config' => [
|
||||
[
|
||||
'title' => 'Webhook URL',
|
||||
'name' => 'mattermost-url',
|
||||
'descr' => 'Mattermost Webhook URL',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'title' => 'Channel',
|
||||
'name' => 'mattermost-channel',
|
||||
'descr' => 'Mattermost Channel',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'title' => 'Username',
|
||||
'name' => 'mattermost-username',
|
||||
'descr' => 'Mattermost Username',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'title' => 'Icon',
|
||||
'name' => 'mattermost-icon',
|
||||
'descr' => 'Icon URL',
|
||||
'type' => 'text',
|
||||
],
|
||||
],
|
||||
'validation' => [
|
||||
'mattermost-url' => 'required|url',
|
||||
'mattermost-icon' => 'url',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
34
html/.htaccess
Normal file
34
html/.htaccess
Normal file
@ -0,0 +1,34 @@
|
||||
# DO NOT CHANGE THIS FILE
|
||||
# If you need to change this file, you are doing something wrong.
|
||||
|
||||
Options +FollowSymlinks +Multiviews
|
||||
|
||||
AddType image/svg+xml .svg
|
||||
<IfModule mod_filter.c>
|
||||
<IfModule mod_deflate.c>
|
||||
AddOutputFilterByType DEFLATE text/css
|
||||
AddOutputFilterByType DEFLATE application/javascript
|
||||
AddOutputFilterByType DEFLATE text/javascript
|
||||
AddOutputFilterByType DEFLATE application/x-javascript
|
||||
AddOutputFilterByType DEFLATE image/svg+xml
|
||||
AddOutputFilterByType DEFLATE text/plain
|
||||
AddOutputFilterByType DEFLATE text/xsd
|
||||
AddOutputFilterByType DEFLATE text/xsl
|
||||
AddOutputFilterByType DEFLATE text/xml
|
||||
AddOutputFilterByType DEFLATE image/x-icon
|
||||
</IfModule>
|
||||
</IfModule>
|
||||
|
||||
RewriteEngine on
|
||||
RewriteBase /
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_URI} !\.(js|ico|txt|gif|jpg|png|css|php)
|
||||
RewriteRule ^api/v0(.*)$ api_v0.php/$1 [L]
|
||||
RewriteCond %{REQUEST_URI} !=/server-status
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_URI} !\.(js|ico|txt|gif|jpg|png|css|php)
|
||||
RewriteRule ^(.*)$ index.php
|
||||
|
||||
AcceptPathInfo On
|
1
html/includes/.htaccess
Normal file
1
html/includes/.htaccess
Normal file
@ -0,0 +1 @@
|
||||
deny from all
|
101
html/includes/collectd/config.php
Normal file
101
html/includes/collectd/config.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* Configuration file for Collectd graph browser
|
||||
*/
|
||||
|
||||
if (isset($config['rrdgraph_def_text'])) {
|
||||
$config['rrdgraph_def_text'] = str_replace(' ', ' ', $config['rrdgraph_def_text']);
|
||||
$config['rrd_opts_array'] = explode(' ', trim($config['rrdgraph_def_text']));
|
||||
}
|
||||
|
||||
// Array of paths when collectd's rrdtool plugin writes RRDs
|
||||
$config['datadirs'] = array($config['collectd_dir']);
|
||||
// Width of graph to be generated by rrdgraph
|
||||
if (isset($_GET['width'])) {
|
||||
$config['rrd_width'] = $_GET['width'];
|
||||
} else {
|
||||
$config['rrd_width'] = 270;
|
||||
}
|
||||
|
||||
// Height of graph to be generated by rrdgraph
|
||||
if (isset($_GET['height'])) {
|
||||
$config['rrd_height'] = $_GET['height'];
|
||||
} else {
|
||||
$config['rrd_height'] = 120;
|
||||
}
|
||||
|
||||
// List of supported timespans (used for period drop-down list)
|
||||
$config['timespan'] = array(
|
||||
array(
|
||||
'name' => 'hour',
|
||||
'label' => 'past hour',
|
||||
'seconds' => 3600,
|
||||
),
|
||||
array(
|
||||
'name' => 'day',
|
||||
'label' => 'past day',
|
||||
'seconds' => 86400,
|
||||
),
|
||||
array(
|
||||
'name' => 'week',
|
||||
'label' => 'past week',
|
||||
'seconds' => 604800,
|
||||
),
|
||||
array(
|
||||
'name' => 'month',
|
||||
'label' => 'past month',
|
||||
'seconds' => 2678400,
|
||||
),
|
||||
array(
|
||||
'name' => 'year',
|
||||
'label' => 'past year',
|
||||
'seconds' => 31622400,
|
||||
),
|
||||
);
|
||||
// Interval at which values are collectd (currently ignored)
|
||||
$config['rrd_interval'] = 10;
|
||||
// Average rows/rra (currently ignored)
|
||||
$config['rrd_rows'] = 2400;
|
||||
// Additional options to pass to rrdgraph
|
||||
// $config['rrd_opts'] = (isset($config['rrdgraph_defaults']) ? $config['rrdgraph_defaults'] : '');
|
||||
// $config['rrd_opts'] = array('-E', "-c", "SHADEA#a5a5a5", "-c", "SHADEB#a5a5a5", "-c", "FONT#000000", "-c", "CANVAS#FFFFFF", "-c", "GRID#aaaaaa",
|
||||
// "-c", "MGRID#FFAAAA", "-c", "FRAME#3e3e3e", "-c", "ARROW#5e5e5e", "-R", "normal");
|
||||
// Predefined set of colors for use by collectd_draw_rrd()
|
||||
$config['rrd_colors'] = array(
|
||||
'h_1' => 'F7B7B7',
|
||||
'f_1' => 'FF0000', // Red
|
||||
'h_2' => 'B7EFB7',
|
||||
'f_2' => '00E000', // Green
|
||||
'h_3' => 'B7B7F7',
|
||||
'f_3' => '0000FF', // Blue
|
||||
'h_4' => 'F3DFB7',
|
||||
'f_4' => 'F0A000', // Yellow
|
||||
'h_5' => 'B7DFF7',
|
||||
'f_5' => '00A0FF', // Cyan
|
||||
'h_6' => 'DFB7F7',
|
||||
'f_6' => 'A000FF', // Magenta
|
||||
'h_7' => 'FFC782',
|
||||
'f_7' => 'FF8C00', // Orange
|
||||
'h_8' => 'DCFF96',
|
||||
'f_8' => 'AAFF00', // Lime
|
||||
'h_9' => '83FFCD',
|
||||
'f_9' => '00FF99',
|
||||
'h_10' => '81D9FF',
|
||||
'f_10' => '00B2FF',
|
||||
'h_11' => 'FF89F5',
|
||||
'f_11' => 'FF00EA',
|
||||
'h_12' => 'FF89AE',
|
||||
'f_12' => 'FF0051',
|
||||
'h_13' => 'BBBBBB',
|
||||
'f_13' => '555555',
|
||||
);
|
||||
/*
|
||||
* Path to TTF font file to use in error images
|
||||
* (fallback when file does not exist is GD fixed font)
|
||||
*/
|
||||
$config['error_font'] = '/usr/share/fonts/corefonts/arial.ttf';
|
||||
|
||||
/*
|
||||
* Constant defining full path to rrdtool
|
||||
*/
|
||||
define('RRDTOOL', $config['rrdtool']);
|
1
html/pages/.htaccess
Normal file
1
html/pages/.htaccess
Normal file
@ -0,0 +1 @@
|
||||
deny from all
|
11
resources/views/alerts/templates/default.blade.php
Normal file
11
resources/views/alerts/templates/default.blade.php
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>LibreNMS Alert</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@yield('content')
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user