mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
api: Added support for Oxidized asking for a single host (#7705)
This commit is contained in:
@ -768,7 +768,7 @@ Output:
|
||||
|
||||
List devices for use with Oxidized. If you have group support enabled then a group will also be returned based on your config.
|
||||
|
||||
Route: `/api/v0/oxidized`
|
||||
Route: `/api/v0/oxidized(/:hostname)`
|
||||
|
||||
Input (JSON):
|
||||
|
||||
|
@ -42,7 +42,7 @@ $app->group(
|
||||
$app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');
|
||||
$app->get('/ospf', 'authToken', 'list_ospf')->name('list_ospf');
|
||||
// api/v0/bgp
|
||||
$app->get('/oxidized', 'authToken', 'list_oxidized')->name('list_oxidized');
|
||||
$app->get('/oxidized(/:hostname)', 'authToken', 'list_oxidized')->name('list_oxidized');
|
||||
$app->group(
|
||||
'/devices',
|
||||
function () use ($app) {
|
||||
|
@ -1239,12 +1239,21 @@ function list_oxidized()
|
||||
{
|
||||
global $config;
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
|
||||
$hostname = $router['hostname'];
|
||||
$devices = array();
|
||||
$device_types = "'".implode("','", $config['oxidized']['ignore_types'])."'";
|
||||
$device_os = "'".implode("','", $config['oxidized']['ignore_os'])."'";
|
||||
foreach (dbFetchRows("SELECT hostname,sysname,os,location FROM `devices` LEFT JOIN devices_attribs AS `DA` ON devices.device_id = DA.device_id AND `DA`.attrib_type='override_Oxidized_disable' WHERE `disabled`='0' AND `ignore` = 0 AND (DA.attrib_value = 'false' OR DA.attrib_value IS NULL) AND (`type` NOT IN ($device_types) AND `os` NOT IN ($device_os))") as $device) {
|
||||
|
||||
$sql = '';
|
||||
$params = array();
|
||||
if ($hostname) {
|
||||
$sql = " AND hostname = ?";
|
||||
$params = array($hostname);
|
||||
}
|
||||
|
||||
foreach (dbFetchRows("SELECT hostname,sysname,os,location FROM `devices` LEFT JOIN devices_attribs AS `DA` ON devices.device_id = DA.device_id AND `DA`.attrib_type='override_Oxidized_disable' WHERE `disabled`='0' AND `ignore` = 0 AND (DA.attrib_value = 'false' OR DA.attrib_value IS NULL) AND (`type` NOT IN ($device_types) AND `os` NOT IN ($device_os)) $sql", $params) as $device) {
|
||||
if ($config['oxidized']['group_support'] == "true") {
|
||||
foreach ($config['oxidized']['group']['hostname'] as $host_group) {
|
||||
if (preg_match($host_group['regex'].'i', $device['hostname'])) {
|
||||
|
Reference in New Issue
Block a user