xperimental / nextcloud-exporter

Prometheus exporter for Nextcloud servers.
MIT License
226 stars 34 forks source link

Include Nextcloud update availability information #116

Closed monofox closed 2 months ago

monofox commented 6 months ago

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

xperimental commented 5 months ago

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.

monofox commented 5 months ago

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.

PReimers commented 5 months ago

@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",
        },
monofox commented 5 months ago

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

xperimental commented 5 months ago

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

xperimental commented 2 months ago

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

monofox commented 2 months ago

@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.