Skip to content

Commit ccd857c

Browse files
committed
added logging to slack and email commands
1 parent 88fe6ab commit ccd857c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Console/SecurityMailCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Jorijn\LaravelSecurityChecker\Console;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Log;
67
use Illuminate\Support\Facades\Mail;
78
use Jorijn\LaravelSecurityChecker\Mailables\SecurityMail;
89
use SensioLabs\Security\SecurityChecker;
@@ -45,12 +46,14 @@ public function handle()
4546
$composerLock = base_path('composer.lock');
4647

4748
// and feed it into the SecurityChecker
49+
Log::debug('about to check for vulnerabilities');
4850
$checkResult = json_decode((string)$this->checker->check($composerLock), true);
4951

5052
// if the user didn't want any email if there are no results,
5153
// cancel execution here.
5254
$proceed = config('laravel-security-checker.notify_even_without_vulnerabilities', false);
5355
if ($proceed !== true && \count($checkResult) === 0) {
56+
Log::info('no vulnerabilities were found, not sending any email');
5457
return 0;
5558
}
5659

@@ -60,12 +63,14 @@ public function handle()
6063
});
6164

6265
if ($recipients->count() === 0) {
66+
Log::error('vulnerabilities were found, but there are no recipients configured');
6367
$this->error(
6468
/** @scrutinizer ignore-type */__('laravel-security-checker::messages.no_recipients_configured')
6569
);
6670
return 1;
6771
}
6872

73+
Log::warning('vulnerabilities were found, emailed to configured recipients');
6974
Mail::to($recipients->toArray())->send(new SecurityMail($checkResult));
7075

7176
return 0;

src/Console/SecuritySlackCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Jorijn\LaravelSecurityChecker\Console;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Log;
67
use Illuminate\Support\Facades\Notification;
78
use Jorijn\LaravelSecurityChecker\Notifications\SecuritySlackNotification;
89
use SensioLabs\Security\SecurityChecker;
@@ -43,21 +44,26 @@ public function handle()
4344
{
4445
// require that the user specifies a slack channel in the .env file
4546
if (!config('laravel-security-checker.slack_webhook_url')) {
47+
Log::error('checking for vulnerabilities using slack was requested but no hook is configured');
4648
throw new \Exception('No Slack Webhook has been specified.');
4749
}
4850

4951
// get the path to composer.lock
5052
$composerLock = base_path('composer.lock');
5153

5254
// and feed it into the SecurityChecker
55+
Log::debug('about to check for vulnerabilities');
5356
$vulnerabilities = json_decode((string)$this->checker->check($composerLock), true);
5457

5558
// cancel execution here if user does not want to be notified when there are 0 vulns.
5659
$proceed = config('laravel-security-checker.notify_even_without_vulnerabilities', false);
5760
if (count($vulnerabilities) === 0 && $proceed !== true) {
61+
Log::info('no vulnerabilities were found, not sending a slack notification');
62+
5863
return 0;
5964
}
6065

66+
Log::warning('vulnerabilities were found, sending slack notification to configured hook');
6167
Notification::route('slack', config('laravel-security-checker.slack_webhook_url', null))
6268
->notify(new SecuritySlackNotification($vulnerabilities, realpath($composerLock)));
6369
}

0 commit comments

Comments
 (0)