Skip to content
Snippets Groups Projects
ClientVersion.php 977 B
Newer Older
<?php

namespace App\Sensor;

/**
 * Description of Reboot
 *
 * @author tibo
 */
Tibo's avatar
Tibo committed
class ClientVersion extends \App\AbstractSensor
{
Tibo's avatar
Tibo committed
    const MANIFEST = "https://gitlab.cylab.be/cylab/monitoring/raw/master/php-client/release/manifest.json";

Tibo's avatar
Tibo committed
    public function latestVersion()
    {
Tibo's avatar
Tibo committed
        $ctx = stream_context_create(array('http' => ['timeout' => 5]));
        $json = @ \file_get_contents(self::MANIFEST, false, $ctx);
Tibo's avatar
Tibo committed
        if ($json === false) {
Tibo's avatar
Tibo committed
            return "";
        }

        return json_decode($json)[0]->version;
    }

    //put your code here
Tibo's avatar
Tibo committed
    public function report()
    {
        return "<p>Installed version: " . $this->getServer()->clientVersion() . "</p>"
        . "<p>Latest client version: " . $this->latestVersion() . "</p>";
    }

Tibo's avatar
Tibo committed
    public function status()
    {
        if ($this->getServer()->clientVersion() === $this->latestVersion()) {
            return self::STATUS_OK;
        }

        return self::STATUS_WARNING;