mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Oxidized + Device remove Was just working on oxidized, but then to properly update nodes after delete, updated delete_device() * revert dumb style changes * baseline update and no DI there... * Fix OS first load and device deletion missing tables
70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Oxidized.php
|
|
*
|
|
* -Description-
|
|
*
|
|
* 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.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
* @link https://www.librenms.org
|
|
*
|
|
* @copyright 2022 Tony Murray
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
*/
|
|
|
|
namespace App\ApiClients;
|
|
|
|
use LibreNMS\Config;
|
|
|
|
class Oxidized extends BaseApi
|
|
{
|
|
/**
|
|
* @var bool if Oxidized is enabled
|
|
*/
|
|
private $enabled;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->base_uri = Config::get('oxidized.url');
|
|
$this->enabled = Config::get('oxidized.enabled') === true && $this->base_uri;
|
|
}
|
|
|
|
/**
|
|
* Ask oxidized to refresh the node list for the source (likely the LibreNMS API).
|
|
*/
|
|
public function reloadNodes(): void
|
|
{
|
|
if ($this->enabled && Config::get('oxidized.reload_nodes') === true) {
|
|
$this->getClient()->get('/reload.json');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Queues a hostname to be refreshed by Oxidized
|
|
*/
|
|
public function updateNode(string $hostname, string $msg, string $username = 'not_provided'): bool
|
|
{
|
|
if ($this->enabled) {
|
|
// Work around https://github.com/rack/rack/issues/337
|
|
$msg = str_replace('%', '', $msg);
|
|
|
|
return $this->getClient()
|
|
->put("/node/next/$hostname", ['user' => $username, 'msg' => $msg])
|
|
->successful();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|