Merge pull request #1772 from f0o/alert-test-ui

Fix Alert-Test Object.
This commit is contained in:
Neil Lathwood 2015-08-27 17:51:57 +01:00
commit 24ace8192b
2 changed files with 20 additions and 19 deletions

View File

@ -326,7 +326,7 @@ function ExtTransports($obj) {
foreach ($config['alert']['transports'] as $transport => $opts) { foreach ($config['alert']['transports'] as $transport => $opts) {
if (($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php')) { if (($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php')) {
echo $transport.' => '; 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); $tmp = $tmp($obj,$opts);
$prefix = array( 0=>"recovery", 1=>$obj['severity']." alert", 2=>"acknowledgment" ); $prefix = array( 0=>"recovery", 1=>$obj['severity']." alert", 2=>"acknowledgment" );
$prefix[3] = &$prefix[0]; $prefix[3] = &$prefix[0];

View File

@ -18,31 +18,32 @@ if (is_admin() === false) {
$transport = mres($_POST['transport']); $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( $obj = array(
'contacts' => $config['alert']['default_mail'], "hostname" => $tmp[0]['hostname'],
'title' => 'Testing transport from ' . $config['project_name'], "device_id" => $tmp[0]['device_id'],
'msg' => 'This is a test alert', "title" => "Testing transport from ".$config['project_name'],
'severity' => 'critical', "elapsed" => "11s",
'state' => 'critical', "id" => "000",
'hostname' => 'testing', "faults" => false,
'name' => 'Testing rule', "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'; $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]; $opts = $config['alert']['transports'][$transport];
if ($opts) { 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); $tmp = $tmp($obj,$opts);
if ($tmp) { if ($tmp) {
$status = 'ok'; $status = 'ok';