diff --git a/html/forms/test-transport.inc.php b/html/forms/test-transport.inc.php new file mode 100644 index 0000000000..121961ee07 --- /dev/null +++ b/html/forms/test-transport.inc.php @@ -0,0 +1,53 @@ + + * + * 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. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if (is_admin() === false) { + die('ERROR: You need to be admin'); +} + +$transport = mres($_POST['transport']); + +$obj = array( + 'contacts' => $config['alert']['default_mail'], + 'title' => 'Testing transport from ' . $config['project_name'], + 'msg' => 'This is a test alert', + 'severity' => 'critical', + 'state' => 'critical', + 'hostname' => 'testing', + 'name' => 'Testing rule', +); + +unset($obj); +$obj['contacts'] = 'test'; +$obj['title'] = 'test'; +$obj['msg'] = 'test'; +$obj['severity'] = 'test'; +$obj['state'] = 'test'; +$obj['hostname'] = 'test'; +$obj['name'] = 'test'; + +$status = 'error'; + +if (file_exists($config['install_dir']."/includes/alerts/transport.$transport.php")) { + $opts = $config['alert']['transports'][$transport]; + if ($opts) { + eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php').' };'); + $tmp = $tmp($obj,$opts); + if ($tmp) { + $status = 'ok'; + } + } +} + +echo _json_encode(array('status' => $status)); diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php index 9282284eea..74ed2be549 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -263,7 +263,7 @@ echo '

- Email transport + Email transport

@@ -389,7 +389,7 @@ foreach ($dyn_config['email_smtp_secure'] as $secure) {

- API transport + API transport

@@ -431,7 +431,7 @@ foreach ($api_urls as $api_url) {
@@ -456,7 +456,7 @@ else {
@@ -475,7 +475,7 @@ else {

- IRC transport + IRC transport

@@ -493,7 +493,7 @@ else {

- Slack transport + Slack transport

@@ -559,7 +559,7 @@ foreach ($slack_urls as $slack_url) {
@@ -655,7 +655,7 @@ foreach ($hipchat_urls as $hipchat_url) {
@@ -736,7 +736,7 @@ echo '

- Boxcar transport + Boxcar transport

@@ -814,6 +814,16 @@ echo '
$(".toolTip").tooltip(); + $("button#test-alert").click(function() { + var transport = $(this).data("transport"); + $.ajax({ + type: 'POST', + url: '/ajax_form.php', + data: { type: "test-transport", transport: transport }, + dataType: "json" + }); + }); + apiIndex = 0; // Add API config