Search in sources :

Example 1 with VersionResponse

use of org.graylog2.versioncheck.VersionResponse in project graylog2-server by Graylog2.

the class VersionCheckThread method doRun.

@Override
public void doRun() {
    final Request request = new Request.Builder().addHeader(HttpHeaders.USER_AGENT, USER_AGENT).get().url(versionCheckUri.toString()).build();
    try (final Response response = httpClient.newCall(request).execute()) {
        if (response.isSuccessful()) {
            final VersionCheckResponse versionCheckResponse = objectMapper.readValue(response.body().byteStream(), VersionCheckResponse.class);
            final VersionResponse version = versionCheckResponse.version;
            final com.github.zafarkhaja.semver.Version reportedVersion = com.github.zafarkhaja.semver.Version.forIntegers(version.major, version.minor, version.patch);
            LOG.debug("Version check reports current version: " + versionCheckResponse);
            if (reportedVersion.greaterThan(ServerVersion.VERSION.getVersion())) {
                LOG.debug("Reported version is higher than ours ({}). Writing notification.", ServerVersion.VERSION);
                Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.NORMAL).addType(Notification.Type.OUTDATED_VERSION).addDetail("current_version", versionCheckResponse.toString());
                notificationService.publishIfFirst(notification);
            } else {
                LOG.debug("Reported version is not higher than ours ({}).", ServerVersion.VERSION);
                notificationService.fixed(Notification.Type.OUTDATED_VERSION);
            }
        } else {
            LOG.error("Version check unsuccessful (response code {}).", response.code());
        }
    } catch (IOException e) {
        LOG.error("Couldn't perform version check", e);
    }
}
Also used : VersionResponse(org.graylog2.versioncheck.VersionResponse) VersionCheckResponse(org.graylog2.versioncheck.VersionCheckResponse) Response(okhttp3.Response) VersionCheckResponse(org.graylog2.versioncheck.VersionCheckResponse) VersionResponse(org.graylog2.versioncheck.VersionResponse) Request(okhttp3.Request) IOException(java.io.IOException) Notification(org.graylog2.notifications.Notification)

Aggregations

IOException (java.io.IOException)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 Notification (org.graylog2.notifications.Notification)1 VersionCheckResponse (org.graylog2.versioncheck.VersionCheckResponse)1 VersionResponse (org.graylog2.versioncheck.VersionResponse)1