mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Refactored audit alerts
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
fe147adec3
commit
848e1fe1f6
|
@ -9,7 +9,6 @@ use App\Notifications\ExpectedCheckinAdminNotification;
|
||||||
use App\Notifications\ExpectedCheckinNotification;
|
use App\Notifications\ExpectedCheckinNotification;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class SendExpectedCheckinAlerts extends Command
|
class SendExpectedCheckinAlerts extends Command
|
||||||
{
|
{
|
||||||
|
@ -65,7 +64,7 @@ class SendExpectedCheckinAlerts extends Command
|
||||||
return new AlertRecipient($item);
|
return new AlertRecipient($item);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->info('Sending Admin ExpectedCheckinNotification to: '.$recipients);
|
$this->info('Sending Admin ExpectedCheckinNotification to: '.$settings->alert_email);
|
||||||
\Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
|
\Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\License;
|
use App\Models\Recipients\AlertRecipient;
|
||||||
use App\Models\Recipients;
|
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Notifications\ExpiringAssetsNotification;
|
|
||||||
use App\Notifications\SendUpcomingAuditNotification;
|
use App\Notifications\SendUpcomingAuditNotification;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
|
@ -45,40 +43,26 @@ class SendUpcomingAuditReport extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$interval = $settings->audit_warning_days ?? 0;
|
||||||
|
$today = Carbon::now();
|
||||||
|
$interval_date = $today->copy()->addDays($interval);
|
||||||
|
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
|
$assets = Asset::whereNull('deleted_at')->DueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'desc')->get();
|
||||||
|
$this->info($assets->count().' assets must be audited in on or before '.$interval_date.' is deadline');
|
||||||
|
|
||||||
if (($settings->alert_email != '') && ($settings->audit_warning_days) && ($settings->alerts_enabled == 1)) {
|
|
||||||
|
|
||||||
|
if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) {
|
||||||
// Send a rollup to the admin, if settings dictate
|
// Send a rollup to the admin, if settings dictate
|
||||||
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) {
|
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item) {
|
||||||
return new \App\Models\Recipients\AlertRecipient($item);
|
return new AlertRecipient($item);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assets due for auditing
|
$this->info('Sending Admin SendUpcomingAuditNotification to: '.$settings->alert_email);
|
||||||
|
\Notification::send($recipients, new SendUpcomingAuditNotification($assets, $settings->audit_warning_days));
|
||||||
|
|
||||||
$assets = Asset::whereNotNull('next_audit_date')
|
|
||||||
->DueOrOverdueForAudit($settings)
|
|
||||||
->orderBy('last_audit_date', 'asc')->get();
|
|
||||||
|
|
||||||
if ($assets->count() > 0) {
|
|
||||||
$this->info(trans_choice('mail.upcoming-audits', $assets->count(),
|
|
||||||
['count' => $assets->count(), 'threshold' => $settings->audit_warning_days]));
|
|
||||||
\Notification::send($recipients, new SendUpcomingAuditNotification($assets, $settings->audit_warning_days));
|
|
||||||
$this->info('Audit report sent to '.$settings->alert_email);
|
|
||||||
} else {
|
|
||||||
$this->info('No assets to be audited. No report sent.');
|
|
||||||
}
|
|
||||||
} elseif ($settings->alert_email == '') {
|
|
||||||
$this->error('Could not send email. No alert email configured in settings');
|
|
||||||
} elseif (! $settings->audit_warning_days) {
|
|
||||||
$this->error('No audit warning days set in Admin Notifications. No mail will be sent.');
|
|
||||||
} elseif ($settings->alerts_enabled != 1) {
|
|
||||||
$this->info('Alerts are disabled in the settings. No mail will be sent');
|
|
||||||
} else {
|
|
||||||
$this->error('Something went wrong. :( ');
|
|
||||||
$this->error('Admin Notifications Email Setting: '.$settings->alert_email);
|
|
||||||
$this->error('Admin Audit Warning Setting: '.$settings->audit_warning_days);
|
|
||||||
$this->error('Admin Alerts Emnabled: '.$settings->alerts_enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue