Git version validation fix (#14042)

Instead of erroring because the date is empty, print the error message from git.
This commit is contained in:
Tony Murray
2022-06-14 13:36:46 -05:00
committed by GitHub
parent 1d35d9391d
commit c1a59e29e5

View File

@@ -35,6 +35,7 @@ use LibreNMS\Util\Git;
use LibreNMS\Util\Version; use LibreNMS\Util\Version;
use LibreNMS\ValidationResult; use LibreNMS\ValidationResult;
use LibreNMS\Validator; use LibreNMS\Validator;
use Symfony\Component\Process\Process;
class Updates extends BaseValidation class Updates extends BaseValidation
{ {
@@ -64,16 +65,24 @@ class Updates extends BaseValidation
$local_ver = Version::get()->localCommit(); $local_ver = Version::get()->localCommit();
$remote_ver = Version::get()->remoteCommit(); $remote_ver = Version::get()->remoteCommit();
if ($local_ver['sha'] != ($remote_ver['sha'] ?? null)) { if ($local_ver['sha'] != ($remote_ver['sha'] ?? null)) {
try { if (empty($local_ver['date'])) {
$commit_date = new DateTime('@' . $local_ver['date'], new DateTimeZone(date_default_timezone_get())); $process = new Process(['git', 'show', '-q', '--pretty=%H|%ct'], base_path());
if ($commit_date->diff(new DateTime())->days > 0) { $process->run();
$validator->warn( $error = rtrim($process->getErrorOutput());
'Your install is over 24 hours out of date, last update: ' . $commit_date->format('r'),
'Make sure your daily.sh cron is running and run ./daily.sh by hand to see if there are any errors.' $validator->fail('Failed to fetch version from local git: ' . $error);
); } else {
try {
$commit_date = new DateTime('@' . $local_ver['date'], new DateTimeZone(date_default_timezone_get()));
if ($commit_date->diff(new DateTime())->days > 0) {
$validator->warn(
'Your install is over 24 hours out of date, last update: ' . $commit_date->format('r'),
'Make sure your daily.sh cron is running and run ./daily.sh by hand to see if there are any errors.'
);
}
} catch (Exception $e) {
$validator->fail($e->getMessage());
} }
} catch (Exception $e) {
$validator->fail($e->getMessage());
} }
} }