nextcloud-exporter icon indicating copy to clipboard operation
nextcloud-exporter copied to clipboard

Include Nextcloud update availability information

Open monofox opened this issue 10 months ago • 5 comments

This commit introduces new option and metric about nextcloud update availabilty information.

A new option was introduced called --enable-info-update which will append the to the Nextcloud serverinfo-URL a &skipUpdate=false.

In response, the update information is returned and provided in a new metric called nextcloud_system_update_available.

Example output if update available:

# HELP nextcloud_system_update_available Contains information whether a system update is available (0 = no, 1 = yes). In case of 1=yes, available_version label contains the new version.
# TYPE nextcloud_system_update_available gauge
nextcloud_system_update_available{available_version="28.0.4.1"} 1

Example output if update not available:

# HELP nextcloud_system_update_available Contains information whether a system update is available (0 = no, 1 = yes). In case of 1=yes, available_version label contains the new version.
# TYPE nextcloud_system_update_available gauge
nextcloud_system_update_available{available_version=""} 0

It was a bit tricky, as Nextcloud is reporting conflicting information (shortened excerpt):

{
  "system": {
    "version": "28.0.4.1",
    "update": {
      "lastupdatedat": 0,
      "available": true,
      "available_version": "28.0.4.1"
    }
  }
}

Fixes xperimental/nextcloud-exporter#115

monofox avatar Apr 13 '24 12:04 monofox

Hi @monofox . Thanks for the contribution :+1:

I have seen the issue and this PR, but I had no time to look at this thoroughly yet. I had an idea to add this information when adding the skipApps code as well.

I'll probably not get to this until after the weekend, but I already enabled CI for this PR and it seems some tests need to be updated for the new code.

xperimental avatar Apr 18 '24 18:04 xperimental

Thank you @xperimental . No hurry. The failed tests results of situation, that the tests are currently running against a non-existing nextcloud.example.com. I wondered during extension of the tests, but expected to have a corresponding docker-container during test phase running to spawn this domain in an isolated test environment.

Just let me know, if (and which) changes should be done in this way.

monofox avatar Apr 18 '24 19:04 monofox

@monofox I checked your tests.

The problem with the test is the expected URL does not match the actual URL.

Example 1: expected: https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false actual: https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false

Example 2: expected: https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipUpdate=false&skipApps=false actual: https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false

If I'm correct, the following code (serverinfo/url.go) would fix the tests: (Changing the wantURL parameter to always include the skipApps and skipUpdate parameters, in exactly that order)

                {
			desc:      "do not skip apps",
			serverURL: "https://nextcloud.example.com",
			wantURL:   "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false",
		},
		{
			desc:      "skip apps",
			serverURL: "https://nextcloud.example.com",
			skipApps:  true,
			wantURL:   "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=true&skipUpdate=false",
		},
		{
			desc:       "do not skip update",
			serverURL:  "https://nextcloud.example.com",
			skipUpdate: false,
			wantURL:    "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false",
		},
		{
			desc:       "skip update",
			serverURL:  "https://nextcloud.example.com",
			skipUpdate: true,
			wantURL:    "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=true",
		},
		{
			desc:       "do not skip update and do not skip apps",
			serverURL:  "https://nextcloud.example.com",
			skipApps:   false,
			skipUpdate: false,
			wantURL:    "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false",
		},

PReimers avatar Apr 30 '24 00:04 PReimers

Thank you @PReimers for review and giving the right hint. I was blind for it. Fixed it. Test is fine on local machine.

monofox avatar May 02 '24 15:05 monofox

Sorry, I have been busy / away the past weekends. This PR is not forgotten though. :slightly_smiling_face:

xperimental avatar May 14 '24 15:05 xperimental

@monofox Do you have time to go through the review comments or do you want me to take over the PR?

xperimental avatar Jul 16 '24 20:07 xperimental

@monofox Do you have time to go through the review comments or do you want me to take over the PR?

Took a bit longer to get again free time. Thanks for your grateful comments. I've addressed them. Unfortunately, the check on the version number seems to be essential for proper indication whether an update is really available. See my comments above.

monofox avatar Jul 18 '24 19:07 monofox