From 75927c83893afffc8edb339b3f85be874d6fb0cb Mon Sep 17 00:00:00 2001
From: TheGreatDoc <32565115+TheGreatDoc@users.noreply.github.com>
Date: Sat, 26 Jan 2019 07:59:04 +0100
Subject: [PATCH 2/2] Revert "Mattermost Alert Transport (#9711)"
This reverts commit 09d500812ea0bfa1e7a935af09b7d9e060a0e09a.
---
LibreNMS/Alert/Transport/Mattermost.php | 135 ------------------
html/.htaccess | 34 +++++
html/includes/.htaccess | 1 +
html/includes/collectd/config.php | 101 +++++++++++++
html/pages/.htaccess | 1 +
.../views/alerts/templates/default.blade.php | 11 ++
6 files changed, 148 insertions(+), 135 deletions(-)
delete mode 100644 LibreNMS/Alert/Transport/Mattermost.php
create mode 100644 html/.htaccess
create mode 100644 html/includes/.htaccess
create mode 100644 html/includes/collectd/config.php
create mode 100644 html/pages/.htaccess
create mode 100644 resources/views/alerts/templates/default.blade.php
diff --git a/LibreNMS/Alert/Transport/Mattermost.php b/LibreNMS/Alert/Transport/Mattermost.php
deleted file mode 100644
index 6413ed56d2..0000000000
--- a/LibreNMS/Alert/Transport/Mattermost.php
+++ /dev/null
@@ -1,135 +0,0 @@
-
- * 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 . */
-
-/**
- * Mattermost API Transport
- * @author George Pantazis
- * @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',
- ],
- ];
- }
-}
diff --git a/html/.htaccess b/html/.htaccess
new file mode 100644
index 0000000000..608a095d82
--- /dev/null
+++ b/html/.htaccess
@@ -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
+
+
+ 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
+
+
+
+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
diff --git a/html/includes/.htaccess b/html/includes/.htaccess
new file mode 100644
index 0000000000..8d2f25636d
--- /dev/null
+++ b/html/includes/.htaccess
@@ -0,0 +1 @@
+deny from all
diff --git a/html/includes/collectd/config.php b/html/includes/collectd/config.php
new file mode 100644
index 0000000000..c81a68c235
--- /dev/null
+++ b/html/includes/collectd/config.php
@@ -0,0 +1,101 @@
+ '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']);
diff --git a/html/pages/.htaccess b/html/pages/.htaccess
new file mode 100644
index 0000000000..8d2f25636d
--- /dev/null
+++ b/html/pages/.htaccess
@@ -0,0 +1 @@
+deny from all
diff --git a/resources/views/alerts/templates/default.blade.php b/resources/views/alerts/templates/default.blade.php
new file mode 100644
index 0000000000..1e0c265596
--- /dev/null
+++ b/resources/views/alerts/templates/default.blade.php
@@ -0,0 +1,11 @@
+
+
+
+ LibreNMS Alert
+
+
+
+ @yield('content')
+
+
+
\ No newline at end of file