mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
version and git helper improvements (#14412)
* Fix up version and git helpers Improve method names Move all git calls into the git helper Allow runtime and external cache of results where appropriate Consolidate version headers for discovery, poller, and validate * Style fixes * improve consistency in git calls * fix style * don't send name inconsistently * Improve database versions * No need to cache Version it is not used more than once currently.
This commit is contained in:
@@ -66,12 +66,12 @@ class AboutController extends Controller
|
||||
'callback_status' => $callback_status,
|
||||
'callback_uuid' => $callback_status ? Callback::get('uuid') : null,
|
||||
|
||||
'db_schema' => vsprintf('%s (%s)', $version->database()),
|
||||
'git_log' => $version->gitChangelog(),
|
||||
'git_date' => $version->localDate(),
|
||||
'db_schema' => $version->database(),
|
||||
'git_log' => $version->git->log(),
|
||||
'git_date' => $version->date(),
|
||||
'project_name' => Config::get('project_name'),
|
||||
|
||||
'version_local' => $version->local(),
|
||||
'version_local' => $version->name(),
|
||||
'version_database' => $version->databaseServer(),
|
||||
'version_php' => phpversion(),
|
||||
'version_laravel' => App::version(),
|
||||
|
51
app/Logging/Reporting/Middleware/AddGitInformation.php
Normal file
51
app/Logging/Reporting/Middleware/AddGitInformation.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* AddGitInformation.php
|
||||
*
|
||||
* Add git information to Flare report, but use a cache so we don't destroy servers
|
||||
*
|
||||
* 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\Logging\Reporting\Middleware;
|
||||
|
||||
use Facade\FlareClient\Report;
|
||||
use LibreNMS\Util\Git;
|
||||
|
||||
class AddGitInformation
|
||||
{
|
||||
/**
|
||||
* @param \Facade\FlareClient\Report $report
|
||||
* @param callable $next next in the pipeline
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Report $report, $next)
|
||||
{
|
||||
$git = Git::make(180);
|
||||
|
||||
$report->group('git', [
|
||||
'hash' => $git->commitHash(),
|
||||
'message' => $git->message(),
|
||||
'tag' => $git->shortTag(),
|
||||
'remote' => $git->remoteUrl(),
|
||||
]);
|
||||
|
||||
return $next($report);
|
||||
}
|
||||
}
|
@@ -43,7 +43,7 @@ class SetGroups
|
||||
$version = Version::get();
|
||||
|
||||
$report->group('LibreNMS', [
|
||||
'Git version' => $version->local(),
|
||||
'Git version' => $version->name(),
|
||||
'App version' => Version::VERSION,
|
||||
]);
|
||||
|
||||
|
@@ -31,8 +31,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
$this->app->singleton('device-cache', function ($app) {
|
||||
return new \LibreNMS\Cache\Device();
|
||||
});
|
||||
$this->app->singleton('version', function ($app) {
|
||||
return new \LibreNMS\Util\Version();
|
||||
$this->app->singleton('git', function ($app) {
|
||||
return new \LibreNMS\Util\Git();
|
||||
});
|
||||
|
||||
$this->app->bind(\App\Models\Device::class, function () {
|
||||
|
@@ -25,6 +25,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Logging\Reporting\Middleware\AddGitInformation;
|
||||
use App\Logging\Reporting\Middleware\CleanContext;
|
||||
use App\Logging\Reporting\Middleware\SetGroups;
|
||||
use ErrorException;
|
||||
@@ -69,6 +70,9 @@ class ErrorReportingProvider extends \Facade\Ignition\IgnitionServiceProvider
|
||||
return \LibreNMS\Util\Version::VERSION;
|
||||
});
|
||||
|
||||
// add git information, but cache it unlike the upstream provider
|
||||
Flare::registerMiddleware(AddGitInformation::class);
|
||||
|
||||
// Filter some extra fields for privacy
|
||||
// Move to header middleware when switching to spatie/laravel-ignition
|
||||
Flare::registerMiddleware(CleanContext::class);
|
||||
@@ -114,20 +118,21 @@ class ErrorReportingProvider extends \Facade\Ignition\IgnitionServiceProvider
|
||||
}
|
||||
|
||||
// Check git
|
||||
if (Git::repoPresent()) {
|
||||
if (! Str::contains(Git::remoteUrl(), ['git@github.com:librenms/librenms.git', 'https://github.com/librenms/librenms.git'])) {
|
||||
$git = Git::make(180);
|
||||
if ($git->isAvailable()) {
|
||||
if (! Str::contains($git->remoteUrl(), ['git@github.com:librenms/librenms.git', 'https://github.com/librenms/librenms.git'])) {
|
||||
\Log::debug('Reporting disabled because LibreNMS is not from the official repository');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! Git::unchanged()) {
|
||||
if ($git->hasChanges()) {
|
||||
\Log::debug('Reporting disabled because LibreNMS is not from the official repository');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! Git::officalCommit()) {
|
||||
if (! $git->isOfficialCommit()) {
|
||||
\Log::debug('Reporting disabled due to local modifications');
|
||||
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user