Skip to content

Commit 23c5c67

Browse files
committed
Review of irrdb warning email post merge
1 parent fc5c855 commit 23c5c67

File tree

6 files changed

+54
-70
lines changed

6 files changed

+54
-70
lines changed

.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ IDENTITY_SUPPORT_EMAIL="${IDENTITY_EMAIL}"
8282
IDENTITY_SUPPORT_PHONE="+1 111 555 5555"
8383
IDENTITY_SUPPORT_HOURS="24x7"
8484

85+
# IXP Manager will need to send alert emails. This is the recipient email for these alerts.
86+
IDENTITY_ALERTS_EMAIL=${IDENTITY_SUPPORT_EMAIL}
87+
IDENTITY_ALERTS_NAME="IXP Manager Alerts"
88+
89+
8590
IDENTITY_BILLING_EMAIL="${IDENTITY_EMAIL}"
8691
IDENTITY_BILLING_PHONE="+1 111 555 5555"
8792
IDENTITY_BILLING_HOURS="24x7"

app/Console/Commands/Irrdb/UpdateDb.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
*/
2525

2626
use Illuminate\Database\Eloquent\Builder;
27+
use Illuminate\Support\Facades\Mail;
2728
use IXP\Console\Commands\Command;
29+
use IXP\Events\User\UserWarning as UserWarningEvent;
30+
use IXP\Mail\User\UserWarning;
2831
use IXP\Models\Customer;
2932

3033
/**
@@ -94,7 +97,7 @@ protected function resolveCustomers( array $options ): mixed
9497
*
9598
* @return void
9699
*/
97-
public function printResults( Customer $c, array $r, string $irrdbType = 'prefix' ): void
100+
protected function printResults( Customer $c, array $r, string $irrdbType = 'prefix' ): void
98101
{
99102
$this->netTime += $r[ 'netTime' ];
100103
$this->dbTime += $r[ 'dbTime' ];
@@ -136,4 +139,30 @@ public function printResults( Customer $c, array $r, string $irrdbType = 'prefix
136139
}
137140
}
138141
}
142+
143+
/**
144+
* Handle exceptions
145+
*/
146+
protected function handleException( Customer $c, \Exception $e, string $type ): void
147+
{
148+
$this->error( "IRRDB {$type} update failed for {$c->name}/AS{$c->autsys}" );
149+
$this->error( $e->getMessage() );
150+
151+
if( !$this->option('alert-email') ) {
152+
return;
153+
}
154+
155+
if( !config('mail.alerts_recipient.address') ) {
156+
$this->warn( "Alert email not sent as IDENTITY_ALERTS_EMAIL .env option not set." );
157+
return;
158+
}
159+
160+
Mail::to( [ [ 'name' => config( 'mail.alerts_recipient.name' ), 'email' => config( 'mail.alerts_recipient.address' ) ] ] )
161+
->send( new UserWarning(
162+
new UserWarningEvent( "IRRDB {$type} update failed for {$c->name}/AS{$c->autsys}", $e->getMessage() )
163+
) );
164+
165+
$this->info( "Alert email sent to " . config( 'mail.alerts_recipient.address' ) );
166+
}
167+
139168
}

app/Events/User/UserWarning.php

+6-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace IXP\Events\User;
44

55
/*
6-
* Copyright (C) 2009 - 2020 Internet Neutral Exchange Association Company Limited By Guarantee.
6+
* Copyright (C) 2009 - 2025 Internet Neutral Exchange Association Company Limited By Guarantee.
77
* All Rights Reserved.
88
*
99
* This file is part of IXP Manager.
@@ -31,52 +31,24 @@
3131
/**
3232
* User Warning Event
3333
* @author Barry O'Donovan <[email protected]>
34-
* @author Yann Robin <[email protected]>
3534
* @author Laszlo Kiss <[email protected]>
3635
* @category Events\User
37-
* @copyright Copyright (C) 2009 - 2020 Internet Neutral Exchange Association Company Limited By Guarantee
36+
* @copyright Copyright (C) 2009 - 2025 Internet Neutral Exchange Association Company Limited By Guarantee
3837
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL V2.0
3938
*/
4039
class UserWarning implements ShouldQueue
4140
{
4241
use Dispatchable, SerializesModels, InteractsWithQueue;
4342

44-
/**
45-
* @var string
46-
* @var string
47-
*/
48-
public string $warningTitle;
49-
public string $errorMessage;
50-
5143
/**
5244
* Create a new event instance.
5345
*
5446
* @param string $warningTitle
5547
* @param string $errorMessage
5648
*/
57-
public function __construct( string $warningTitle, string $errorMessage )
58-
{
59-
$this->warningTitle = $warningTitle;
60-
$this->errorMessage = $errorMessage;
61-
}
62-
63-
/**
64-
* Get asn string
65-
*
66-
* @return string
67-
*/
68-
public function getTitle(): string
69-
{
70-
return $this->warningTitle;
71-
}
49+
public function __construct(
50+
public string $warningTitle,
51+
public string $errorMessage )
52+
{}
7253

73-
/**
74-
* Get error message string
75-
*
76-
* @return string
77-
*/
78-
public function getErrorMessage(): string
79-
{
80-
return $this->errorMessage;
81-
}
8254
}

app/Mail/User/UserWarning.php

+6-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace IXP\Mail\User;
44

55
/*
6-
* Copyright (C) 2009 - 2020 Internet Neutral Exchange Association Company Limited By Guarantee.
6+
* Copyright (C) 2009 - 2025 Internet Neutral Exchange Association Company Limited By Guarantee.
77
* All Rights Reserved.
88
*
99
* This file is part of IXP Manager.
@@ -31,7 +31,6 @@
3131
* Mailable for warning email User
3232
*
3333
* @author Barry O'Donovan <[email protected]>
34-
* @author Yann Robin <[email protected]>
3534
* @author Laszlo Kiss <[email protected]>
3635
* @category User
3736
* @package IXP\Mail\User
@@ -42,26 +41,15 @@ class UserWarning extends Mailable
4241
{
4342
use Queueable, SerializesModels;
4443

45-
/**
46-
*
47-
* @var UserWarningEvent
48-
*/
49-
public UserWarningEvent $event;
50-
51-
public string $warningTitle;
52-
public string $errorMessage;
53-
5444
/**
5545
* Create a new message instance.
5646
*
5747
* @param UserWarningEvent $e
58-
*
5948
* @return void
6049
*/
61-
public function __construct( UserWarningEvent $e )
62-
{
63-
$this->event = $e;
64-
}
50+
public function __construct(
51+
public UserWarningEvent $event
52+
) {}
6553

6654
/**
6755
* Build the message.
@@ -70,9 +58,7 @@ public function __construct( UserWarningEvent $e )
7058
*/
7159
public function build(): self
7260
{
73-
$this->warningTitle = $this->event->getTitle();
74-
$this->errorMessage = $this->event->getErrorMessage();
75-
76-
return $this->markdown( 'user.emails.warning' )->subject( config('identity.sitename' ) . " - Warning" );
61+
return $this->markdown( 'user.emails.warning' )
62+
->subject( config('identity.sitename' ) . " - Alert" );
7763
}
7864
}

config/mail.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@
117117
'name' => env('IDENTITY_NAME', 'Newly Installed IXP Manager'),
118118
],
119119

120+
// IXP Manager will need to send alert emails. This is the recipient email for these alerts.
121+
120122
'alerts_recipient' => [
121-
'address' => env('IDENTITY_ALERTS_EMAIL','[email protected]'),
122-
'name' => env('IDENTITY_ALERTS_NAME','IXP Ops Alerts'),
123+
'address' => env('IDENTITY_ALERTS_EMAIL',false ),
124+
'name' => env('IDENTITY_ALERTS_NAME','IXP Manager Alerts'),
123125
],
124126

125127
/*
+3-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
@component('mail::message')
22

3-
## Warning Message
3+
## {{ config('identity.sitename') }} Alert
44

5-
{{ $warningTitle }}
5+
{{ $event->warningTitle }}
66

77
@component('mail::panel')
8-
{{ $errorMessage }}
8+
{{ $event->errorMessage }}
99
@endcomponent
1010

11-
@component('mail::subcopy')
12-
&nbsp;
13-
@endcomponent
14-
15-
Thanks and kind regards,
16-
17-
18-
{{ config( 'identity.name' ) }}
19-
20-
[{{ config( 'identity.email' ) }}](mailto:{{ config( 'identity.email' ) }})
2111

2212
@endcomponent

0 commit comments

Comments
 (0)