2015-08-11 15:58:49 +00:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2019-07-18 11:05:43 -05:00
|
|
|
use LibreNMS\Alert\AlertUtil;
|
2018-07-31 15:53:03 -05:00
|
|
|
use LibreNMS\Config;
|
2018-04-07 15:55:28 -05:00
|
|
|
|
2019-08-05 14:16:05 -05:00
|
|
|
if (!Auth::user()->hasGlobalAdmin()) {
|
2016-08-18 20:28:22 -05:00
|
|
|
header('Content-type: text/plain');
|
2015-08-11 15:58:49 +00:00
|
|
|
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-11 15:58:49 +00:00
|
|
|
|
Refactored and update Location Geocoding (#9359)
- Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls)
- Parse coordinates from the location more consistently
- Add settings to webui
- ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~
- Google Maps, Bing, Mapquest, and OpenStreetMap supported initially.
- Default to OpenStreetMap, which doesn't require a key. They will liberally hand out bans if you exceed 1 query per second though.
- All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate)
- Update all (I think) sql queries to handle the new structure
- Remove final vestiges of override_sysLocation as a device attribute
- Update existing device groups and rules in DB
- Tested all APIs with good/bad location, no/bad/good key, and no connection.
- Cannot fix advanced queries that use location
This blocks #8868
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`
After you are done testing, you can remove the changes with `./scripts/github-remove`. If there are schema changes, you can ask on discord how to revert.
2018-11-28 16:49:18 -06:00
|
|
|
$tmp = array(dbFetchRow('select device_id,hostname,sysDescr,version,hardware,location_id from devices order by device_id asc limit 1'));
|
2019-07-18 11:05:43 -05:00
|
|
|
$tmp['contacts'] = AlertUtil::getContacts($tmp);
|
2015-08-11 15:58:49 +00:00
|
|
|
$obj = array(
|
2015-08-27 14:28:46 +01:00
|
|
|
"hostname" => $tmp[0]['hostname'],
|
|
|
|
"device_id" => $tmp[0]['device_id'],
|
2017-06-01 04:16:39 -07:00
|
|
|
"sysDescr" => $tmp[0]['sysDescr'],
|
|
|
|
"version" => $tmp[0]['version'],
|
|
|
|
"hardware" => $tmp[0]['hardware'],
|
|
|
|
"location" => $tmp[0]['location'],
|
2019-06-23 00:29:12 -05:00
|
|
|
"title" => "Testing transport from " . Config::get('project_name'),
|
2015-08-27 14:28:46 +01:00
|
|
|
"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",
|
2017-06-01 04:16:39 -07:00
|
|
|
"string" => "#1: test => string;",
|
2015-08-27 14:28:46 +01:00
|
|
|
"timestamp" => date("Y-m-d H:i:s"),
|
|
|
|
"contacts" => $tmp['contacts'],
|
2015-09-04 21:49:31 +01:00
|
|
|
"state" => "1",
|
2015-08-27 14:28:46 +01:00
|
|
|
"msg" => "This is a test alert",
|
2015-08-11 15:58:49 +00:00
|
|
|
);
|
|
|
|
|
2018-07-31 15:53:03 -05:00
|
|
|
$response = ['status' => 'error'];
|
2015-08-11 15:58:49 +00:00
|
|
|
|
2018-07-21 13:34:59 -06:00
|
|
|
if ($transport_id) {
|
|
|
|
$transport = dbFetchCell("SELECT `transport_type` FROM `alert_transports` WHERE `transport_id` = ?", [$transport_id]);
|
|
|
|
}
|
2017-12-10 21:20:28 +01:00
|
|
|
$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;
|
2015-08-11 15:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
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);
|