mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Fix oxidized web requests not closing connections or responding fast enough * Update showconfig.inc.php * Add method to get the text content of an oxidized page * Use Oxidized getContent method instead of file_get_content * Too much brackets with copy paste * Fix carriage return errors because of copy paste * Fix copy paste error again * Fix indent * PHPStan is waiting for a return even outside of the if loop * Single quotes * Variabilize timeout in baseapi * Set Oxidized Api class timeout var to 90 because oxidized is slow and to be sure not to break half the installs here * fix typo * Variabilize timeout * Variabilize timeout * Variabilize timeout * Variabilize timeout * Variabilize timeout * Spacing * Remove timeout type because of this error Unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in app/ApiClients/BaseApi.php on line 34 * Lint needs type finally * Use contruct instead of setting variable * Type hinting instead for php7.3 * Type hinting fix * Set property value instead of calling parent constructor * Typo * Remove unneededconstructors * Remove unneeded constructors * Remove unneeded constructors * Remove unneeded constructors * Remove unneeded constructors * Remove unneeded constructors * Typing not casting * Typing not casting * Cannot type variables outside of a class Co-authored-by: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com>
81 lines
2.2 KiB
PHP
81 lines
2.2 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->timeout = 90;
|
|
$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;
|
|
}
|
|
|
|
/* Get content of the page */
|
|
public function getContent(string $uri): string
|
|
{
|
|
if ($this->enabled) {
|
|
return $this->getClient()->get($uri);
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
}
|