> For the complete documentation index, see [llms.txt](https://l-shop-en.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://l-shop-en.gitbook.io/documentation/software-api/adding-a-server-monitoring-driver.md).

# Adding a server monitoring driver

## Steps

Для того, чтобы реализовать механизм мониторинга, отличный от стандартного вам необходимо:

* Create a class and implement an interface `App\Services\Monitoring\Drivers\Driver`.
* Write implementation `retrieve()`. This method takes a server object (`App\Entity\Server`) for which you want to retrieve online data and returns a data transfer object of type `App\Services\Monitoring\Drivers\DTO`.

{% code title="/app/Services/Monitoring/Drivers/CustomDriver" %}

```php
<?php
declare(strict_types = 1);

namespace App\Services\Monitoring\Drivers;

use App\Entity\Server;

class CustomDriver implements Driver
{
    /**
     * {@inheritdoc}
     */
    public function retrieve(Server $server): DTO
    {
        // Логика получения данных мониторинга сервера.
    }
}
```

{% endcode %}

* Install the newly created class as the primary monitoring driver:
  * Go to /config/monitoring.php.
  * Set the full qualified name of the new driver class with the driver element:

{% code title="/config/monitoring.php" %}

```php
'driver' => \App\Services\Monitoring\Drivers\CustomDriver::class
```

{% endcode %}

* Reset application cache to apply new configuration.

## Specification

{% hint style="info" %}
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "NOT SHALL", "RECOMMENDED", "MAY" must be interpreted in the same way as described in [RFC 2119](http://www.ietf.org/rfc/rfc2119.txt).
{% endhint %}

* The driver class *MUST* implement the `App\Services\Monitoring\Drivers\Driver` interface.
* It is *RECOMMENDED* to add the Driver suffix to the class name, so that the driver class can be identified by name.
* It is *RECOMMENDED* to place the monitoring drivers in the `App\Services\Monitoring\Drivers`.
* The implementation of the `retrieve()` method *MUST* contain the logic for retrieving the online data of the specified server.
* The implementation of the `retrieve()` method *MUST NOT* contain the logic for caching the received data. Caching is performed in another layer of the application and is not included in the driver's area of ​​responsibility.
* If it is impossible to connect to the server, the implementation *MUST* report this to the application by means of passing the corresponding parameter to the object returned from the method.
* If there is an error in getting/parsing data, the implementation *MUST* report this to the application by means of passing the corresponding parameter to the object returned from the method.
* If an error occurs that the driver is unable to process, an exception of the `App\Services\Monitoring\MonitoringException` type *MUST* be thrown. The application will handle this exceptional situation on its own.
