lukaszaleckas/laravel-alerts is a Laravel package.
It currently has 0 GitHub stars and 21 downloads on Packagist (latest version v1.1.0).
Install it with composer require lukaszaleckas/laravel-alerts.
Discover more Laravel packages by lukaszaleckas
or browse all Laravel packages to compare alternatives.
Last updated
composer require lukaszaleckas/laravel-alerts
Service provider should be automatically registered, if not add
LaravelAlerts\LaravelAlertsServiceProvider::class
to your application's app.php.
laravel-alerts.php config file: php artisan vendor:publish --tag=laravel-alerts
RunChecksCommand in your App\Console\Kernel schedule method: use LaravelAlerts\RunChecksCommand;
protected function schedule(Schedule $schedule): void
{
$schedule->command(RunChecksCommand::class)
->everyMinute()
->withoutOverlapping();
}
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:
protected function schedule(Schedule $schedule): void
{
$schedule->command(
RunChecksCommand::class,
[
RunChecksCommand::ARGUMENT_IDENTIFIERS => [
'first_alert',
'second_alert'
]
]
)
->everyMinute()
->withoutOverlapping();
}
Alert can be created using these steps:
LaravelAlerts\Contracts\AbstractAlert:class MySuperDuperAlert extends AbstractAlert
{
...
Add required method buildAlertResult which should return
LaravelAlerts\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 a failed_jobs table row count alert configuration:
[
ConfigKeys::ALERT => TableSizeAlert::class,
ConfigKeys::IDENTIFIER => 'failed_jobs_alert',
ConfigKeys::CONFIG => [
TableSizeAlert::CONFIG_CONNECTION => 'mysql',
TableSizeAlert::CONFIG_TABLE_NAME => 'failed_jobs',
TableSizeAlert::CONFIG_THRESHOLD => 30
]
]
To make alerts reusable, they can require configuration parameters. If you want to use this feature:
ConfigKeys::CONFIG in you laravel-alerts.php
alerts' configuration and specify any number of parameters.
(See an example above).LaravelAlerts\Contracts\AbstractAlert configure method,
which will receive an array containing all of the parameters you added
in the first step.Log level and log channels can be configured by overriding LaravelAlerts\Contracts\AbstractAlert
classes getAlertLeveland getLogChannels methods respectively.
This package contains some predefined alerts that you can use.
They are in the LaravelAlerts\Alerts namespace.
QueueSizeAlertAlert is triggered if queue size, on a particular connection, exceeds threshold.
connection (required) (string) - Queue connection namequeue (required) (string) - Queue namethreshold (required) (int) - Queue size (job count) thresholdTableSizeAlertAlert is triggered if database table size exceeds threshold.
connection (required) (string) - Database connection nametable_name (required) (string) - Table namethreshold (required) (int) - Table size (row count) threshold