mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Validate: use "database version" instead of "mysql version" (#14158)
* Validate: use "database version" instead of "mysql version" * wip * wip
This commit is contained in:
@@ -43,7 +43,6 @@ use LibreNMS\Util\Debug;
|
|||||||
use LibreNMS\Util\Dns;
|
use LibreNMS\Util\Dns;
|
||||||
use LibreNMS\Util\Git;
|
use LibreNMS\Util\Git;
|
||||||
use LibreNMS\Util\StringHelpers;
|
use LibreNMS\Util\StringHelpers;
|
||||||
use LibreNMS\Util\Version;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@@ -371,7 +370,7 @@ Commit SHA: %s
|
|||||||
Commit Date: %s
|
Commit Date: %s
|
||||||
DB Schema: %s
|
DB Schema: %s
|
||||||
PHP: %s
|
PHP: %s
|
||||||
MySQL: %s
|
Database: %s
|
||||||
RRDTool: %s
|
RRDTool: %s
|
||||||
SNMP: %s
|
SNMP: %s
|
||||||
==================================
|
==================================
|
||||||
@@ -380,7 +379,7 @@ EOH,
|
|||||||
Git::localDate(),
|
Git::localDate(),
|
||||||
vsprintf('%s (%s)', $version->database()),
|
vsprintf('%s (%s)', $version->database()),
|
||||||
phpversion(),
|
phpversion(),
|
||||||
Version::get()->databaseServer(),
|
$version->databaseServer(),
|
||||||
$version->rrdtool(),
|
$version->rrdtool(),
|
||||||
$version->netSnmp()
|
$version->netSnmp()
|
||||||
));
|
));
|
||||||
|
@@ -140,7 +140,7 @@ class Stats
|
|||||||
'vminfo' => $this->selectTotal('vminfo', ['vm_type']),
|
'vminfo' => $this->selectTotal('vminfo', ['vm_type']),
|
||||||
'vmware' => $this->selectTotal('vminfo'),
|
'vmware' => $this->selectTotal('vminfo'),
|
||||||
'vrfs' => $this->selectTotal('vrfs'),
|
'vrfs' => $this->selectTotal('vrfs'),
|
||||||
'mysql_version' => $this->selectStatic($version->databaseServer()),
|
'database_version' => $this->selectStatic($version->databaseServer()),
|
||||||
'php_version' => $this->selectStatic(phpversion()),
|
'php_version' => $this->selectStatic(phpversion()),
|
||||||
'python_version' => $this->selectStatic($version->python()),
|
'python_version' => $this->selectStatic($version->python()),
|
||||||
'rrdtool_version' => $this->selectStatic($version->rrdtool()),
|
'rrdtool_version' => $this->selectStatic($version->rrdtool()),
|
||||||
|
@@ -122,7 +122,20 @@ class Version
|
|||||||
|
|
||||||
public function databaseServer(): string
|
public function databaseServer(): string
|
||||||
{
|
{
|
||||||
return Eloquent::isConnected() ? Arr::first(DB::selectOne('select version()')) : 'Not Connected';
|
if (! Eloquent::isConnected()) {
|
||||||
|
return 'Not Connected';
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (Eloquent::getDriver()) {
|
||||||
|
case 'mysql':
|
||||||
|
$ret = Arr::first(DB::selectOne('select version()'));
|
||||||
|
|
||||||
|
return (str_contains($ret, 'MariaDB') ? 'MariaDB ' : 'MySQL ') . $ret;
|
||||||
|
case 'sqlite':
|
||||||
|
return 'SQLite ' . Arr::first(DB::selectOne('select sqlite_version()'));
|
||||||
|
default:
|
||||||
|
return 'Unsupported: ' . Eloquent::getDriver();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function database(): array
|
public function database(): array
|
||||||
|
@@ -39,22 +39,26 @@ class CheckDatabaseServerVersion implements Validation
|
|||||||
public function validate(): ValidationResult
|
public function validate(): ValidationResult
|
||||||
{
|
{
|
||||||
$version = Version::get()->databaseServer();
|
$version = Version::get()->databaseServer();
|
||||||
$version = explode('-', $version);
|
[$name, $version] = explode(' ', $version, 2);
|
||||||
|
[$version] = explode('-', $version, 2);
|
||||||
|
|
||||||
if (isset($version[1]) && $version[1] == 'MariaDB') {
|
switch ($name) {
|
||||||
if (version_compare($version[0], Database::MARIADB_MIN_VERSION, '<=')) {
|
case 'MariaDB':
|
||||||
return ValidationResult::fail(
|
if (version_compare($version, Database::MARIADB_MIN_VERSION, '<=')) {
|
||||||
trans('validation.validations.database.CheckDatabaseServerVersion.fail', ['server' => 'MariaDB', 'min' => Database::MARIADB_MIN_VERSION, 'date' => Database::MARIADB_MIN_VERSION_DATE]),
|
return ValidationResult::fail(
|
||||||
trans('validation.validations.database.CheckDatabaseServerVersion.fix', ['server' => 'MariaDB', 'suggested' => Database::MARIADB_RECOMMENDED_VERSION]),
|
trans('validation.validations.database.CheckDatabaseServerVersion.fail', ['server' => 'MariaDB', 'min' => Database::MARIADB_MIN_VERSION, 'date' => Database::MARIADB_MIN_VERSION_DATE]),
|
||||||
);
|
trans('validation.validations.database.CheckDatabaseServerVersion.fix', ['server' => 'MariaDB', 'suggested' => Database::MARIADB_RECOMMENDED_VERSION]),
|
||||||
}
|
);
|
||||||
} else {
|
}
|
||||||
if (version_compare($version[0], Database::MYSQL_MIN_VERSION, '<=')) {
|
break;
|
||||||
return ValidationResult::fail(
|
case 'MySQL':
|
||||||
trans('validation.validations.database.CheckDatabaseServerVersion.fail', ['server' => 'MySQL', 'min' => Database::MYSQL_MIN_VERSION, 'date' => Database::MYSQL_MIN_VERSION_DATE]),
|
if (version_compare($version, Database::MYSQL_MIN_VERSION, '<=')) {
|
||||||
trans('validation.validations.database.CheckDatabaseServerVersion.fix', ['server' => 'MySQL', 'suggested' => Database::MYSQL_RECOMMENDED_VERSION]),
|
return ValidationResult::fail(
|
||||||
);
|
trans('validation.validations.database.CheckDatabaseServerVersion.fail', ['server' => 'MySQL', 'min' => Database::MYSQL_MIN_VERSION, 'date' => Database::MYSQL_MIN_VERSION_DATE]),
|
||||||
}
|
trans('validation.validations.database.CheckDatabaseServerVersion.fix', ['server' => 'MySQL', 'suggested' => Database::MYSQL_RECOMMENDED_VERSION]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ValidationResult::ok(trans('validation.validations.database.CheckDatabaseServerVersion.ok'));
|
return ValidationResult::ok(trans('validation.validations.database.CheckDatabaseServerVersion.ok'));
|
||||||
|
@@ -72,7 +72,7 @@ class AboutController extends Controller
|
|||||||
'project_name' => Config::get('project_name'),
|
'project_name' => Config::get('project_name'),
|
||||||
|
|
||||||
'version_local' => $version->local(),
|
'version_local' => $version->local(),
|
||||||
'version_mysql' => $version->databaseServer(),
|
'version_database' => $version->databaseServer(),
|
||||||
'version_php' => phpversion(),
|
'version_php' => phpversion(),
|
||||||
'version_laravel' => App::VERSION(),
|
'version_laravel' => App::VERSION(),
|
||||||
'version_python' => $version->python(),
|
'version_python' => $version->python(),
|
||||||
|
@@ -72,7 +72,7 @@ Commit SHA: {$versions['local_sha']}
|
|||||||
Commit Date: {$versions['local_date']}
|
Commit Date: {$versions['local_date']}
|
||||||
DB Schema: {$versions['db_schema']}
|
DB Schema: {$versions['db_schema']}
|
||||||
PHP: {$versions['php_ver']}
|
PHP: {$versions['php_ver']}
|
||||||
MySQL: {$versions['mysql_ver']}
|
Database: {$versions['database_ver']}
|
||||||
RRDTool: {$versions['rrdtool_ver']}
|
RRDTool: {$versions['rrdtool_ver']}
|
||||||
SNMP: {$versions['netsnmp_ver']}
|
SNMP: {$versions['netsnmp_ver']}
|
||||||
==================================
|
==================================
|
||||||
|
@@ -27,7 +27,7 @@ Output:
|
|||||||
"local_branch": "master",
|
"local_branch": "master",
|
||||||
"db_schema": 249,
|
"db_schema": 249,
|
||||||
"php_ver": "7.2.2",
|
"php_ver": "7.2.2",
|
||||||
"mysql_ver": "5.5.56-MariaDB",
|
"database_ver": "MariaDB 5.5.56-MariaDB",
|
||||||
"rrdtool_ver": "1.4.8",
|
"rrdtool_ver": "1.4.8",
|
||||||
"netsnmp_ver": "NET-SNMP 5.7.2"
|
"netsnmp_ver": "NET-SNMP 5.7.2"
|
||||||
}
|
}
|
||||||
|
@@ -551,7 +551,7 @@ function version_info($remote = false)
|
|||||||
'db_schema' => vsprintf('%s (%s)', $version->database()),
|
'db_schema' => vsprintf('%s (%s)', $version->database()),
|
||||||
'php_ver' => phpversion(),
|
'php_ver' => phpversion(),
|
||||||
'python_ver' => $version->python(),
|
'python_ver' => $version->python(),
|
||||||
'mysql_ver' => $version->databaseServer(),
|
'database_ver' => $version->databaseServer(),
|
||||||
'rrdtool_ver' => $version->rrdtool(),
|
'rrdtool_ver' => $version->rrdtool(),
|
||||||
'netsnmp_ver' => $version->netSnmp(),
|
'netsnmp_ver' => $version->netSnmp(),
|
||||||
];
|
];
|
||||||
|
@@ -107,7 +107,7 @@ Commit SHA: {$versions['local_sha']}
|
|||||||
Commit Date: {$versions['local_date']}
|
Commit Date: {$versions['local_date']}
|
||||||
DB Schema: {$versions['db_schema']}
|
DB Schema: {$versions['db_schema']}
|
||||||
PHP: {$versions['php_ver']}
|
PHP: {$versions['php_ver']}
|
||||||
MySQL: {$versions['mysql_ver']}
|
Database: {$versions['database_ver']}
|
||||||
RRDTool: {$versions['rrdtool_ver']}
|
RRDTool: {$versions['rrdtool_ver']}
|
||||||
SNMP: {$versions['netsnmp_ver']}
|
SNMP: {$versions['netsnmp_ver']}
|
||||||
==================================
|
==================================
|
||||||
|
@@ -47,8 +47,8 @@
|
|||||||
<td>{{ $version_python }}</td>
|
<td>{{ $version_python }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>{{ __('MySQL') }}</b></td>
|
<td><b>{{ __('Database') }}</b></td>
|
||||||
<td>{{ $version_mysql }}</td>
|
<td>{{ $version_database }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="https://laravel.com/"><b>{{ __('Laravel') }}</b></a></td>
|
<td><a href="https://laravel.com/"><b>{{ __('Laravel') }}</b></a></td>
|
||||||
|
@@ -160,7 +160,7 @@ LibreNMS | ${versions['local_ver']}
|
|||||||
DB Schema | ${versions['db_schema']}
|
DB Schema | ${versions['db_schema']}
|
||||||
PHP | ${versions['php_ver']}
|
PHP | ${versions['php_ver']}
|
||||||
Python | ${versions['python_ver']}
|
Python | ${versions['python_ver']}
|
||||||
MySQL | ${versions['mysql_ver']}
|
Database | ${versions['database_ver']}
|
||||||
RRDTool | ${versions['rrdtool_ver']}
|
RRDTool | ${versions['rrdtool_ver']}
|
||||||
SNMP | ${versions['netsnmp_ver']}
|
SNMP | ${versions['netsnmp_ver']}
|
||||||
====================================
|
====================================
|
||||||
|
Reference in New Issue
Block a user