diff --git a/app/Utils/InfluxDB/InfluxDB.php b/app/Utils/InfluxDB/InfluxDB.php index 5664bed2..defe5f63 100644 --- a/app/Utils/InfluxDB/InfluxDB.php +++ b/app/Utils/InfluxDB/InfluxDB.php @@ -37,16 +37,25 @@ class InfluxDB $host = SettingsHelper::get('influx_db_host')->value; $port = SettingsHelper::get('influx_db_port')->value; - $token = ''; + $username = SettingsHelper::get('influx_db_username')->value; + $password = SettingsHelper::get('influx_db_password')->value; $database = SettingsHelper::get('influx_db_database')->value; $version = (int) SettingsHelper::get('influx_db_version')->value; $wrapper = $version === 1 ? new InfluxDBVersion1Wrapper( - new Version1(str_replace(['http://', 'https://'], '', $host), $port) + new Version1( + str_replace(['http://', 'https://'], '', $host), + $port, + $username, + $password + ) ) : new InfluxDBVersion2Wrapper( - new Version2([]) + new Version2([ + 'url' => $host . ':' . $port, + 'token' => '', + ]) ); return (new self($wrapper))->setDatabase($database) diff --git a/database/migrations/2021_04_10_182503_add_influx_db_settings.php b/database/migrations/2021_04_10_182503_add_influx_db_settings.php index 7ff7e8a5..33993cf3 100644 --- a/database/migrations/2021_04_10_182503_add_influx_db_settings.php +++ b/database/migrations/2021_04_10_182503_add_influx_db_settings.php @@ -47,6 +47,22 @@ class AddInfluxDbSettings extends Migration ]); } + if (!SettingsHelper::get('influx_db_username')) { + Setting::create([ + 'name' => 'influx_db_username', + 'value' => '', + 'description' => 'InfluxDB username' + ]); + } + + if (!SettingsHelper::get('influx_db_password')) { + Setting::create([ + 'name' => 'influx_db_password', + 'value' => '', + 'description' => 'InfluxDB password' + ]); + } + if (!SettingsHelper::get('influx_db_version')) { Setting::create([ 'name' => 'influx_db_version', @@ -68,6 +84,8 @@ class AddInfluxDbSettings extends Migration 'influx_db_host', 'influx_db_port', 'influx_db_database', + 'influx_db_username', + 'influx_db_password', 'influx_db_version', ])->delete(); }