Download the PHP package lukaszaleckas/laravel-alerts without Composer
On this page you can find all versions of the php package lukaszaleckas/laravel-alerts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-alerts
Laravel Alerts
Installation
- Run:
Service provider should be automatically registered, if not add
to your application's app.php
.
-
Publish
laravel-alerts.php
config file: - Schedule
RunChecksCommand
in yourApp\Console\Kernel
schedule
method:
In the example above, we are running all of the checks registered in config file, every minute.
To run only specific alert checks, use the example below:
Creating alerts
Alert can be created using these steps:
- Create a new class anywhere in you project.
-
Extend it from
LaravelAlerts\Contracts\AbstractAlert
: -
Add required method
buildAlertResult
which should returnLaravelAlerts\DTOs\AlertResultDto
DTO. This DTO contains a boolean if alert was triggered, alert message and any additional context which will be appended to the alert's log. - Next, we need to register this alert in the config files
alerts
array. Below is an example of afailed_jobs
table row count alert configuration:
Additional alert customization
Configuration parameters
To make alerts reusable, they can require configuration parameters. If you want to use this feature:
- Add
ConfigKeys::CONFIG
in yoularavel-alerts.php
alerts' configuration and specify any number of parameters. (See an example above). - Override
LaravelAlerts\Contracts\AbstractAlert
configure
method, which will receive an array containing all of the parameters you added in the first step.
Logging options
Log level and log channels can be configured by overriding LaravelAlerts\Contracts\AbstractAlert
classes getAlertLevel
and getLogChannels
methods respectively.
Available alerts
This package contains some predefined alerts that you can use.
They are in the LaravelAlerts\Alerts
namespace.
QueueSizeAlert
Alert is triggered if queue size, on a particular connection, exceeds threshold.
Configuration
connection
(required) (string) - Queue connection namequeue
(required) (string) - Queue namethreshold
(required) (int) - Queue size (job count) threshold
TableSizeAlert
Alert is triggered if database table size exceeds threshold.
Configuration
connection
(required) (string) - Database connection nametable_name
(required) (string) - Table namethreshold
(required) (int) - Table size (row count) threshold