Files

69 lines
2.3 KiB
PHP
Raw Permalink Normal View History

<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* 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.
*/
2018-09-11 07:51:35 -05:00
use LibreNMS\Authentication\LegacyAuth;
2018-07-31 15:53:03 -05:00
use LibreNMS\Config;
2018-09-11 07:51:35 -05:00
if (!LegacyAuth::user()->hasGlobalAdmin()) {
2016-08-18 20:28:22 -05:00
header('Content-type: text/plain');
die('ERROR: You need to be admin');
}
2018-07-21 13:34:59 -06:00
$transport = $vars['transport'] ?: null;
$transport_id = $vars['transport_id'] ?: null;
2015-08-27 14:28:46 +01:00
require_once $config['install_dir'].'/includes/alerts.inc.php';
$tmp = array(dbFetchRow('select device_id,hostname,sysDescr,version,hardware,location_id from devices order by device_id asc limit 1'));
2015-08-27 14:28:46 +01:00
$tmp['contacts'] = GetContacts($tmp);
$obj = array(
2015-08-27 14:28:46 +01:00
"hostname" => $tmp[0]['hostname'],
"device_id" => $tmp[0]['device_id'],
"sysDescr" => $tmp[0]['sysDescr'],
"version" => $tmp[0]['version'],
"hardware" => $tmp[0]['hardware'],
"location" => $tmp[0]['location'],
2015-08-27 14:28:46 +01:00
"title" => "Testing transport from ".$config['project_name'],
"elapsed" => "11s",
"id" => "000",
"faults" => false,
"uid" => "000",
"severity" => "critical",
2018-07-21 13:34:59 -06:00
"rule" => "macros.device = 1",
2015-08-27 14:28:46 +01:00
"name" => "Test-Rule",
"string" => "#1: test => string;",
2015-08-27 14:28:46 +01:00
"timestamp" => date("Y-m-d H:i:s"),
"contacts" => $tmp['contacts'],
"state" => "1",
2015-08-27 14:28:46 +01:00
"msg" => "This is a test alert",
);
2018-07-31 15:53:03 -05:00
$response = ['status' => 'error'];
2018-07-21 13:34:59 -06:00
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)) {
2018-07-31 15:53:03 -05:00
$opts = Config::get("alert.transports.$transport");
2018-07-25 09:00:24 +01:00
$instance = new $class($transport_id);
2018-07-31 15:53:03 -05:00
$result = $instance->deliverAlert($obj, $opts);
if ($result === true) {
$response['status'] = 'ok';
} else {
$response['message'] = $result;
}
}
2016-04-28 14:42:06 -07:00
header('Content-type: application/json');
2018-07-31 15:53:03 -05:00
echo json_encode($response);