mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Don't use proxy for localhost (Oxidized and Prometheus) (#13450)
fixes #13382
This commit is contained in:
@@ -30,6 +30,7 @@ use App\Polling\Measure\Measurement;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\Proxy;
|
||||
use Log;
|
||||
|
||||
class Prometheus extends BaseDatastore
|
||||
@@ -56,7 +57,7 @@ class Prometheus extends BaseDatastore
|
||||
$this->default_opts = [
|
||||
'headers' => ['Content-Type' => 'text/plain'],
|
||||
];
|
||||
if ($proxy = get_proxy()) {
|
||||
if ($proxy = Proxy::get($url)) {
|
||||
$this->default_opts['proxy'] = $proxy;
|
||||
}
|
||||
|
||||
|
@@ -29,14 +29,25 @@ use LibreNMS\Config;
|
||||
|
||||
class Proxy
|
||||
{
|
||||
/**
|
||||
* Check if if the proxy should be used.
|
||||
* (it should not be used for connections to localhost)
|
||||
*/
|
||||
public static function shouldBeUsed(string $target_url): bool
|
||||
{
|
||||
return (bool) preg_match('#//:(localhost|127\.|::1)#', $target_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the proxy url
|
||||
*
|
||||
* @return array|bool|false|string
|
||||
*/
|
||||
public static function get()
|
||||
public static function get(?string $target_url = null)
|
||||
{
|
||||
if (getenv('http_proxy')) {
|
||||
if ($target_url && ! self::shouldBeUsed($target_url)) {
|
||||
return false;
|
||||
} elseif (getenv('http_proxy')) {
|
||||
return getenv('http_proxy');
|
||||
} elseif (getenv('https_proxy')) {
|
||||
return getenv('https_proxy');
|
||||
|
@@ -21,6 +21,7 @@ use LibreNMS\Modules\Core;
|
||||
use LibreNMS\Util\Debug;
|
||||
use LibreNMS\Util\IPv4;
|
||||
use LibreNMS\Util\IPv6;
|
||||
use LibreNMS\Util\Proxy;
|
||||
|
||||
function array_sort_by_column($array, $on, $order = SORT_ASC)
|
||||
{
|
||||
@@ -1687,7 +1688,7 @@ function oxidized_node_update($hostname, $msg, $username = 'not_provided')
|
||||
$postdata = ['user' => $username, 'msg' => $msg];
|
||||
$oxidized_url = Config::get('oxidized.url');
|
||||
if (! empty($oxidized_url)) {
|
||||
Requests::put("$oxidized_url/node/next/$hostname", [], json_encode($postdata), ['proxy' => get_proxy()]);
|
||||
Requests::put("$oxidized_url/node/next/$hostname", [], json_encode($postdata), ['proxy' => Proxy::get($oxidized_url)]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user