diff --git a/README.md b/README.md index 1c2f7cff..502768ff 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,17 @@ directory **nextcloud/apps/serverinfo** ## API -The API provides a lot of information information about a running Nextcloud -instance in XML or JSON format, by using the following URL. If you want to -get the information returned in JSON format, you have to append **`?format=json`** -to the URL. +The API provides a lot of information about a running Nextcloud +instance in XML or JSON format by using the following URL. + ``` https:///ocs/v2.php/apps/serverinfo/api/v1/info ``` +- To request the information in JSON append the url parameter `format=json` +- Use the url parameter `skipUpdate=true` to omit server updates. +- Use the url parameter `skipApps=true` to omit app updates (including available app updates will send an external request to the app store). + ### Example XML output: ``` diff --git a/css/style.css b/css/style.css index 11dc4a03..b6f1cbed 100644 --- a/css/style.css +++ b/css/style.css @@ -244,3 +244,14 @@ } } */ + +.monitoring-url-params { + margin-top: 3px; + margin-bottom: 3px; +} + +.monitoring-url-param { + display: flex; + align-items: center; + height: 24px; +} diff --git a/js/script.js b/js/script.js index 92b3dec2..8e76dd87 100644 --- a/js/script.js +++ b/js/script.js @@ -310,3 +310,32 @@ } })(jQuery, OC); + +function updateMonitoringUrl(event) { + const $endpointUrl = document.getElementById('monitoring-endpoint-url'); + const $params = document.querySelectorAll('.update-monitoring-endpoint-url'); + + const url = new URL($endpointUrl.value) + url.searchParams.delete('format') + url.searchParams.delete('skipUpdate') + url.searchParams.delete('skipApps') + + for (const $param of $params) { + if ($param.name === 'format_json' && $param.checked) { + url.searchParams.set('format', 'json') + } + if ($param.name === 'skip_update' && $param.checked) { + url.searchParams.set('skipUpdate', 'true') + } + if ($param.name === 'skip_apps' && $param.checked) { + url.searchParams.set('skipApps', 'true') + } + } + + $endpointUrl.value = url.toString() +} + +document.addEventListener('DOMContentLoaded', function (event) { + const $params = document.querySelectorAll('.update-monitoring-endpoint-url'); + $params.forEach($param => $param.addEventListener('change', updateMonitoringUrl)); +}); diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index ea2621ba..5824c1f2 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -113,7 +113,7 @@ private function checkAuthorized(): bool { * @PublicPage * @BruteForceProtection(action=serverinfo) */ - public function info(): DataResponse { + public function info(bool $skipUpdate = false, bool $skipApps = false): DataResponse { if (!$this->checkAuthorized()) { $response = new DataResponse(['message' => 'Unauthorized']); $response->throttle(); @@ -122,7 +122,7 @@ public function info(): DataResponse { } return new DataResponse([ 'nextcloud' => [ - 'system' => $this->systemStatistics->getSystemStatistics(), + 'system' => $this->systemStatistics->getSystemStatistics($skipUpdate, $skipApps), 'storage' => $this->storageStatistics->getStorageStatistics(), 'shares' => $this->shareStatistics->getShareStatistics() ], diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index df32051a..aad3d31b 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -47,7 +47,7 @@ public function __construct(string $appName, */ public function update(): JSONResponse { $data = [ - 'system' => $this->systemStatistics->getSystemStatistics() + 'system' => $this->systemStatistics->getSystemStatistics(true, true) ]; return new JSONResponse($data); diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php index 9a19233f..2b671c4a 100644 --- a/lib/Settings/AdminSettings.php +++ b/lib/Settings/AdminSettings.php @@ -87,7 +87,7 @@ public function getForm(): TemplateResponse { 'php' => $this->phpStatistics->getPhpStatistics(), 'database' => $this->databaseStatistics->getDatabaseStatistics(), 'activeUsers' => $this->sessionStatistics->getSessionStatistics(), - 'system' => $this->systemStatistics->getSystemStatistics(), + 'system' => $this->systemStatistics->getSystemStatistics(true, true), 'thermalzones' => $this->os->getThermalZones(), 'phpinfo' => $this->config->getAppValue('serverinfo', 'phpinfo', 'no') === 'yes', 'phpinfoUrl' => $this->urlGenerator->linkToRoute('serverinfo.page.phpinfo') diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index 467e0fa2..36985b08 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -51,12 +51,12 @@ public function __construct(IConfig $config, IAppManager $appManager, Installer * * @throws \OCP\Files\InvalidPathException */ - public function getSystemStatistics(): array { + public function getSystemStatistics(bool $skipUpdate = false, bool $skipApps = false): array { $processorUsage = $this->getProcessorUsage(); $memoryUsage = $this->os->getMemory(); - return [ + + $data = [ 'version' => $this->config->getSystemValue('version'), - 'update' => $this->getServerUpdateInfo(), 'theme' => $this->config->getSystemValue('theme', 'none'), 'enable_avatars' => $this->config->getSystemValue('enable_avatars', true) ? 'yes' : 'no', 'enable_previews' => $this->config->getSystemValue('enable_previews', true) ? 'yes' : 'no', @@ -71,8 +71,17 @@ public function getSystemStatistics(): array { 'mem_free' => $memoryUsage->getMemAvailable() * 1024, 'swap_total' => $memoryUsage->getSwapTotal() * 1024, 'swap_free' => $memoryUsage->getSwapFree() * 1024, - 'apps' => $this->getAppsInfo() ]; + + if (!$skipUpdate) { + $data['update'] = $this->getServerUpdateInfo(); + } + + if (!$skipApps) { + $data['apps'] = $this->getAppsInfo(); + } + + return $data; } /** diff --git a/templates/settings-admin.php b/templates/settings-admin.php index 679e0483..474d5e70 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -412,15 +412,28 @@ function FormatMegabytes(int $byte): string {

t('External monitoring tool')); ?>

- t('You can connect an external monitoring tool by using this end point:')); ?> + t('Use this end point to connect an external monitoring tool:')); ?>

-

- t('Appending "?format=json" at the end of the URL gives you the result in JSON.')); ?> -

+ +
+
+ + +
+
+ + +
+
+ + +
+
+

t('To use an access token, please generate one then set it using the following command:')); ?>

occ config:app:set serverinfo token --value yourtoken