Repository navigation
feat(os): collect the operating system status #1214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karlitschek
wants to merge
23
commits into
master
Choose a base branch
from
feat/os-status-collector
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+8,237
−7
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9bf0743
feat(os): collect the operating system status
karlitschek 2f0c96c
fix(os): treat missing package lists as unknown updates
karlitschek 284aa2b
fix(os): report unknown, exit 3, when the updates are not known
karlitschek 421cef1
fix(os): count a pending security update per package, not per version
karlitschek e7d4ae8
fix(os): no core-library reboot for systemd or in system containers
karlitschek 38a3e80
fix(os): keep each error threshold at or above its warning threshold
karlitschek 03fb879
fix(os): collect the operating system status only from system cron
karlitschek 52d55c0
fix(os): no support dates for Raspbian or NixOS unstable
karlitschek 635481d
docs(os): list what is read and run, the exit code 3 and the cron req…
karlitschek aeb0016
fix(build): regenerate the license files from the locked dependencies
karlitschek 2451a33
fix(os): never count interrupted command output as complete
karlitschek bac4a50
fix(os): try apt when open_basedir hides it, and remember missing bin…
karlitschek 7948a5e
fix(os): take the package list age from verified files, not lists/par…
karlitschek 9fd93ca
fix(os): no permanent "kernel removed" for provider and netboot kernels
karlitschek 6eefcad
fix(os): require a package change before a core library asks for a re…
karlitschek ed28f95
fix(os): keep the PHP process's first sighting under its own key
karlitschek b315697
perf(os): keep the collected status in app data, not in app config
karlitschek 6c418d5
fix(os): warn about an old status, and keep one failing probe from en…
karlitschek 0153570
refactor(os): give SupportTable a constructor without a scalar parameter
karlitschek e462a8d
docs(os): describe only what this part of the stack delivers
karlitschek ec559b6
fix(os): only store apt updates whose names and versions look like apt's
karlitschek 9448c0f
fix(os): count apt updates as security only from the distribution's a…
karlitschek 934a33d
refactor(os): declare occ serverinfo:os-status with attributes
karlitschek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| .nextcloudignore | ||
| .php-cs-fixer.dist.php | ||
| .tx/ | ||
| build/ | ||
| eslint.config.mjs | ||
| l10n/.gitkeep | ||
| psalm.xml | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| /** | ||
| * Regenerates resources/os-support.json from the endoflife.date dataset | ||
| * (https://endoflife.date, MIT License). | ||
| * | ||
| * Run it before a release: php build/update-os-support.php | ||
| * The app itself never contacts endoflife.date. | ||
| */ | ||
|
|
||
| const API = 'https://endoflife.date/api/v1/products/%s/'; | ||
|
|
||
| /** | ||
| * os-release ID => endoflife.date product, how VERSION_ID maps to a release | ||
| * cycle, and which paid programme (if any) extends security support. | ||
| */ | ||
| const PRODUCTS = [ | ||
| 'ubuntu' => ['product' => 'ubuntu', 'cycle' => 'minor', 'extended' => 'ubuntu-pro'], | ||
| 'debian' => ['product' => 'debian', 'cycle' => 'major', 'extended' => 'debian-elts', 'lts' => true], | ||
| 'rhel' => ['product' => 'rhel', 'cycle' => 'major', 'extended' => 'rhel-els'], | ||
| 'almalinux' => ['product' => 'almalinux', 'cycle' => 'major', 'extended' => null], | ||
| 'rocky' => ['product' => 'rocky-linux', 'cycle' => 'major', 'extended' => null], | ||
| 'centos-stream' => ['product' => 'centos-stream', 'cycle' => 'major', 'extended' => null], | ||
| 'centos' => ['product' => 'centos', 'cycle' => 'major', 'extended' => null], | ||
| 'ol' => ['product' => 'oracle-linux', 'cycle' => 'major', 'extended' => 'oracle-extended'], | ||
| 'fedora' => ['product' => 'fedora', 'cycle' => 'major', 'extended' => null], | ||
| 'opensuse-leap' => ['product' => 'opensuse', 'cycle' => 'minor', 'extended' => null], | ||
| 'sles' => ['product' => 'sles', 'cycle' => 'minor', 'extended' => 'suse-ltss'], | ||
| 'alpine' => ['product' => 'alpine-linux', 'cycle' => 'minor', 'extended' => null], | ||
| 'amzn' => ['product' => 'amazon-linux', 'cycle' => 'major', 'extended' => null], | ||
| ]; | ||
|
|
||
| /** os-release IDs of rolling releases, which have no end of support. */ | ||
| const ROLLING = [ | ||
| 'arch', 'archarm', 'manjaro', 'endeavouros', 'cachyos', 'garuda', | ||
| 'opensuse-tumbleweed', 'opensuse-microos', 'opensuse-slowroll', | ||
| 'gentoo', 'void', | ||
| ]; | ||
|
|
||
| /** Releases whose support ended before this are left out; nothing that old runs a current Nextcloud. */ | ||
| const OLDEST = '2018-01-01'; | ||
|
|
||
| function fetchProduct(string $product): array { | ||
| $context = stream_context_create(['http' => ['timeout' => 120, 'user_agent' => 'nextcloud-serverinfo-build']]); | ||
| $json = file_get_contents(sprintf(API, $product), false, $context); | ||
| if ($json === false) { | ||
| fwrite(STDERR, "Could not download $product\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| $data = json_decode($json, true, 32, JSON_THROW_ON_ERROR); | ||
| if (!isset($data['result']['releases']) || !is_array($data['result']['releases'])) { | ||
| fwrite(STDERR, "Unexpected response for $product\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| return $data['result']['releases']; | ||
| } | ||
|
|
||
| function date_or_null(mixed $value): ?string { | ||
| return is_string($value) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $value) === 1 ? $value : null; | ||
| } | ||
|
|
||
| $releases = []; | ||
| foreach (PRODUCTS as $id => $config) { | ||
| foreach (fetchProduct($config['product']) as $release) { | ||
| $cycle = (string)($release['name'] ?? ''); | ||
| $securityEnds = date_or_null($release['eolFrom'] ?? null); | ||
| $extendedEnds = $config['extended'] !== null ? date_or_null($release['eoesFrom'] ?? null) : null; | ||
| if ($cycle === '' || $securityEnds === null) { | ||
| continue; | ||
| } | ||
| if (max($securityEnds, $extendedEnds ?? '') < OLDEST) { | ||
| continue; | ||
| } | ||
|
|
||
| $entry = ['securityEnds' => $securityEnds]; | ||
| if (($config['lts'] ?? false) && ($ltsFrom = date_or_null($release['eoasFrom'] ?? null)) !== null) { | ||
| $entry['ltsFrom'] = $ltsFrom; | ||
| } | ||
| if ($extendedEnds !== null && $extendedEnds > $securityEnds) { | ||
| $entry['extendedEnds'] = $extendedEnds; | ||
| $entry['extended'] = $config['extended']; | ||
| } | ||
|
|
||
| $releases[$id . ':' . $cycle] = $entry; | ||
| } | ||
| } | ||
|
|
||
| ksort($releases, SORT_NATURAL); | ||
|
|
||
| $table = [ | ||
| 'source' => 'endoflife.date, MIT License, https://endoflife.date', | ||
| 'generatedAt' => gmdate('Y-m-d'), | ||
| 'cycles' => array_map(static fn (array $c): string => $c['cycle'], PRODUCTS), | ||
| 'rolling' => ROLLING, | ||
| 'releases' => $releases, | ||
| ]; | ||
|
|
||
| $target = __DIR__ . '/../resources/os-support.json'; | ||
| file_put_contents($target, json_encode($table, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR) . "\n"); | ||
| echo 'Wrote ' . count($releases) . " releases to resources/os-support.json\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\ServerInfo\Commands; | ||
|
|
||
| use OCA\ServerInfo\OsStatus\OsStatusCollector; | ||
| use OCA\ServerInfo\OsStatus\OsStatusService; | ||
| use OCA\ServerInfo\OsStatus\Verdict\Concern; | ||
| use OCP\Console\Attribute\AsCommand; | ||
| use OCP\Console\Attribute\Option; | ||
| use OCP\Console\IOutput; | ||
|
|
||
| /** | ||
| * @psalm-api | ||
| */ | ||
| #[AsCommand( | ||
| name: 'serverinfo:os-status', | ||
| description: 'Shows pending operating system updates, reboots and other concerns', | ||
| supportsOutputFormat: true, | ||
| )] | ||
| class ShowOsStatus { | ||
| /** Exit codes of monitoring plugins */ | ||
| public const EXIT_OK = 0; | ||
| public const EXIT_WARNING = 1; | ||
| public const EXIT_CRITICAL = 2; | ||
| public const EXIT_UNKNOWN = 3; | ||
|
|
||
| public function __construct( | ||
| private OsStatusCollector $collector, | ||
| private OsStatusService $service, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @return self::EXIT_* the monitoring plugin exit code, which needs 3 for unknown | ||
| */ | ||
| public function __invoke( | ||
| IOutput $output, | ||
| #[Option(description: 'Collect the status now instead of showing the stored one', shortcut: 'r')] | ||
| bool $refresh = false, | ||
| ): int { | ||
| if ($refresh) { | ||
| if ($this->collector->collectAndStore() === null) { | ||
| $output->writeln('<error>The operating system status could not be collected; see the Nextcloud log.</error>'); | ||
|
|
||
| return self::EXIT_UNKNOWN; | ||
| } | ||
| } | ||
|
|
||
| $status = $this->service->getStatus(); | ||
| if ($status === null) { | ||
| $output->writeln('The operating system has not been checked yet. Run with --refresh to check it now.'); | ||
|
|
||
| return self::EXIT_UNKNOWN; | ||
| } | ||
|
|
||
| $verdict = $this->service->evaluate($status); | ||
| $concerns = []; | ||
| foreach ($verdict?->concerns ?? [] as $concern) { | ||
| $concerns[$concern->id] = ['level' => $concern->level] + array_filter( | ||
| $concern->facts, | ||
| static fn (mixed $fact): bool => $fact !== null && $fact !== [], | ||
| ); | ||
| } | ||
| $pendingDays = $verdict?->get(Concern::UPDATES)?->facts['days'] ?? null; | ||
| $age = $verdict?->get(Concern::FRESHNESS)?->facts['ageSeconds'] ?? null; | ||
| $securityUpdates = $status->securityUpdates(); | ||
|
|
||
| $output->writeArrayInOutputFormat([ | ||
| 'level' => $verdict?->level() ?? Concern::LEVEL_UNKNOWN, | ||
| 'collectedAt' => date(DATE_ATOM, $status->collectedAt), | ||
| 'statusAge' => is_int($age) ? self::formatAge($age) : 'unknown', | ||
| 'release' => $status->release?->prettyName ?? 'unknown', | ||
| 'kernel' => $status->kernel, | ||
| 'environment' => $status->environment->kind, | ||
| 'packageManager' => $status->packageManager ?? 'none', | ||
| 'securityUpdates' => $securityUpdates === null ? 'unknown' : count($securityUpdates), | ||
| 'updates' => $status->updates === null ? 'unknown' : count($status->updates) + $status->updatesOmitted, | ||
| 'updatesPendingDays' => is_int($pendingDays) ? $pendingDays : 'none', | ||
| 'rebootRequired' => $status->rebootReasons === null ? 'unknown' : ($status->rebootReasons !== [] ? 'yes' : 'no'), | ||
| 'concerns' => $concerns, | ||
| ]); | ||
|
|
||
| return self::exitCode($verdict?->level()); | ||
| } | ||
|
|
||
| /** | ||
| * A duration in its two largest units, e.g. "3 d 4 h" or "12 min". | ||
| */ | ||
| public static function formatAge(int $seconds): string { | ||
| return match (true) { | ||
| $seconds >= 86400 => sprintf('%d d %d h', intdiv($seconds, 86400), intdiv($seconds % 86400, 3600)), | ||
| $seconds >= 3600 => sprintf('%d h %d min', intdiv($seconds, 3600), intdiv($seconds % 3600, 60)), | ||
| default => sprintf('%d min', intdiv(max(0, $seconds), 60)), | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @param Concern::LEVEL_*|null $level | ||
| * @return self::EXIT_* | ||
| */ | ||
| public static function exitCode(?string $level): int { | ||
| return match ($level) { | ||
| Concern::LEVEL_OK, Concern::LEVEL_INFO => self::EXIT_OK, | ||
| Concern::LEVEL_WARNING => self::EXIT_WARNING, | ||
| Concern::LEVEL_ERROR => self::EXIT_CRITICAL, | ||
| default => self::EXIT_UNKNOWN, | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.