mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	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:
		
				
					committed by
					
						
						Neil Lathwood
					
				
			
			
				
	
			
			
			
						parent
						
							9bc0c542a5
						
					
				
				
					commit
					deb405fac9
				
			@@ -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(){
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user