Alert transport fixes (#8967)
DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
parent
9bc0c542a5
commit
deb405fac9
|
@ -35,7 +35,7 @@ class Api extends Transport
|
|||
}
|
||||
$url = $this->config['api-url'];
|
||||
$method = $this->config['api-method'];
|
||||
$this->contactAPI($obj, $url, $method);
|
||||
return $this->contactAPI($obj, $url, $method);
|
||||
}
|
||||
|
||||
private function deliverAlertOld($obj, $opts)
|
||||
|
@ -73,6 +73,8 @@ class Api extends Transport
|
|||
var_dump("Return: ".$ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function configTemplate()
|
||||
|
|
|
@ -118,6 +118,8 @@ class Boxcar extends Transport
|
|||
var_dump("Boxcar returned error"); //FIXME: proper debugging
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function configTemplate()
|
||||
|
|
|
@ -34,7 +34,6 @@ class Ciscospark extends Transport
|
|||
'roomId' => $room_id,
|
||||
'text' => $text
|
||||
);
|
||||
$token = $token;
|
||||
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
|
|
|
@ -118,6 +118,8 @@ class Hipchat extends Transport
|
|||
var_dump("Return: " . $ret);
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function configTemplate()
|
||||
|
|
|
@ -46,6 +46,8 @@ class Irc extends Transport
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function configTemplate()
|
||||
|
|
|
@ -30,10 +30,10 @@ class Mail extends Transport
|
|||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
return $this->contactMail($obj, $opts);
|
||||
return $this->contactMail($obj);
|
||||
}
|
||||
|
||||
public function contactMail($obj, $opts)
|
||||
public function contactMail($obj)
|
||||
{
|
||||
if (empty($this->config['email'])) {
|
||||
$email = $obj['contacts'];
|
||||
|
|
|
@ -37,7 +37,7 @@ class Playsms extends Transport
|
|||
$playsms_opts['token'] = $this->config['playsms-token'];
|
||||
$playsms_opts['from'] = $this->config['playsms-from'];
|
||||
$playsms_opts['to'] = preg_split('/([,\r\n]+)/', $this->config['playsms-mobiles']);
|
||||
return $this->contactDiscord($obj, $playsms_opts);
|
||||
return $this->contactPlaysms($obj, $playsms_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
use LibreNMS\Util\FileLock;
|
||||
|
||||
$init_modules = ['alerts', 'alerts-cli'];
|
||||
$init_modules = ['alerts', 'laravel'];
|
||||
require __DIR__ . '/includes/init.php';
|
||||
|
||||
$options = getopt('d::');
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
use LibreNMS\Authentication\Auth;
|
||||
|
||||
$init_modules = array('web', 'auth', 'alerts', 'eloquent');
|
||||
$init_modules = array('web', 'auth', 'alerts', 'laravel');
|
||||
require realpath(__DIR__ . '/..') . '/includes/init.php';
|
||||
|
||||
set_debug(isset($_REQUEST['debug']) ? $_REQUEST['debug'] : false);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
|
||||
use LibreNMS\Authentication\Auth;
|
||||
use LibreNMS\Config;
|
||||
|
||||
if (!Auth::user()->hasGlobalAdmin()) {
|
||||
header('Content-type: text/plain');
|
||||
|
@ -47,19 +48,21 @@ $obj = array(
|
|||
"msg" => "This is a test alert",
|
||||
);
|
||||
|
||||
$status = 'error';
|
||||
$response = ['status' => 'error'];
|
||||
|
||||
if ($transport_id) {
|
||||
$transport = dbFetchCell("SELECT `transport_type` FROM `alert_transports` WHERE `transport_id` = ?", [$transport_id]);
|
||||
}
|
||||
$class = 'LibreNMS\\Alert\\Transport\\' . ucfirst($transport);
|
||||
if (class_exists($class)) {
|
||||
$opts = $config['alert']['transports'][$transport];
|
||||
$opts = Config::get("alert.transports.$transport");
|
||||
$instance = new $class($transport_id);
|
||||
$tmp = $instance->deliverAlert($obj, $opts);
|
||||
if ($tmp) {
|
||||
$status = 'ok';
|
||||
$result = $instance->deliverAlert($obj, $opts);
|
||||
if ($result === true) {
|
||||
$response['status'] = 'ok';
|
||||
} else {
|
||||
$response['message'] = $result;
|
||||
}
|
||||
}
|
||||
header('Content-type: application/json');
|
||||
echo _json_encode(array('status' => $status));
|
||||
echo json_encode($response);
|
||||
|
|
|
@ -47,9 +47,9 @@ foreach (dbFetchRows($query) as $transport) {
|
|||
} else {
|
||||
echo "<td>No</td>";
|
||||
}
|
||||
|
||||
|
||||
echo "<td class='col-sm-4'>";
|
||||
|
||||
|
||||
// Iterate through transport config template to display config details
|
||||
$class = 'LibreNMS\\Alert\\Transport\\'.ucfirst($transport['type']);
|
||||
if (!method_exists($class, 'configTemplate')) {
|
||||
|
@ -58,10 +58,10 @@ foreach (dbFetchRows($query) as $transport) {
|
|||
}
|
||||
$tmp = call_user_func($class.'::configTemplate');
|
||||
$transport_config = json_decode($transport['config'], true);
|
||||
|
||||
|
||||
foreach ($tmp['config'] as $item) {
|
||||
$val = $transport_config[$item['name']];
|
||||
|
||||
|
||||
// Match value to key name for select inputs
|
||||
if ($item['type'] == 'select') {
|
||||
$val = array_search($val, $item['options']);
|
||||
|
@ -144,10 +144,10 @@ foreach (dbFetchRows($query) as $group) {
|
|||
data: { type: "test-transport", transport_id: transport_id },
|
||||
dataType: "json",
|
||||
success: function(data){
|
||||
if (data.status == 'ok') {
|
||||
if (data.status === 'ok') {
|
||||
toastr.success('Test to ' + transport + ' ok');
|
||||
} else {
|
||||
toastr.error('Test to ' + transport + ' failed');
|
||||
toastr.error('Test to ' + transport + ' failed<br />' + data.message);
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
|
@ -160,4 +160,4 @@ foreach (dbFetchRows($query) as $group) {
|
|||
trigger: 'hover',
|
||||
placement: 'top'
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
@ -1726,10 +1726,10 @@ echo '
|
|||
data: { type: "test-transport", transport: transport },
|
||||
dataType: "json",
|
||||
success: function(data){
|
||||
if (data.status == 'ok') {
|
||||
if (data.status === 'ok') {
|
||||
toastr.success('Test to ' + transport + ' ok');
|
||||
} else {
|
||||
toastr.error('Test to ' + transport + ' failed');
|
||||
toastr.error('Test to ' + transport + ' failed<br />' + data.message);
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
|
|
|
@ -1100,6 +1100,8 @@ function send_mail($emails, $subject, $message, $html = false)
|
|||
}
|
||||
return $mail->send() ? true : $mail->ErrorInfo;
|
||||
}
|
||||
|
||||
return "No contacts found";
|
||||
}
|
||||
|
||||
function formatCiscoHardware(&$device, $short = false)
|
||||
|
|
|
@ -90,13 +90,6 @@ if (module_selected('polling', $init_modules)) {
|
|||
if (module_selected('alerts', $init_modules)) {
|
||||
require_once $install_dir . '/includes/device-groups.inc.php';
|
||||
require_once $install_dir . '/includes/alerts.inc.php';
|
||||
if (module_selected('alerts-cli', $init_modules)) {
|
||||
// Boot Laravel - we only use it in alerting at present
|
||||
require $install_dir . '/bootstrap/autoload.php';
|
||||
$app = require_once $install_dir . '/bootstrap/app.php';
|
||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
||||
$kernel->bootstrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Display config.php errors instead of http 500
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
$init_modules = ['alerts', 'alerts-cli'];
|
||||
$init_modules = ['alerts', 'laravel'];
|
||||
require __DIR__ . '/../includes/init.php';
|
||||
|
||||
$options = getopt('t:h:r:p:s:d::');
|
||||
|
||||
if ($options['r'] && $options['h']) {
|
||||
if (isset($options['r']) && isset($options['h'])) {
|
||||
set_debug(isset($options['d']));
|
||||
|
||||
$rule_id = (int)$options['r'];
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
$init_modules = ['alerts', 'alerts-cli'];
|
||||
$init_modules = ['alerts', 'laravel'];
|
||||
require __DIR__ . '/../includes/init.php';
|
||||
|
||||
use LibreNMS\Alert\Template;
|
||||
|
|
Loading…
Reference in New Issue