From 867c83e9acdc13b758ed6c97b1ce29898f74cddc Mon Sep 17 00:00:00 2001 From: f0o Date: Thu, 27 Aug 2015 14:28:46 +0100 Subject: [PATCH] Fix Alert-Test Object. --- alerts.php | 2 +- html/includes/forms/test-transport.inc.php | 37 +++++++++++----------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/alerts.php b/alerts.php index fafc909ac..8cbeae55d 100755 --- a/alerts.php +++ b/alerts.php @@ -326,7 +326,7 @@ function ExtTransports($obj) { foreach ($config['alert']['transports'] as $transport => $opts) { if (($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php')) { echo $transport.' => '; - eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php').' };'); + eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php').' return false; };'); $tmp = $tmp($obj,$opts); $prefix = array( 0=>"recovery", 1=>$obj['severity']." alert", 2=>"acknowledgment" ); $prefix[3] = &$prefix[0]; diff --git a/html/includes/forms/test-transport.inc.php b/html/includes/forms/test-transport.inc.php index 121961ee0..4919a7ebc 100644 --- a/html/includes/forms/test-transport.inc.php +++ b/html/includes/forms/test-transport.inc.php @@ -18,31 +18,32 @@ if (is_admin() === false) { $transport = mres($_POST['transport']); +require_once $config['install_dir'].'/includes/alerts.inc.php'; +$tmp = array(dbFetchRow('select device_id,hostname from devices order by device_id asc limit 1')); +$tmp['contacts'] = GetContacts($tmp); $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', + "hostname" => $tmp[0]['hostname'], + "device_id" => $tmp[0]['device_id'], + "title" => "Testing transport from ".$config['project_name'], + "elapsed" => "11s", + "id" => "000", + "faults" => false, + "uid" => "000", + "severity" => "critical", + "rule" => "%macros.device = 1", + "name" => "Test-Rule", + "timestamp" => date("Y-m-d H:i:s"), + "contacts" => $tmp['contacts'], + "state" => "0", + "msg" => "This is a test alert", ); -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")) { +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').' };'); + eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php').' return false; };'); $tmp = $tmp($obj,$opts); if ($tmp) { $status = 'ok';